Skip to content

Instantly share code, notes, and snippets.

@JeanRibes
Last active November 27, 2019 23:23
Show Gist options
  • Save JeanRibes/8ce785d24c8ad8a7ef0bbd4c72b5efa0 to your computer and use it in GitHub Desktop.
Save JeanRibes/8ce785d24c8ad8a7ef0bbd4c72b5efa0 to your computer and use it in GitHub Desktop.
ELP Logoskell
import Prelude hiding (Left, Right)
data Instruction = Forward Int| Left Int| Right Int| Repeat Int [Instruction] deriving (Show, Read)
derouler [] a = a
derouler (i:rprog) a = case i of
(Repeat x ri)->derouler rprog ((concat (replicate x (derouler ri [])) )++a)
_ ->derouler rprog (i:a)
points [] posx posy angle pts = pts
points (i:rprog) posx posy angle pts = case i of
Left t->points rprog posx posy (angle+((realToFrac t)*3.1415/180)) pts
Right t->points rprog posx posy (angle-((realToFrac t)*3.1415/180)) pts
Forward l->(points rprog nposx nposy angle ((nposx,nposy):pts))
where nposx=posx+(realToFrac l)*(cos angle)
nposy=posy+(realToFrac l)*(sin angle)
svgligne [] svg = svg
svgligne pl svg= if (length pl)>1 then (svgligne (tail pl) ("<line x1=\"" ++(show (fst $ head pl))++ "\" y1=\"" ++(show (snd $ head pl))++ "\" x2=\"" ++(show (fst (pl!!1)))++ "\" y2=\"" ++(show (snd (pl!!1)))++ "\" stroke=\"red\" stroke-width=\"1\" />\n" ++ svg)) else svgligne [] svg
toutfaire string = "<?xml version=\"1.0\" encoding=\"utf-8\"?><svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width=\"200\" height=\"200\">" ++(svgligne (reverse (reverse $ points (derouler (read string :: [Instruction]) []) 0 0 0 [(0,0)])) "</svg>")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment