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