Skip to content

Instantly share code, notes, and snippets.

@ericfode
Created July 7, 2012 19:55
Show Gist options
  • Save ericfode/3067908 to your computer and use it in GitHub Desktop.
Save ericfode/3067908 to your computer and use it in GitHub Desktop.
import System.Random
import Wumpus.Core
import Wumpus.Core.Colour
import Wumpus.Drawing.Shapes
import Wumpus.Basic.Kernel
import System.Directory
makeRandomPoint :: (RandomGen g, Random f) => (f , f) -> g -> ((f,f),g)
makeRandomPoint limit gen =
let (x , ngen) = randomR limit gen
(y , ngen2) = randomR limit ngen
in ((x,y),ngen2)
sqr x = x*x
divp :: (Floating f) => (f,f) -> f -> (f,f)
divp point scale = (((fst point)/scale),((snd point) / scale))
getr :: (Floating f) => (f,f) -> f
getr point = sqrt (sqr (fst point)) + (sqr (snd point))
linear :: (Floating f) => (f,f) -> (f,f)
linear point= point
sinusoidal :: (Floating f) => (f,f) -> (f,f)
sinusoidal point = (sin (fst point), sin (snd point))
spherical :: (Floating f) => (f,f) -> (f,f)
spherical point = (divp point (sqr (getr point)))
swirl point =
((fst point) * sin (sqr (getr point)) - (snd point) * cos (sqr (getr point)),
(fst point) * cos (sqr (getr point)) - (snd point) * sin (sqr (getr point)))
horseshoe :: (Floating f) => (f,f) -> (f,f)
horseshoe point =
((1/(getr point)) * (((fst point) - (snd point))*((fst point )+ (snd point))),
2 * (fst point) * (snd point))
funcs = [linear, sinusoidal, spherical, swirl, horseshoe]
colors = [(11,33,22),(233,213,32),(221,112,78),(23,234,33),(23,234,10)]
mutate world gen funcs point cur < max =
let (i, gen) = randomR (0,4) gen
newC = c +
newPoint = (funcs || i) point
newCur = cur +1
newWorld = world ++ newpoint
mutate newWorld gen func newPoint newCur max
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment