I have a function here (inspired by https://github.com/amitp/mapgen2/blob/master/Map.as in the islandshape factory function) that should seperate a square map into land and water. Like so: disregard the different biomes
Buut, in the function I use below, the whole thing seems to just come out as water...
--makeRadial decides which points are on land or water based on overlapping sine waves (random radial island)
function makeRadial(seed) --factory function to return same randoms for inside(), unless new island is created
local bumps = math.random(1, 6)
math.randomseed(seed)
local startAngle = math.random() * (2*math.pi)
local dipAngle = math.random() * (2*math.pi)
local dipWidth = math.random() * 0.5 + 0.2
local inside = function (point)
if not point then return end
local angle = math.atan2(point.y, point.x)
local length = 0.5 * (math.max(math.abs(point.x), math.abs(point.y) + point.magnitude))
local r1 = 0.5 + 0.40*math.sin(startAngle + bumps*angle + math.cos((bumps+3)*angle))
local r2 = 0.7 - 0.20*math.sin(startAngle + bumps*angle - math.sin((bumps+2)*angle))
if math.abs(angle - dipAngle) < dipWidth
or math.abs(angle - dipAngle + 2*math.pi) < dipWidth
or math.abs(angle - dipAngle - 2*math.pi) < dipWidth then
r1, r2 = 0.2, 0.2
end
print("length:"..length.." < ".." r1:"..r1.." or < ".." r2:"..r2)
return length < r1 or (length > r1*ISLAND_FACTOR and length < r2)
end
return {
inside = inside
}
end
And the function below just redistributes the points from -1.0 to 1.0 and plugs them into the actual function
function inside(point, SIZE)
local islandshape = makeradial(*random seed*)
return islandshape.inside(2*(point.x/SIZE - 0.5), 2*(point.y/SIZE - 0.5))
end
This algorithm creates an island based on overlapping sine waves (smooth single large island with mostly no tiny islands off to the side). However, there is a problem with the length variable.
Just as a note: I discern water from land by setting a water boolean to each corner of a tile (corner.water = not inside(corner.point)) and then setting the tile as water based on the average of its corners.
Anyways the length variable seems to always come out greater than r1 and r2:
length:1.1783428788185 r1:0.76499270607242 r2:0.68719228997449
length:1.1779255270958 r1:0.76592961292669 r2:0.68729183465378
length:1.1775082945824 r1:0.7668633458924 r2:0.68739145169441
I'm not an expert in trigonometry, so I don't know if length is the problem here... but I think it may be a factor since I translated this from C. FYI, point.magnitude is just the distance of the point from 0,0.
Thanks in advance!