Skip to content

Instantly share code, notes, and snippets.

@yuanw
Last active September 25, 2016 04:26
Show Gist options
  • Select an option

  • Save yuanw/6a7457a4e924faba6acf085837a27c36 to your computer and use it in GitHub Desktop.

Select an option

Save yuanw/6a7457a4e924faba6acf085837a27c36 to your computer and use it in GitHub Desktop.
{-# LANGUAGE OverloadedStrings #-}
import CodeWorld
botCircle c = colored c (translated 0 (-1.5) (solidCircle 1))
middleCircle c = colored c (translated 0 1.5 (solidCircle 1))
topCircle c = colored c (translated 0 4.5 (solidCircle 1))
frame = rectangle 2.5 12.0
trafficLight 0 = botCircle green & middleCircle black & topCircle black & frame
trafficLight 1 = botCircle black & middleCircle yellow & topCircle black & frame
trafficLight 2 = botCircle black & middleCircle black & topCircle red & frame
trafficLight 3 = botCircle black & middleCircle yellow & topCircle red & frame
trafficController :: Double -> Picture
trafficController t = trafficLight ( round (t/3) `mod` 4)
main :: IO ()
main = animationOf trafficController
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment