@@ -11,12 +11,7 @@ fn main() {
11
11
width: 1024
12
12
height: 768
13
13
frame_fn: unsafe { state.draw }
14
- event_fn: fn (event & gg.Event, ctx voidptr ) {
15
- if event.typ == .char && event.char_code == `f` {
16
- gg.toggle_fullscreen ()
17
- return
18
- }
19
- }
14
+ event_fn: unsafe { state.on_event }
20
15
)
21
16
}
22
17
@@ -35,6 +30,7 @@ struct State {
35
30
mut :
36
31
t f32
37
32
real_t f32
33
+ drt f32 = 0.1
38
34
tparams gg.DrawTextParams
39
35
rects []BigRect
40
36
}
@@ -45,7 +41,9 @@ const colors = []gg.Color{len: 1024, init: gg.Color{u8(100 +
45
41
46
42
fn init_state () State {
47
43
mut state := State{
48
- real_t: 1300
44
+ t: 0
45
+ real_t: 120
46
+ drt: 0.1
49
47
tparams: gg.DrawTextParams{
50
48
x: 40
51
49
size: 20
@@ -69,6 +67,41 @@ fn init_state() State {
69
67
return state
70
68
}
71
69
70
+ fn (mut state State) on_event (e & gg.Event, ctx voidptr ) {
71
+ if e.typ == .char {
72
+ if e.char_code == `f` {
73
+ gg.toggle_fullscreen ()
74
+ return
75
+ }
76
+ if e.char_code == `1` {
77
+ state.real_t - = 100
78
+ }
79
+ if e.char_code == `2` {
80
+ state.real_t + = 100
81
+ }
82
+ if e.char_code == `3` {
83
+ state.t - = 100
84
+ }
85
+ if e.char_code == `4` {
86
+ state.t + = 100
87
+ }
88
+ if e.char_code == `5` {
89
+ state.rects[0 ].w + = 10
90
+ }
91
+ if e.char_code == `6` {
92
+ state.rects[0 ].w - = 10
93
+ }
94
+ if e.char_code == `r` {
95
+ state.real_t = 120
96
+ state.t = 0
97
+ state.rects[0 ].w = 30
98
+ }
99
+ if e.char_code == ` ` {
100
+ state.drt = if state.drt > 0.0001 { f32 (0.0 ) } else { 0.1 }
101
+ }
102
+ }
103
+ }
104
+
72
105
fn (mut state State) draw (ctx & gg.Context) {
73
106
update (mut state)
74
107
ctx.begin ()
@@ -80,7 +113,7 @@ fn (mut state State) draw(ctx &gg.Context) {
80
113
ctx.draw_text2 (gg.DrawTextParams{
81
114
...state.tparams
82
115
y: 0
83
- text: 'real_t : ${state.real_t:7 .3f} , r : ${state.t:7 .3f} , r0.x: ${r0.x:7 .3f} , r0.y: ${r0.y:7 .3f} '
116
+ text: 'rt[1,2] : ${state.real_t:08 .3f} , t[3,4] : ${state.t:08 .3f} , r0.x: ${r0.x:07 .3f} , r0.y: ${r0.y:07 .3f} , r0.w[5,6]: ${r0.w:4.1f} , [f]-toggle fs, [r]-reset, [ ]-pause '
84
117
})
85
118
draw_center_point (ctx, r0 , state.t)
86
119
ctx.show_fps ()
@@ -89,8 +122,11 @@ fn (mut state State) draw(ctx &gg.Context) {
89
122
90
123
@[live]
91
124
fn update (mut state State) {
92
- state.real_t + = 0.1
93
- state.t + = 0.5 * math.sinf (state.real_t / 7000 )
125
+ if state.drt < = 0.0001 {
126
+ return
127
+ }
128
+ state.real_t + = state.drt
129
+ state.t + = 0.5 * math.sinf (state.real_t / 1000 )
94
130
mut r0 := & state.rects[0 ]
95
131
r0 .t = state.t
96
132
r0 .x = 550 + 450 * math.sinf (state.t / 10 ) * math.sinf (state.t / 50 )
0 commit comments