Alex Schroeder/Island Generation
Jump to navigation
Jump to search
For a map generator of mine I needed to prototype an island generation algorithm. Inspired by archipelagos like Hawaii and the Galapagos, I wanted the following:
- a hot spot moves across the map, lifting land up
- behind the hot spot, land starts sinking again
- the uplift is spotty because there are volcanoes, and parasitic cones, etc. It's not always clear where the land gets lifted
- the sinking is also spotty because hard lava cores can be left behind, softer material gets eroded, crusts break and sink
- the sinking must be somewhat slower than the rising or else there won't be much of an island chain to see
J901 version
mx =: 30 my =: 20 NB. a table of complex numbers c =: (i. my) j./ i. mx NB. starting position of the hotspot hr =: 6 hy =: >. hr % 2 hx =: <. 0.5 + (my % 3) + ? <. 0.5 + my % 3 hc =: hx j. hy NB. a function to compute altitude changes based on where the hotspot is change =: 3 : 0 h =. hr > {. & *. c - y NB. hotspot = 1 u =. 0.85 < ? (my, mx) $ 0 NB. regions atop the hotspot might move up d =. 0.7 < ? (my, mx) $ 0 NB. regions off the hotspot might move down (u * h) - d * -. h ) NB. a biased list of steps to take d =: _1j1 1j1 0j1 NB. a table of altitudes a =: (my, mx) $ 0 NB. compute the meandering path of the hotspot across the map NB. compute the change for each step and add it to the altitude NB. no negative values 3 : 0'' for. i. mx - 2 * hr do. hc =: hc+(?#d){d a =: 0 & >. a + change hc end. ) decimal =:16"_#.'0123456789abcdef'"_ i.] rgb =: 3 : 0 n =. decimal }. y NB. strip leading # (<.n % 65536), ((<.n % 256) |~ 256), (n |~ 256) ) ocean =: rgb '#1c86ee' NB. 0 water =: rgb '#6ebae7' NB. 1 sand =: rgb '#e3bea3' NB. 2 dry =: rgb '#c97457' NB. 3 nice =: rgb '#b0b446' NB. 4 green =: rgb '#77904c' NB. 5 humid =: rgb '#2d501a' NB. 6 rocky =: rgb '#dcddbe' NB. 7 colors =: (ocean, water, sand, dry, nice, green, humid,: rocky) colors viewmat a
iPad version
mx =: 30 my =: 20 NB. a table of complex numbers c =: (i. my) j./ i. mx NB. a table of altitudes a =: (my, mx) $ _2 NB. center of the hotspot hr =: 5 hy =: >. hr % 2 hx =: <. 0.5 + (my % 3) + ? <. 0.5 + my % 3 hc =: hx j. hy NB. a list of translations d =: _1j0 1j0, 4 $ 0j1 m =: ( ? 30 # # d ) { d NB. start loop 3 : 0'' for_i. m do. hc =: hc + i NB. move hotspot center h =: 5 > {. & *. c - hc NB. hotspot = 1 l =: -. _2 = a * -. h NB. outside the hotspot -2 is the limit r =: 0.8 < ? (my, mx) $ 0 NB. 20% of regions are potentially active s =: 0.5 < ? (my, mx) $ 0 NB. 50% of regions... t =: h + s * -. h NB. ...will ignore the activity a =: a + r * t* l * _1 + 2 * h end. ) jv a