Created
November 28, 2012 21:40
-
-
Save weskerfoot/4164779 to your computer and use it in GitHub Desktop.
lsysgraphics.hs
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
{-# 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