love.math.noise

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
dalmuti
Prole
Posts: 4
Joined: Fri Feb 12, 2016 5:36 am

love.math.noise

Post by dalmuti »

Code: Select all

	for i=1, 10, do
		value = love.math.noise(i)
		print(value)
	end
I'm trying to create a Perlin noise function. From what I gathered this is a build in function in lua that given an x value it returns a value between 0 and 1, but when I run the loop above I get the same value of .5 for every i variable input into the function. Am I wrong to think that this can be substituted instead of the random number generator? and why I cant get different values when inputting i into love.math.noise(i)?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: love.math.noise

Post by Robin »

What if you try love.math.noise(i/10) ?
Help us help you: attach a .love.
Zarty55
Citizen
Posts: 79
Joined: Thu Jul 25, 2013 2:36 am

Re: love.math.noise

Post by Zarty55 »

I've had the same problem as you.

https://bitbucket.org/account/notificat ... -arguments

The solution is to pass non-integer values to the function.
dalmuti
Prole
Posts: 4
Joined: Fri Feb 12, 2016 5:36 am

Re: love.math.noise

Post by dalmuti »

thanks for the help, ironed out a few things with that, but i'm running into the issue that when I close the program and reopen it I get the same values. How can I have a random set of numbers each time?
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: love.math.noise

Post by zorg »

Try multiplying it with love.math.random.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
slime
Solid Snayke
Posts: 3162
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: love.math.noise

Post by slime »

noise is supposed to give the same output given the same input. You could add an offset to the arguments which is randomized at startup. Something like this:

Code: Select all

function love.load()
    local offset = love.math.random() * 100000
    for i=1, 10 do
        local value = love.math.noise(offset + i / 10)
    end
end
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests