2019-07-19 13:15:47 +02:00
|
|
|
module main
|
|
|
|
|
|
|
|
import gx
|
|
|
|
import gg
|
2019-09-23 12:42:20 +02:00
|
|
|
import time
|
|
|
|
import glfw
|
2019-10-13 06:11:40 +02:00
|
|
|
// import math
|
2019-09-28 19:42:29 +02:00
|
|
|
import os
|
2019-09-23 12:42:20 +02:00
|
|
|
|
2019-07-19 13:15:47 +02:00
|
|
|
const (
|
2019-07-23 00:19:20 +02:00
|
|
|
Size = 700
|
2019-07-20 17:38:00 +02:00
|
|
|
Scale = 50.0
|
2019-07-19 13:15:47 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
struct Context {
|
2019-09-04 14:10:18 +02:00
|
|
|
gg &gg.GG
|
2019-07-19 13:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2019-09-28 19:42:29 +02:00
|
|
|
os.clear()
|
2019-10-12 05:03:15 +02:00
|
|
|
glfw.init_glfw()
|
2019-07-19 13:27:44 +02:00
|
|
|
ctx:= &Context{
|
|
|
|
gg: gg.new_context(gg.Cfg {
|
2019-07-20 17:38:00 +02:00
|
|
|
width: Size
|
|
|
|
height: Size
|
2019-07-19 13:27:44 +02:00
|
|
|
use_ortho: true
|
|
|
|
create_window: true
|
2019-07-20 17:38:00 +02:00
|
|
|
window_title: 'Graph builder'
|
2019-07-19 13:27:44 +02:00
|
|
|
window_user_ptr: ctx
|
2019-07-20 17:38:00 +02:00
|
|
|
always_on_top: true
|
2019-07-19 13:27:44 +02:00
|
|
|
})
|
|
|
|
}
|
2019-07-23 00:19:20 +02:00
|
|
|
go update() // update the scene in the background in case the window isn't focused
|
2019-07-19 13:27:44 +02:00
|
|
|
for {
|
|
|
|
gg.clear(gx.White)
|
2019-07-19 13:15:47 +02:00
|
|
|
ctx.draw()
|
2019-07-19 13:27:44 +02:00
|
|
|
ctx.gg.render()
|
2019-07-19 13:15:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-19 13:27:44 +02:00
|
|
|
[live]
|
2019-07-20 17:38:00 +02: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
|
2019-09-28 19:42:29 +02:00
|
|
|
center := f64(Size / 2)
|
|
|
|
mut y := 0.0
|
2019-07-20 17:38:00 +02:00
|
|
|
for x := -10.0; x <= 10.0; x += 0.002 {
|
2019-09-28 19:42:29 +02:00
|
|
|
y = x * x - 1
|
|
|
|
//y = (x + 3) * (x + 3) - 1
|
|
|
|
//y = math.sqrt(30.0 - x * x)
|
2019-07-23 00:19:20 +02:00
|
|
|
ctx.gg.draw_rect(center + x * Scale, center - y * Scale, 1, 1, gx.Black)
|
|
|
|
//ctx.gg.draw_rect(center + x * Scale, center + y * Scale, 1, 1, gx.Black)
|
2019-07-19 13:15:47 +02:00
|
|
|
}
|
|
|
|
}
|
2019-07-23 00:19:20 +02:00
|
|
|
|
|
|
|
fn update() {
|
|
|
|
for {
|
|
|
|
gg.post_empty_event()
|
|
|
|
time.sleep_ms(300)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|