v/examples/gg/set_pixels.v

53 lines
944 B
V
Raw Normal View History

2021-08-20 00:14:25 +02:00
module main
import gg
import gx
struct App {
mut:
gg &gg.Context
pixels []f32
2021-08-20 00:14:25 +02:00
}
fn main() {
mut pixels := []f32{}
density := 4
for x in 30 .. 60 {
if x % density == 0 {
continue
}
for y in 30 .. 60 {
if y % density == 0 {
continue
}
pixels << f32(x + density)
pixels << f32(y + density)
}
}
2021-08-20 00:14:25 +02:00
mut app := &App{
gg: 0
pixels: pixels
2021-08-20 00:14:25 +02:00
}
app.gg = gg.new_context(
bg_color: gx.rgb(174, 198, 255)
width: 100
height: 100
window_title: 'Set Pixels'
frame_fn: frame
user_data: app
)
app.gg.run()
}
fn frame(mut app App) {
app.gg.begin()
// Set a blue pixel near each corner. (Find your magnifying glass)
app.gg.set_pixel(2, 2, gx.blue)
app.gg.set_pixel(app.gg.width - 2, 2, gx.blue)
app.gg.set_pixel(app.gg.width - 2, app.gg.height - 2, gx.blue)
app.gg.set_pixel(2, app.gg.height - 2, gx.blue)
// Set pixels in a grid-like pattern.
app.gg.set_pixels(app.pixels, gx.red)
2021-08-20 00:14:25 +02:00
app.gg.end()
}