Skip to content

Instantly share code, notes, and snippets.

@weskerfoot
Created November 28, 2012 21:40
Show Gist options
  • Save weskerfoot/4164779 to your computer and use it in GitHub Desktop.
Save weskerfoot/4164779 to your computer and use it in GitHub Desktop.
lsysgraphics.hs
{-# LANGUAGE GADTs, FlexibleInstances #-}
import Graphics.Gloss
import Graphics.Gloss.Data.Vector
import LSystem
data PlantInstruction a where
DrawForward :: PlantInstruction a
TurnLeft :: (Show a, Num a) => a -> PlantInstruction a
TurnRight :: (Show a, Num a) => a -> PlantInstruction a
SaveState :: (Show a, Num a) => (a, [Point]) -> PlantInstruction [(a, [Point])]
PopState :: (Show a, Num a) => [(a, [Point])] -> PlantInstruction [(a, [Point])]
decision :: (Show a, Num a) => Char -> PlantInstruction a
decision state current c = case c of
'F' -> DrawForward
'-' -> TurnLeft 25
'+' -> TurnRight 25
'[' -> SaveState
instance Show (PlantInstruction a) where
show DrawForward = "DrawForward"
show (TurnLeft n) = "TurningLeft " ++ (show n)
show (TurnRight n) = "TurningRight " ++ (show n)
-- main = display (InWindow "Nice Window" (200, 200) (10, 10)) red (Circle 80)
rotfact = 0.785398163
ps = pictures [(Line [(310,210), (rotateV rotfact (500,500))])
, (Line [(110,210), (rotateV rotfact (500,500))])
, (Line [(110,210), (rotateV rotfact (500,500))])]
-- main = display (InWindow "Nice Window" (200, 200) (10, 10)) white (color red ps)
main = print $ decision '+'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment