Last active
March 22, 2016 17:17
-
-
Save joelgrus/b27c12fc159367ea2440 to your computer and use it in GitHub Desktop.
trying to sequence effects in purescript-flare
This file contains 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
width :: Number | |
width = 600.0 | |
height :: Number | |
height = 600.0 | |
-- Generate a Drawing of n deterministic points | |
nonRandomPoints :: Int -> Drawing | |
nonRandomPoints n = foldMap makeCircle points | |
where | |
makeCircle p = filled (fillColor black) $ circle p.x p.y 10.0 | |
n' = toNumber n | |
points = map (\i -> { x : width * (toNumber i) / n', y : height * (toNumber i) / n'}) (1..n) | |
main = do | |
runFlareDrawing "controls" "canvas" points | |
where | |
points = nonRandomPoints <$> intRange "numPoints" 1 100 10 |
This file contains 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
-- Generate a random point | |
randomPoint :: forall eff. Eff (random :: RANDOM | eff) Point | |
randomPoint = do | |
x <- randomRange 0.0 width | |
y <- randomRange 0.0 height | |
return { x: x, y: y} | |
-- Generate a drawing consisting of n random points | |
randomPoints :: forall eff. Int -> Eff (random :: RANDOM | eff) Drawing | |
randomPoints n = (foldMap makeCircle) <$> points | |
where | |
makeCircle p = filled (fillColor black) $ circle p.x p.y 10.0 | |
points = replicateM n randomPoint | |
-- this doesn't work, I need to somehow combine the `Eff RANDOM` and the `UI` | |
main = do | |
runFlareDrawing "controls" "canvas" points | |
where | |
points = randomPoints <$> intRange "numPoints" 1 100 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment