zak
12-08-2010, 09:15
Hi
drawing using canvas is a pleasure, since it is simple, and the refreshing screen done without the user to concern about it, believe me some languages do the refrersh by continious executing of the drawing code, and if you want to do the refresh yourself using api, god help you.
i have posted before about ploting sine curve slowly, and it is done using tbgl , and tbgl+ui, but using canvas alone is simpler: it is like plotting using quick basic but more advanced. you can simply convert all vb6 and quickbasic plotting codes to thinbasic.
the following code will plot the sine curve
Canvas_SetPixel(x*30+300, y*80+300) for plotting pixels,
Canvas_Line( (x1, y1), (x1, y1) , Rgb(255, 0, 0) ) for plotting with thickness defined by a previous "Canvas_Width(10)" .
i have used the canvas new feature like:
a = Canvas_WaitKey(27) to wait pressing ESC to exit, the 27 is the asc of ESC you can use 32 to exit by pressing space bar
to plot without animation just delete the first "Canvas_Redraw" and keep the second one
Uses "UI"
Uses "math"
' Global variables
'-----------------------------------------------------------
Dim ScreenWidth As Long = 800
Dim ScreenHeight As Long = 600
Dim hWin As DWord '---Handle of the canvas window
Dim a As Long
Dim x,y,x1,y1 As Double
'-----------------------------------------------------------
' Main program
'-----------------------------------------------------------
hWin = Canvas_Window("test Canvas sine curve: press ESC to exit", 1, 1, ScreenWidth, ScreenHeight )
Canvas_Attach(hWin, 0, %TRUE) ' <- double buffer
'---Init canvas
Canvas_Clear(%BLACK)
Canvas_Width(10)
For x=-9 To 15 Step 0.05
y = Sin(x)
Canvas_Color(Rgb(0, 255, 0))
'plotting the thin sine curve points:
Canvas_SetPixel(x*30+300, y*80+300)
x1 = x*30+300: y1 = y*80+150
'plotting the thick sine curve points:
Canvas_Line( (x1, y1), (x1, y1) , Rgb(255, 0, 0) )
Canvas_Redraw
Next x
Canvas_Redraw
a = Canvas_WaitKey(27)
Canvas_Window End
drawing using canvas is a pleasure, since it is simple, and the refreshing screen done without the user to concern about it, believe me some languages do the refrersh by continious executing of the drawing code, and if you want to do the refresh yourself using api, god help you.
i have posted before about ploting sine curve slowly, and it is done using tbgl , and tbgl+ui, but using canvas alone is simpler: it is like plotting using quick basic but more advanced. you can simply convert all vb6 and quickbasic plotting codes to thinbasic.
the following code will plot the sine curve
Canvas_SetPixel(x*30+300, y*80+300) for plotting pixels,
Canvas_Line( (x1, y1), (x1, y1) , Rgb(255, 0, 0) ) for plotting with thickness defined by a previous "Canvas_Width(10)" .
i have used the canvas new feature like:
a = Canvas_WaitKey(27) to wait pressing ESC to exit, the 27 is the asc of ESC you can use 32 to exit by pressing space bar
to plot without animation just delete the first "Canvas_Redraw" and keep the second one
Uses "UI"
Uses "math"
' Global variables
'-----------------------------------------------------------
Dim ScreenWidth As Long = 800
Dim ScreenHeight As Long = 600
Dim hWin As DWord '---Handle of the canvas window
Dim a As Long
Dim x,y,x1,y1 As Double
'-----------------------------------------------------------
' Main program
'-----------------------------------------------------------
hWin = Canvas_Window("test Canvas sine curve: press ESC to exit", 1, 1, ScreenWidth, ScreenHeight )
Canvas_Attach(hWin, 0, %TRUE) ' <- double buffer
'---Init canvas
Canvas_Clear(%BLACK)
Canvas_Width(10)
For x=-9 To 15 Step 0.05
y = Sin(x)
Canvas_Color(Rgb(0, 255, 0))
'plotting the thin sine curve points:
Canvas_SetPixel(x*30+300, y*80+300)
x1 = x*30+300: y1 = y*80+150
'plotting the thick sine curve points:
Canvas_Line( (x1, y1), (x1, y1) , Rgb(255, 0, 0) )
Canvas_Redraw
Next x
Canvas_Redraw
a = Canvas_WaitKey(27)
Canvas_Window End