examples/graph: update the graph instantly; add a couple of graphs

pull/1275/head
Alexander Medvednikov 2019-07-23 00:19:20 +02:00
parent 5375038d88
commit a2a0b149b2
2 changed files with 19 additions and 4 deletions

View File

@ -8,7 +8,7 @@ import glfw
import math
const (
Size = 1000
Size = 700
Scale = 50.0
)
@ -29,6 +29,7 @@ fn main() {
always_on_top: true
})
}
go update() // update the scene in the background in case the window isn't focused
for {
gg.clear(gx.White)
ctx.draw()
@ -42,8 +43,18 @@ fn (ctx &Context) draw() {
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) - 2
ctx.gg.draw_rect(center + x * Scale,
center - y * Scale, 1, 1, gx.Black)
y := x * x + 1
//y := (x + 3) * (x + 3) - 1
//y := math.sqrt(30.0 - x * x)
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)
}
}
fn update() {
for {
gg.post_empty_event()
time.sleep_ms(300)
}
}

View File

@ -329,6 +329,10 @@ fn update() {
// # ui__post_empty_event();
}
pub fn post_empty_event() {
glfw.post_empty_event()
}
pub fn (c GG) circle(x, y, r int) {
}