-
Notifications
You must be signed in to change notification settings - Fork 5
/
App.fm
46 lines (43 loc) · 1.39 KB
/
App.fm
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
43
44
45
46
T App<S: Type>
| App.new(
init: S,
draw: S -> App.Render,
when: App.Event -> S -> S);
T App.Render
| App.Render.txt(text: String);
| App.Render.pix(size: U32, draw: U32 -> Pair(U32,U32));
T App.Event
| App.Event.tick(date: U64, screen: Pair(U32,U32), mouse: Pair(U32,U32));
| App.Event.ukey(down: Bool, code: U16);
| App.Event.post(date: U64, auth: String, name: String, head: String, body: String);
// A demo application
App.demo.0: App(Pair(U32,U32))
def u32
Nat.to_u32
def init
Pair.new<,>(U32.0, U32.0)
def draw(state)
def size
u32(256)
def draw(i)
case state:
| let m_x = state.fst // mouse x
let m_y = state.snd // mouse y
let i_x = U32.mod(i, u32(16)) // square x
let i_y = U32.div(i, u32(16)) // square y
let p_x = U32.sub(U32.add(m_x, i_x), u32(8)) // pixel x
let p_y = U32.sub(U32.add(m_y, i_y), u32(8)) // pixel y
let p_z = u32(128) // pixel z
let pos = U32.0
let pos = U32.or(U32.mul(p_x, u32(1048576)), pos)
let pos = U32.or(U32.mul(p_y, u32(256)), pos)
let pos = U32.or(U32.mul(p_z, u32(1)), pos)
let col = u32(4278190335) // rgba(255,0,0,255)
Pair.new<,>(pos, col);
App.Render.pix(size, draw)
def when(event, state)
case event:
| tick => event.mouse; // sets state to mouse pos
| ukey => state;
| post => state;
App.new<>(init, draw, when)