2019-07-19 14:15:47 +03:00
|
|
|
module main
|
|
|
|
|
|
|
|
import gx
|
|
|
|
import gg
|
2019-07-19 14:27:44 +03:00
|
|
|
import time
|
|
|
|
import glfw
|
2019-07-20 18:38:00 +03:00
|
|
|
import math
|
2019-07-19 14:15:47 +03:00
|
|
|
|
|
|
|
const (
|
2019-07-20 18:38:00 +03:00
|
|
|
Size = 1000
|
|
|
|
Scale = 50.0
|
2019-07-19 14:15:47 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
struct Context {
|
|
|
|
gg *gg.GG
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
glfw.init()
|
2019-07-19 14:27:44 +03:00
|
|
|
ctx:= &Context{
|
|
|
|
gg: gg.new_context(gg.Cfg {
|
2019-07-20 18:38:00 +03:00
|
|
|
width: Size
|
|
|
|
height: Size
|
2019-07-19 14:27:44 +03:00
|
|
|
use_ortho: true
|
|
|
|
create_window: true
|
2019-07-20 18:38:00 +03:00
|
|
|
window_title: 'Graph builder'
|
2019-07-19 14:27:44 +03:00
|
|
|
window_user_ptr: ctx
|
2019-07-20 18:38:00 +03:00
|
|
|
always_on_top: true
|
2019-07-19 14:27:44 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
for {
|
|
|
|
gg.clear(gx.White)
|
2019-07-19 14:15:47 +03:00
|
|
|
ctx.draw()
|
2019-07-19 14:27:44 +03:00
|
|
|
ctx.gg.render()
|
2019-07-19 14:15:47 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-19 14:27:44 +03:00
|
|
|
[live]
|
2019-07-20 18:38:00 +03:00
|
|
|
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 {
|
|
|
|
y := (x - 1) * (x - 1) + 1
|
|
|
|
ctx.gg.draw_rect(center + x * Scale,
|
|
|
|
center - y * Scale, 1, 1, gx.Black)
|
2019-07-19 14:15:47 +03:00
|
|
|
}
|
|
|
|
}
|