Created
          October 8, 2014 06:37 
        
      - 
      
 - 
        
Save shashi/dbcd76670409de0ccbe3 to your computer and use it in GitHub Desktop.  
    Sierpinski's triangles in Elm
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | {- Sierpinski's triangle -} | |
| hscale = sqrt(3) / 2 | |
| triangle a = | |
| filled black (path [(-a / 2, -hscale * a / 2), | |
| (a / 2, -hscale * a / 2), | |
| (0, hscale * a / 2)]) | |
| sierpinski (x, y) a n = | |
| if n == 0 then | |
| move (x, y) (triangle a) | |
| else | |
| group [ | |
| sierpinski (x - a / 4, y - hscale *a / 4) (a / 2) (n - 1), | |
| sierpinski (x + a / 4, y - hscale *a / 4) (a / 2) (n - 1), | |
| sierpinski (x, y + hscale * a / 4) (a / 2) (n - 1) | |
| ] | |
| main = collage 400 400 [ sierpinski (0, 0) 300 8 ] | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment