Page 1 of 1

Crude Island Generator (11.2)

Posted: Thu Jan 31, 2019 9:42 am
by BlueThumbDevelopment
So I'm working on a game where I needed some randomly generated islands and so I focused on actually creating these, ending with a little thing that can generate little islands. There is lots of room for customisation ( and probably optimisation ) but at this point it is good for what I need.
IslandGen.love
(1.32 KiB) Downloaded 296 times
I thought I'd share it anyway just to see what people think.

Press "g" to generate a new island and remove the previous one.

It works by creating a grid of numbers with LÖVE's noise function and then a circular mask is added to give it a rounded effect, after a random "z" value is made and applied to the island so if the noise value for each pixel is less than that "z" value it will just draw it black (or set it to what background you need) giving a random effect to the shape of the island.

Hopefully that explains it, ut go have a see for yourself!

Re: Crude Island Generator (11.2)

Posted: Thu Jan 31, 2019 8:49 pm
by KayleMaster
You almost got it !
I ran it at first, and it seemed ok,but as I generated more islands, they all looked the same to me, just minor variations.
So I seeded the noise with three values that are randomised everytime you press G, the results are much better now.

Code: Select all

function noise(posX,posY)
	-- and added these three lines
	seedx =love.math.random( 500 )
	seedy =love.math.random( 500 )
	seedz =love.math.random( 500 )
	grid = {}
	local scale = 10
	for x = posX, (posX + size) do
		for y = posY, (posY + size) do
			distX =	math.abs(x-(size * 0.5)-posX)
			distY = math.abs(y-(size * 0.5)-posY)
			dist = math.sqrt((distX*distX) + (distY*distY)) -- circular
			maxW = size * 0.5 - 10
			delta = dist / maxW
			gradient = delta * delta

			grid[x] = grid[x] or {}
			xCoord = x/size * scale
			yCoord = y/size * scale
			zCoord = scale
			Noise = love.math.noise(xCoord+seedx,yCoord+seedy, zCoord+seedz) --changed this
			grid[x][y] = Noise * pickMax(0, 1-gradient)
		end
	end
	local rn = love.math.random(200, 450)/1000
	newIsland = {
					x = posX, y = posY,
					level = rn,
					Noise = n,
					g = grid
				}
	table.insert(islands, newIsland)
end
It was generating the same island, just with a different level.

Re: Crude Island Generator (11.2)

Posted: Fri Feb 01, 2019 7:29 am
by BlueThumbDevelopment
KayleMaster wrote: Thu Jan 31, 2019 8:49 pm You almost got it !
I ran it at first, and it seemed ok,but as I generated more islands, they all looked the same to me, just minor variations.
So I seeded the noise with three values that are randomised everytime you press G, the results are much better now.

Code: Select all

function noise(posX,posY)
	-- and added these three lines
	seedx =love.math.random( 500 )
	seedy =love.math.random( 500 )
	seedz =love.math.random( 500 )
	grid = {}
	local scale = 10
	for x = posX, (posX + size) do
		for y = posY, (posY + size) do
			distX =	math.abs(x-(size * 0.5)-posX)
			distY = math.abs(y-(size * 0.5)-posY)
			dist = math.sqrt((distX*distX) + (distY*distY)) -- circular
			maxW = size * 0.5 - 10
			delta = dist / maxW
			gradient = delta * delta

			grid[x] = grid[x] or {}
			xCoord = x/size * scale
			yCoord = y/size * scale
			zCoord = scale
			Noise = love.math.noise(xCoord+seedx,yCoord+seedy, zCoord+seedz) --changed this
			grid[x][y] = Noise * pickMax(0, 1-gradient)
		end
	end
	local rn = love.math.random(200, 450)/1000
	newIsland = {
					x = posX, y = posY,
					level = rn,
					Noise = n,
					g = grid
				}
	table.insert(islands, newIsland)
end
It was generating the same island, just with a different level.
Thanks Kaylemaster, I really appreciate the feedback!