PDA

View Full Version : plotting speed



zak
31-05-2010, 14:20
Hi
a phenomena !!
in the following code the speed of plot increased noticeably when we press the left mouse button on the title bar of the window
the purpose of "Canvas_Redraw" after "Canvas_SetPixel(x, y)" rather than after the whole loop is to give the impression of animation. why the speed is increased this way !.

Uses "UI"

Dim hWin As DWord = Canvas_Window("draw speed", 1, 1, 640, 480 )
Canvas_Attach(hWin, 0, %TRUE) ' <- double buffer
Canvas_Clear(%BLACK)

Dim x, y,i As Long
x=0:y=0

For i = 1 To 500
x = x + 1: y =y + 1
Canvas_Color( Rgb(255, 255, 255))
Canvas_SetPixel(x, y)
Canvas_Redraw

next

MsgBox hWin, "ok", %MB_APPLMODAL


Canvas_Window end

Petr Schreiber
31-05-2010, 14:32
I can only confirm it behaves the same on my machine.

When no clicking on title bar, the CPU usage is 0%, when clicking it goes up to 16%.
It seems to me this action somehow triggers more intensive message processing.

Eros will know more.


Petr

ErosOlmi
31-05-2010, 15:11
With this example it is more evident:


Uses "UI"

Dim hWin As DWord = Canvas_Window("draw speed", 1, 1, 640, 480 )
Canvas_Attach(hWin, 0, %TRUE) ' <- double buffer
Canvas_Clear(%BLACK)

Dim x, y, i, ntime As Long

x=0
y=0
ntime = 1

For i = 1 To 50000
x = x + 1
y = y + 1
Canvas_SetPixel(x, y, Rgb(255, 255, 255))
Canvas_Redraw
If y = 480 Then
ntime += 3
y = 0
x = ntime
End If
Next

MsgBox hWin, "ok", %MB_APPLMODAL


Canvas_Window End





Do not know the reason.

TomLebowski
01-06-2010, 12:59
hi, a) last example from eros causes a gpf at my machine after closing the app. b) don`t know there is a canvas_window, new for me. why it`s better for using than dialog new or dialog pixel ?

have a lot of private stress (son with problems at school) and heavy task at university, so not enough time for thinbasic at the moment, I am sad about that, sorry.

bye, tom

ErosOlmi
01-06-2010, 15:31
a) last example from eros causes a gpf at my machine after closing the app.

If you force closing with [X] button you are forcing the process to shut down.
GPF is quite normal in that case because script is inside a loop