mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
gg: use gg types for Events instead of sapp
This commit is contained in:
@ -2,7 +2,6 @@ module main
|
||||
|
||||
import gx
|
||||
import gg
|
||||
import sokol.sapp
|
||||
import time
|
||||
import math
|
||||
|
||||
@ -20,7 +19,7 @@ fn main() {
|
||||
mut context := &Context{
|
||||
gg: 0
|
||||
}
|
||||
context.gg = gg.new_context({
|
||||
context.gg = gg.new_context(
|
||||
width: size
|
||||
height: size
|
||||
font_size: 20
|
||||
@ -32,7 +31,7 @@ fn main() {
|
||||
resizable: true
|
||||
bg_color: gx.white
|
||||
font_path: gg.system_font_path()
|
||||
})
|
||||
)
|
||||
context.gg.run()
|
||||
}
|
||||
|
||||
@ -44,34 +43,45 @@ fn frame(mut ctx Context) {
|
||||
|
||||
[live]
|
||||
fn (ctx &Context) draw() {
|
||||
mut w := sapp.width()
|
||||
mut h := sapp.height()
|
||||
if sapp.high_dpi() {
|
||||
s := gg.window_size()
|
||||
mut w := s.width
|
||||
mut h := s.height
|
||||
if gg.high_dpi() {
|
||||
w /= 2
|
||||
h /= 2
|
||||
}
|
||||
ctx.gg.draw_line(0, h/2, w, h/2, gx.gray) // x axis
|
||||
ctx.gg.draw_line(w/2, 0, w/2, h, gx.gray) // y axis
|
||||
ctx.gg.draw_line(0, h / 2, w, h / 2, gx.gray) // x axis
|
||||
ctx.gg.draw_line(w / 2, 0, w / 2, h, gx.gray) // y axis
|
||||
atime := f64(time.ticks() / 10)
|
||||
stime := math.sin(2.0 * math.pi * f64(time.ticks() % 6000) / 6000)
|
||||
mut y := 0.0
|
||||
blue := gx.Color {r:100, g:100, b:200}
|
||||
red := gx.Color {r:200, g:100, b:100}
|
||||
blue := gx.Color{
|
||||
r: 100
|
||||
g: 100
|
||||
b: 200
|
||||
}
|
||||
red := gx.Color{
|
||||
r: 200
|
||||
g: 100
|
||||
b: 100
|
||||
}
|
||||
y = 1.0
|
||||
max := f32(w)/(2*scale)
|
||||
max := f32(w) / (2 * scale)
|
||||
min := -max
|
||||
for x := min; x <= max; x += 0.01 {
|
||||
// y = x*x + 2
|
||||
// y = x * x + stime * stime
|
||||
// y = stime
|
||||
// y = stime * h
|
||||
y = stime * 1.0 * math.sin((x) + stime + atime / 32) * ((h/256) + x)
|
||||
y = stime * 1.0 * math.sin((x) + stime + atime / 32) * ((h / 256) + x)
|
||||
// y = (stime * x) * x + stime
|
||||
// y = (x + 3) * (x + 3) / stime + stime*2.5
|
||||
// y = math.sqrt(30.0 - x * x) * stime
|
||||
// y -= (stime-0.5) + stime
|
||||
// ctx.gg.draw_rect(f32((w/2) + x * scale), f32((h/2) - y * scale), 2, 2, blue)
|
||||
ctx.gg.draw_rect(f32((w/2) + x * scale), f32((h/2) - y * scale), 2, (f32(y) * scale), blue)
|
||||
ctx.gg.draw_rect(f32((w/2) + x * scale), f32((h/2) + y * scale), 2, (f32(y) * scale) + 32, red)
|
||||
ctx.gg.draw_rect(f32((w / 2) + x * scale), f32((h / 2) - y * scale), 2, (f32(y) * scale),
|
||||
blue)
|
||||
ctx.gg.draw_rect(f32((w / 2) + x * scale), f32((h / 2) + y * scale), 2, (f32(y) * scale) +
|
||||
32, red)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user