local coords = require"common.coords" local noise = require"noise" local chunk = require"common.chunk" local ChunkS = require"chunk".ChunkS local CHUNK_SIZE = require"common.constants".CHUNK_SIZE local function p(amp,scale) return {scale=scale,amp=amp,gen=noise.PerlinNoise:make()} end -- local ng = noise.NoiseAgg:make{ -- p(1,20), -- -- p(0.7,2), -- p(0.5,15), -- --p(2,200), -- } -- whether there is a tile there or not local surface_ng = noise.NoiseAgg:make{p(1,20),p(0.5,15)} -- if there is a tile there, what color should it be local color_ng = noise.NoiseAgg:make{p(1,20),p(0.5,15)} local function gen_chunk(chpos) local htl,hbr = chpos:extents() local tiles = {} for q = 0,CHUNK_SIZE-1 do for r = 0,CHUNK_SIZE-1 do local p = (htl+coords.Hex:make(q,r)):to_pos() local ix = chunk.index(q,r) local nv = surface_ng:at(p.x,p.y) if nv <= 0 then tiles[ix] = false else local nv2 = color_ng:at(p.x,p.y) nv2 = math.max(-0.9999999,math.min(0.9999999,nv2*2.5)) nv2 = (nv2+1)/2 local tv = 1+math.floor(nv2*8) assert(1<=tv and tv<=8,"oopsy woopsy") tiles[ix] = tv end end end local the_chunk = ChunkS:make(chpos,tiles) return the_chunk end return { gen_chunk=gen_chunk }