-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrandom.hs
More file actions
42 lines (38 loc) · 1.06 KB
/
random.hs
File metadata and controls
42 lines (38 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
{-# LANGUAGE OverloadedStrings #-}
import Graphics.Web.Processing.Mid
import Graphics.Web.Processing.Html
import Control.Applicative ((<$>))
main :: IO ()
main = writeHtml "processing.js" "random.pde" "Random demo" "random.html" randomDemo
randomDemo :: ProcScript
randomDemo = execScriptM $ do
vi <- newVar 0
vj <- newVar 0
rv <- newVar 0
gv <- newVar 0
bv <- newVar 0
on Setup $ do
size screenWidth screenHeight
background $ Color 255 255 255 255
setFrameRate 30
on Draw $ do
strokeWeight $ div screenWidth 40
-- Random color
random rv 0 50
r <- pround <$> readVar rv
random gv 0 255
g <- pround <$> readVar gv
random bv 0 255
b <- pround <$> readVar bv
stroke $ Color r g b 100
-- Top position
i <- readVar vi
-- Bottom position
random vj 0 (intToFloat screenWidth)
j <- readVar vj
-- Line
line (intToFloat i,0) (j,intToFloat screenHeight)
-- Update top position
ifM (i #>= screenWidth)
(writeVar vi 0)
(writeVar vi $ i + div screenWidth 250)