Skip to content

Commit 71ff221

Browse files
authored
gg: update draw polygon test (#14880)
1 parent e4a49d5 commit 71ff221

File tree

1 file changed

+34
-11
lines changed

1 file changed

+34
-11
lines changed

vlib/gg/testdata/draw_simple_polygons.vv

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1+
module main
2+
13
import gg
24
import gx
35

46
struct App {
57
mut:
6-
gg &gg.Context = 0
8+
gg &gg.Context = unsafe { 0 }
79
rotation f32 = f32(0)
10+
edge int = 3
811
}
912

1013
[console]
1114
fn main() {
15+
println('rotation: left arrow key, right arrow key')
16+
println('center polygon edge: up arrow key, down arrow key')
17+
1218
mut app := &App{}
1319

1420
app.gg = gg.new_context(
@@ -33,28 +39,45 @@ fn render(app &App) {
3339
b: 0
3440
a: 200
3541
}
36-
mut shape := 3
37-
for i := 1; i < 5; i++ {
38-
for j := 1; j < 5; j++ {
39-
app.gg.draw_polygon_filled(100 * j, 100 * i, 30, shape, app.rotation, color)
40-
shape++
42+
mut edge := 3
43+
for i := 0; i <= 5; i++ {
44+
for j := 0; j <= 5; j++ {
45+
if i == 0 || j == 0 || i == 5 || j == 5 {
46+
app.gg.draw_polygon_filled(50 + 80 * i, 50 + 80 * j, 30, edge, app.rotation,
47+
color)
48+
edge++
49+
}
4150
}
4251
}
4352

53+
app.gg.draw_polygon_filled(250, 250, 150, app.edge, app.rotation, color)
54+
4455
app.gg.end()
4556
}
4657

4758
fn event(e &gg.Event, mut app App) {
4859
match e.typ {
4960
.key_down {
5061
match e.key_code {
51-
.right { app.rotation++ }
52-
.left { app.rotation-- }
53-
.escape { app.gg.quit() }
62+
.up {
63+
app.edge++
64+
}
65+
.down {
66+
if app.edge > 3 {
67+
app.edge--
68+
}
69+
}
70+
.right {
71+
app.rotation++
72+
}
73+
.left {
74+
app.rotation--
75+
}
76+
.escape {
77+
app.gg.quit()
78+
}
5479
else {}
5580
}
56-
print('rotation: ')
57-
println(app.rotation)
5881
}
5982
else {}
6083
}

0 commit comments

Comments
 (0)