0hc.net Menu
Home Overview
About Menu
Impressum

Sierpinski Gasket

Compile with the following options: ghc -optl-mwindows -O2 -fexcess-precision -optc-O3 -optc-ffast-math -no-recomp -package GLUT -o sierpinski.exe sierpinski.hs module Main where import Graphics.UI.GLUT import Graphics.Rendering.OpenGL import System.Random main :: IO () main = do (progName,_) <- getArgsAndInitialize createWindow progName displayCallback $= displayPoints mainLoop displayPoints = do clear [ColorBuffer] currentColor $= Color4 1 1 0 1 renderPrimitive Points $ mapM_ (\(x,y) -> vertex $ Vertex2 x y) myS flush myS :: [(GLfloat, GLfloat)] myS = fR1 (0.0,0.9) (rand 50000) [] fR1 x [] z = x:z fR1 x (y:ys) z = fR1 a ys (a:z) where a = fR y x fR 1 (x,y) = (x/2,(0.9+y)/2) fR 2 (x,y) = ((x-0.9)/2,(y-0.9)/2) fR _ (x,y) = ((0.9+x)/2,(y-0.9)/2) rand x = take x $ randList 1 3 101 randList sm hi st = randomRs (sm,hi) (mkStdGen st)
0hc.net    © 2001-2014 Harald Wolfsgruber