v2 / examples / gg / draw_pixels.v
52 lines · 46 sloc · 976 bytes · bbb61ab3687afe512a1fa12492c876d011626107
Raw
1module main
2
3import gg
4
5struct App {
6mut:
7 gg &gg.Context = unsafe { nil }
8 pixels []f32
9}
10
11fn main() {
12 mut pixels := []f32{}
13 density := 4
14 for x in 30 .. 60 {
15 if x % density == 0 {
16 continue
17 }
18 for y in 30 .. 60 {
19 if y % density == 0 {
20 continue
21 }
22 pixels << f32(x + density)
23 pixels << f32(y + density)
24 }
25 }
26 mut app := &App{
27 pixels: pixels
28 }
29 app.gg = gg.new_context(
30 bg_color: gg.rgb(174, 198, 255)
31 width: 100
32 height: 100
33 window_title: 'Set Pixels'
34 frame_fn: frame
35 user_data: app
36 )
37 app.gg.run()
38}
39
40fn frame(mut app App) {
41 app.gg.begin()
42
43 // Draw a blue pixel near each corner. (Find your magnifying glass)
44 app.gg.draw_pixel(2, 2, gg.blue)
45 app.gg.draw_pixel(app.gg.width - 2, 2, gg.blue)
46 app.gg.draw_pixel(app.gg.width - 2, app.gg.height - 2, gg.blue)
47 app.gg.draw_pixel(2, app.gg.height - 2, gg.blue)
48
49 // Draw pixels in a grid-like pattern.
50 app.gg.draw_pixels(app.pixels, gg.red)
51 app.gg.end()
52}
53