remove os/time references from live programs, fix warnings
parent
8082a5e7f4
commit
32b0225079
|
@ -1,6 +1,5 @@
|
|||
module main
|
||||
|
||||
import time
|
||||
import gg
|
||||
import glfw
|
||||
import gx
|
||||
|
@ -51,8 +50,6 @@ fn main() {
|
|||
///////////////////////////////////////////////
|
||||
a.update()
|
||||
print_automaton(a)
|
||||
|
||||
graphics.render()
|
||||
time.sleep_ms(1) // TODO: remove this when live reload depence on the time module is fixed
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,8 @@ fn main() {
|
|||
dy: 2
|
||||
height: height
|
||||
width: width
|
||||
main_wnd: 0
|
||||
draw_fn: 0
|
||||
}
|
||||
window := glfw.create_window(glfw.WinCfg {
|
||||
width: width
|
||||
|
@ -49,6 +51,7 @@ fn main() {
|
|||
height: height
|
||||
font_size: 20
|
||||
use_ortho: true
|
||||
window_user_ptr: 0
|
||||
})
|
||||
println('Starting the game loop...')
|
||||
go game.run()
|
||||
|
@ -63,26 +66,39 @@ fn main() {
|
|||
|
||||
const (
|
||||
width = 50
|
||||
red = gx.rgb(255,0,0)
|
||||
green = gx.rgb(0,255,0)
|
||||
blue = gx.rgb(0,0,255)
|
||||
)
|
||||
|
||||
// Try uncommenting or changing the lines inside the live functions.
|
||||
// Guess what will happen:
|
||||
[live]
|
||||
fn (game &Game) draw() {
|
||||
game.gg.draw_rect(game.x, game.y, width, width, gx.rgb(255, 0, 0))
|
||||
game.gg.draw_rect(game.x, game.y, width, width, blue)
|
||||
// game.gg.draw_rect(game.x, game.y, width, width, gx.rgb(128,10,255))
|
||||
}
|
||||
|
||||
[live]
|
||||
fn (game mut Game) update_model() {
|
||||
// game.x = 0 game.y = 0 game.dx = 1 game.dy = 1
|
||||
// game.dx = 3 game.dy = 3
|
||||
speed := 2
|
||||
game.x += speed * game.dx
|
||||
game.y += speed * game.dy
|
||||
if game.y >= game.height - width || game.y <= 0 {
|
||||
game.dy = - game.dy
|
||||
}
|
||||
if game.x >= game.width - width || game.x <= 0 {
|
||||
game.dx = - game.dx
|
||||
}
|
||||
}
|
||||
|
||||
fn (game mut Game) run() {
|
||||
for {
|
||||
game.x += game.dx
|
||||
game.y += game.dy
|
||||
if game.y >= game.height - width || game.y <= 0 {
|
||||
game.dy = - game.dy
|
||||
}
|
||||
if game.x >= game.width - width || game.x <= 0 {
|
||||
game.dx = - game.dx
|
||||
}
|
||||
// Refresh
|
||||
game.update_model()
|
||||
glfw.post_empty_event() // Refresh
|
||||
time.sleep_ms(17)
|
||||
glfw.post_empty_event()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,12 +4,12 @@ import gx
|
|||
import gg
|
||||
import time
|
||||
import glfw
|
||||
// import math
|
||||
import os
|
||||
import math
|
||||
|
||||
const (
|
||||
Size = 700
|
||||
Scale = 50.0
|
||||
pi = math.pi
|
||||
)
|
||||
|
||||
struct Context {
|
||||
|
@ -17,7 +17,6 @@ struct Context {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
os.clear()
|
||||
glfw.init_glfw()
|
||||
ctx:= &Context{
|
||||
gg: gg.new_context(gg.Cfg {
|
||||
|
@ -40,23 +39,31 @@ fn main() {
|
|||
|
||||
[live]
|
||||
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)
|
||||
ctx.gg.draw_line(0, center, Size, center) // x axis
|
||||
ctx.gg.draw_line(center, 0, center, Size) // y axis
|
||||
atime := f64( time.ticks() / 10 )
|
||||
stime := math.sin( 2.0 * pi * f64( time.ticks() % 6000 ) / 6000 )
|
||||
mut y := 0.0
|
||||
for x := -10.0; x <= 10.0; x += 0.002 {
|
||||
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)
|
||||
y = 1.0
|
||||
for x := -10.0; x <= 10.0; x += 0.02 {
|
||||
//y = x*x + 2
|
||||
y = x*x + stime*stime
|
||||
//y = stime
|
||||
//y = stime * x
|
||||
y = stime*1.0*math.sin(x + stime+atime/50) * 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(center + x * Scale, center - y * Scale, 1, 1, gx.Blue)
|
||||
ctx.gg.draw_rect(center + x * Scale, center + y * Scale, 1, 1, gx.Red)
|
||||
}
|
||||
}
|
||||
|
||||
fn update() {
|
||||
for {
|
||||
gg.post_empty_event()
|
||||
time.sleep_ms(300)
|
||||
time.sleep_ms(16) // 60 fps
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
// v -live message.v
|
||||
module main
|
||||
|
||||
import os
|
||||
import time
|
||||
|
||||
[live]
|
||||
|
@ -11,7 +10,6 @@ fn print_message() {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
os.clear()
|
||||
for {
|
||||
print_message()
|
||||
time.sleep_ms(500)
|
||||
|
|
|
@ -277,7 +277,7 @@ fn todo_remove_me(cfg Cfg, scale int) {
|
|||
}
|
||||
width := cfg.width * scale
|
||||
height := cfg.height * scale
|
||||
font_size := cfg.font_size * scale
|
||||
//font_size := cfg.font_size * scale
|
||||
gl.enable(C.GL_BLEND)
|
||||
//# glBlendFunc(C.GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
shader := gl.new_shader('text')
|
||||
|
|
|
@ -272,8 +272,8 @@ pub fn identity3() []f32 {
|
|||
|
||||
// https://github.com/toji/gl-matrix/blob/1549cf21dfa14a2bc845993485343d519cf064fe/src/gl-matrix/mat4.js
|
||||
fn ortho_js(left, right, bottom, top f32) &f32 {
|
||||
mynear := 1
|
||||
myfar := 1
|
||||
// mynear := 1
|
||||
// myfar := 1
|
||||
lr := 1.0 / (left - right)
|
||||
bt := 1.0 / (bottom - top)
|
||||
nf := 1.0 / 1.0// (mynear -myfar)
|
||||
|
|
Loading…
Reference in New Issue