-- An alternate version of Sierpinski's triangle from SOE, -- putting the graphics commands in a list and sequencing -- them. This is not a better way, just a different one. -- Scot Drysdale on 10/3/07 module SierpinskiAlt where import Graphics.SOE.Gtk spaceClose :: Window -> IO () spaceClose w = do k <- getKey w if k==' ' || k == '\x0' then closeWindow w else spaceClose w fillTri :: Window -> Int -> Int -> Int -> IO () fillTri w x y size = drawInWindow w (withColor Blue (polygon [(x,y),(x+size,y),(x,y-size),(x,y)])) minSize :: Int minSize = 8 sierpinskiTri :: Window -> Int -> Int -> Int -> [IO ()] sierpinskiTri w x y size = if size <= minSize then [fillTri w x y size] else let size2 = size `div` 2 in (sierpinskiTri w x y size2) ++ (sierpinskiTri w x (y-size2) size2) ++ (sierpinskiTri w (x+size2) y size2) main = runGraphics ( do w <- openWindow "Sierpinski's Triangle" (400,400) sequence_ (sierpinskiTri w 50 300 256) spaceClose w )