examples/hot_code_reloading: graph builder

pull/1245/head
Alexander Medvednikov 2019-07-19 13:15:47 +02:00
parent 760034b6b1
commit 26ed3fb372
1 changed files with 60 additions and 0 deletions

View File

@ -0,0 +1,60 @@
module main
import gx
import gl
import gg
import glfw
const (
WIDTH = 1000
HEIGHT = 1000
SCALE = 50
)
struct Context {
mut:
gg *gg.GG
}
fn main() {
glfw.init()
mut ctx := &Context{gg: 0}
window := glfw.create_window(glfw.WinCfg{
title: 'graph builder'
width: 1000
height: 1000
ptr: ctx
})
window.make_context_current()
gg.init()
ctx.gg = gg.new_context(gg.Cfg {
width: 1000
height: 1000
use_ortho: true
})
for {
gl.clear()
gl.clear_color(255, 255, 255, 255)
ctx.draw()
window.swap_buffers()
glfw.wait_events()
}
}
fn (ctx mut Context) draw() {
// x axis
ctx.gg.draw_line(0, HEIGHT / 2, WIDTH, HEIGHT / 2)
// y axis
ctx.gg.draw_line(WIDTH / 2, 0, WIDTH / 2, HEIGHT)
mut prev_x := f64(0)
mut prev_y := f64(0)
center := f64(WIDTH / 2)
for x := f64(- 10); x <= f64(10); x += 0.01 {
y := x * x * f64(SCALE)
// gx.draw_line_c(center + prev_x, center+prev_y, center + int(x*float(10)), center+y, gx.BLACK)
ctx.gg.draw_rect(int(center) + int(x * f64(SCALE)), int(center - y), 1, 1, gx.Black)
// gx.draw_rect_f(center + (x * f64(SCALE)), center - y, 1, 1, gx.BLACK)
prev_x = x
prev_y = y
}
}