mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
examples/graph: update the graph instantly; add a couple of graphs
This commit is contained in:
parent
5375038d88
commit
a2a0b149b2
@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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) {
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user