Drawing point by point

In a for-next loop there are the coordinates of points calculated. My Apple (IOS) stores the coordinates and after the loop the points are displayed. I would like the points were displayed directly after they were calculated. How can I achieve this?

That would not be good as each calculation is MUCH faster than the refresh rate of the screen, so in order to show a point NOW you would need to initiate a refresh after each calculation -> horrible flicker.

Better call canvas1.Invalidate which will update the canvas at the next scheduled refresh (about every 16 ms) which should be plenty enough.

Markus thanks!! I know it is much faster, but for demonstration I am just interested in slower drawing of the points. Using Invalidate shows just one point, while I want a drawing point by point.

If you WANT them to appear slowly…

Create a window-level picture of the same size as your canvas.

In the canvas’ PAINT event, use

g.drawpicture  thepicture,0,0

In the for… next loop, use

picture.graphics.pixel (x,y)  // to plot each point in turn

After each point , you should call
canvas1.invalidate
or
canvas1.refresh

refresh may flicker but will cause an update for every point
invalidate wont flicker, but it may not show each point in turn

You might want a delay in the x,y loop if you want a really slow display

Or use a timer and every iteration draw one point to the BufferPicture to reaaaly slow it down.

add to the app a public property

Public Property Randomizer as Random

and in the app.open event

Sub Open() Handles Open Randomizer = New Random End Sub

PushButton:

[code]Sub Action() Handles Action

BufferPic = New Picture( Canvas1.Width, Canvas1.Height, 32 )

Iteration = 0

Timer1.Mode = Timer.ModeMultiple
Timer1.Reset

End Sub[/code]

Canvas1:

Sub Paint(g As Graphics, areas() As REALbasic.Rect) Handles Paint g.DrawPicture( BufferPic, 0, 0, g.Width, g.Height ) End Sub

Timer 1: Mode: OFF Period: 20

[code]Sub Action() Handles Action

if Iteration < BufferPic.Width Then

dim g as Graphics = BufferPic.Graphics

Dim i As Integer = App.Randomizer.InRange(-3, 3)

g.ForeColor = &c0000FF

BufferPic.Graphics.FillOval( Iteration, 100 + i, 2, 2 )

Iteration = Iteration + 1

Canvas1.Invalidate

'if iteration = 20 then break

else

me.Mode = Timer.ModeOff

end if
End Sub[/code]

Two window properties:

Public Property BufferPic as Picture

Public Property Iteration as Integer = 0

Ideally your Timer should be a subclass of Timer with an attached array that has all the points you want to draw