Starting to investigate more seriously the use of canvas() functions (@Keith Baxter and @Sling are having a stroke right now ), I have a newbie question:
I want to create a curve graph that updates constantly. For this, i want to use canvas draw, where I have to create a new segment of the curve every iteration, while retaining the previous display until the screen is filled, then scroll the graph.
What I understood is that canvas is drawn at once, and cannot really be updated, ie the previous content kept, while adding new content. So i figured that i would have to create a canvas every iteration, and draw my new pixels on top of each other.
Here's the test code I wrote for this, which is not working, I get a "cannot initiate canvas outside of initial logic.lua execution" error.
Code: Select all
function line(x1,y1,x2,y2)
_move_to(x1,y1)
_line_to(x2,y2)
end
x_oldvalue=10
y_oldvalue=390
x_newvalue=x_old_value
y_newvalue=0
function draw()
x_newvalue=x_oldvalue+5
y_newvalue=math.random(0,380)
print(x_newvalue.."/"..y_newvalue)
canvas_add(0,0,400,400,function()
line(10,0,10,390)
line(10,390,400,390)
_fstroke("red",1)
line(x_oldvalue,y_oldvalue,x_newvalue,y_newvalue)
_stroke("black",1)
end)
x_oldvalue=x_newvalue
y_oldvalue=y_newvalue
end
timer_start(0,1000,draw)
Do I need to first create a table of values in memory (like a screen buffer), then draw the content of the table all at once every 500msec?
Thanks
Jacques