Created
September 12, 2014 20:46
-
-
Save highfestiva/663527457bea3191e2dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Graphics.Gloss | |
main = animate (InWindow "Tree" (500, 650) (20, 20)) | |
black (picture 4) | |
picture :: Int -> Float -> Picture | |
picture degree time | |
= Translate 0 (-300) | |
$ tree degree time (dim $ dim brown) | |
stump :: Color -> Picture | |
stump color | |
= Color color | |
$ Polygon [(30,0), (15,300), (-15,300), (-30,0)] | |
tree :: Int -- Fractal degree | |
-> Float -- time | |
-> Color -- Color for the stump | |
-> Picture | |
tree 0 time color = stump color | |
tree n time color | |
= let smallTree | |
= Rotate (sin time) | |
$ Scale 0.5 0.5 | |
$ tree (n-1) (- time) (greener color) | |
in Pictures | |
[ stump color | |
, Translate 0 300 $ smallTree | |
, Translate 0 240 $ Rotate 20 smallTree | |
, Translate 0 180 $ Rotate (-20) smallTree | |
, Translate 0 120 $ Rotate 40 smallTree | |
, Translate 0 60 $ Rotate (-40) smallTree ] | |
brown :: Color | |
brown = makeColor8 139 100 35 255 | |
greener :: Color -> Color | |
greener c = mixColors 1 10 green c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment