-
Notifications
You must be signed in to change notification settings - Fork 9
/
colortest.fsx
37 lines (32 loc) · 1.04 KB
/
colortest.fsx
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
#r "nuget:DIKU.Canvas, 2.0"
open Canvas
open Color
type state = color // state is a color
let w,h = 600,600 // window size
/// Prepare a Picture by the present state whenever needed
let draw (s:state): Picture =
filledRectangle s w h
|> make
/// React to whenever an event happens
/// All but left-, right-, up-, and down-arrows are ignored. Each of these
/// key-presses produces a window with a unique color.
/// Present state is ignored.
let react _ (ev:Event) : state option =
match ev with
| LeftArrow ->
printfn "Going red!"
Some red
| RightArrow ->
printfn "Going blue!"
Some blue
| DownArrow ->
printfn "Going green!"
Some green
| UpArrow->
printfn "Going yellow!"
Some yellow
| _ -> None // ignore event, state is not updated
// Start interaction session
let initialState = red // First state drawn by draw
let delayTime = None // no delay time
interact "ColorTest" w h delayTime draw react initialState