Skip to content

Instantly share code, notes, and snippets.

@Gabriella439
Last active March 31, 2018 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Gabriella439/fd0a56258160a67e89e3 to your computer and use it in GitHub Desktop.
Save Gabriella439/fd0a56258160a67e89e3 to your computer and use it in GitHub Desktop.
Purescript Flare - Simon example
<!DOCTYPE html>
<html>
<head>
<title>Try Flare!</title>
<link rel="stylesheet" href="css/style.css">
</head>
<div id="input"></div>
<canvas id="output" width="800" height="800"></canvas>
</html>
module Main where
import Data.Array ((..), reverse)
import Data.Int (toNumber)
import Flare (UI, radioGroup)
import Flare.Drawing (runFlareDrawing)
import Graphics.Drawing
import Graphics.Drawing.Font (font, sansSerif, bold)
import Math (cos, sin, pi)
import Prelude
data Illumination = Lit | Unlit
quadrant :: Color -> Illumination -> Drawing
quadrant color illumination = filled (fillColor c) shape
where
c = case illumination of
Unlit -> color
Lit -> lighten 0.5 color
shape = path (points 100.0 (2..89) ++ points 50.0 (reverse (3..87)))
points radius angles = do
theta <- map (\i -> toNumber i * pi / 180.0) angles
return ({ x: radius * cos theta, y: radius * sin theta })
points2 = []
points3 = []
points4 = []
quadrant0 :: Illumination -> Drawing
quadrant0 i = rotate (0.0 * pi / 2.0) (quadrant blue i)
quadrant1 :: Illumination -> Drawing
quadrant1 i = rotate (1.0 * pi / 2.0) (quadrant yellow i)
quadrant2 :: Illumination -> Drawing
quadrant2 i = rotate (2.0 * pi / 2.0) (quadrant green i)
quadrant3 :: Illumination -> Drawing
quadrant3 i = rotate (3.0 * pi / 2.0) (quadrant red i)
background :: Drawing
background = filled (fillColor black) (circle 0.0 0.0 103.0)
data Direction = Blue | Yellow | Green | Red
showDirection :: Direction -> String
showDirection Blue = "Blue"
showDirection Yellow = "Yellow"
showDirection Green = "Green"
showDirection Red = "Red"
board :: Direction -> Drawing
board d = translate 110.0 110.0 drawing
where
f = font sansSerif 30 bold
drawing =
background
<> quadrant0 i0
<> quadrant1 i1
<> quadrant2 i2
<> quadrant3 i3
<> text f (-43.0) 7.0 (fillColor white) "simon"
i0 = case d of
Blue -> Lit
_ -> Unlit
i1 = case d of
Yellow -> Lit
_ -> Unlit
i2 = case d of
Green -> Lit
_ -> Unlit
i3 = case d of
Red -> Lit
_ -> Unlit
ui :: UI _ Drawing
ui = map board (radioGroup "Color" Blue [Yellow, Green, Red] showDirection)
main = runFlareDrawing "input" "output" ui
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment