1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/vlib/gg/testdata/draw_simple_polygons.vv
2022-06-28 08:30:45 +03:00

62 lines
856 B
V

import gg
import gx
struct App {
mut:
gg &gg.Context = 0
rotation f32 = f32(0)
}
[console]
fn main() {
mut app := &App{}
app.gg = gg.new_context(
window_title: 'Simple Polygons'
width: 500
height: 500
bg_color: gx.black
event_fn: event
frame_fn: render
user_data: app
)
app.gg.run()
}
fn render(app &App) {
app.gg.begin()
color := gx.Color{
r: 175
g: 0
b: 0
a: 200
}
mut shape := 3
for i := 1; i < 5; i++ {
for j := 1; j < 5; j++ {
app.gg.draw_polygon_filled(100 * j, 100 * i, 30, shape, app.rotation, color)
shape++
}
}
app.gg.end()
}
fn event(e &gg.Event, mut app App) {
match e.typ {
.key_down {
match e.key_code {
.right { app.rotation++ }
.left { app.rotation-- }
.escape { app.gg.quit() }
else {}
}
print('rotation: ')
println(app.rotation)
}
else {}
}
}