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.
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!
Crude Island Generator (11.2)
-
- Prole
- Posts: 7
- Joined: Mon Jan 21, 2019 5:36 pm
- Contact:
-
- Party member
- Posts: 234
- Joined: Mon Aug 29, 2016 8:51 am
Re: Crude Island Generator (11.2)
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.
It was generating the same island, just with a different level.
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
-
- Prole
- Posts: 7
- Joined: Mon Jan 21, 2019 5:36 pm
- Contact:
Re: Crude Island Generator (11.2)
Thanks Kaylemaster, I really appreciate the feedback!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.
It was generating the same island, just with a different level.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
Who is online
Users browsing this forum: No registered users and 6 guests