From 7dbf9cca101d12fe338f74f7edb64c4b19525222 Mon Sep 17 00:00:00 2001 From: "Yann Esposito (Yogsototh)" Date: Wed, 9 Jan 2013 15:37:54 +0100 Subject: [PATCH] sierpinsky --- flame.elm | 52 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/flame.elm b/flame.elm index b49c596..851d645 100644 --- a/flame.elm +++ b/flame.elm @@ -2,8 +2,7 @@ module Flame where import Random - - +-- Solarized colors base03 = rgb 0 43 54 base02 = rgb 7 54 66 base01 = rgb 88 110 117 @@ -21,9 +20,10 @@ blue = rgb 38 139 210 cyan = rgb 42 161 152 green = rgb 133 153 0 -mybase = rgba 147 161 161 (2/3) +-- mybase = rgba 147 161 161 (2/3) +mybase = rgba 108 113 196 (2/3) -point = filled mybase . rect 20 20 +point = filled mybase . rect 1 1 background w h = filled base3 ( rect w h (div w 2,div h 2)) @@ -42,8 +42,46 @@ randcouples seed k = if (k<0) then [] nns = nextint ns in (ns,nns):randcouples nns (k-1) -scene (x,y) (w,h) = +scene (x,y) (w,h) points = let modpoint (x,y) = (rem x w,rem y h) - in collage w h $ background w h:map (point . modpoint) (randcouples (div y 10) (div x 10)) + in collage w h $ + background w h: + map (point . modpoint) points -main = lift2 scene Mouse.position Window.dimensions + +vs = [ \(x,y) -> (x,y) + , \(x,y) -> (sin x, sin y) + , \(x,y) -> let r2 = x*x+y*y in (x/r2,y/r2) + , \(x,y) -> let r2 = x*x+y*y in (x*(sin r2) - y*(cos r2),x*(cos r2) + y * (sin r2)) + , \(x,y) -> let r = sqrt (x^2+y^2) in ((x - y)*(x + y)/r,2*x*y/r) + ] + +aff a b c d e f (x,y) = (a*x + b*y + c, d*x + e*y +f) + +sierp = [ aff + 0.5 0.0 0.0 + 0.0 0.5 0.0 + , aff + 0.5 0.0 0.5 + 0.0 0.5 0.0 + , aff + 0.5 0.0 0.0 + 0.0 0.5 0.5 + ] + +-- (!!) :: [a] -> Int -> [a] +l !! n = if n == 0 then head l else (tail l) !! (n-1) + +sierpset startpoint rands = + if rands == [] + then [] + else + let + randval=(head rands) `rem` (length sierp) + newpoint = (sierp !! randval) startpoint + in + newpoint:(sierpset newpoint (tail rands)) + +sierpinsky = map (\(x,y) -> (x*300,y*300)) $ drop 20 $ sierpset (0.132,0.432) (randlist 0 10000) + +main = lift3 scene Mouse.position Window.dimensions (constant sierpinsky)