1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/examples/hot_code_reloading/graph.v

50 lines
799 B
Go
Raw Normal View History

module main
import gx
2019-07-22 13:51:22 +03:00
import gl
import gg
import time
import glfw
import math
const (
Size = 1000
Scale = 50.0
)
struct Context {
gg *gg.GG
}
fn main() {
glfw.init()
ctx:= &Context{
gg: gg.new_context(gg.Cfg {
width: Size
height: Size
use_ortho: true
create_window: true
window_title: 'Graph builder'
window_user_ptr: ctx
always_on_top: true
})
}
for {
gg.clear(gx.White)
ctx.draw()
ctx.gg.render()
}
}
[live]
fn (ctx &Context) draw() {
ctx.gg.draw_line(0, Size / 2, Size, Size / 2) // x axis
ctx.gg.draw_line(Size / 2, 0, Size / 2, Size) // y axis
center := f64(Size / 2)
for x := -10.0; x <= 10.0; x += 0.002 {
2019-07-22 13:51:22 +03:00
y := (x - 1) * (x - 1) - 2
ctx.gg.draw_rect(center + x * Scale,
center - y * Scale, 1, 1, gx.Black)
}
}