PDA

View Full Version : canvas tourism



zak
29-06-2010, 15:57
this is the season of the canvas
yes the canvas_width introduced recently is usefull,
also here is drawing a circle defined by x,y and radius, instead of the coordinates of the rectangle which surrounds it.
the ellipse is more complex since we may need to rotate it.
also drawing the arc in blue over part of an ellipse going from 0 radian to Pi/2 ie clockwise; the arc is part of the ellipse which is defined by the surrounded rectangle.
by the way Pi constant seems not working ??
sorry: corrected: it needs uses "math"
a good color picker may be usefull here:http://www.silvermaine.co.uk/downloads.html
regards


Uses "UI"


Uses "math"
' Global variables
'-----------------------------------------------------------
Dim ScreenWidth As Long = 640
Dim ScreenHeight As Long = 480
Dim hWin As DWord '---Handle of the canvas window
'Dim Pi As Double =3.141592
Dim colr, colrFill As Long
'-----------------------------------------------------------
' Main program
'-----------------------------------------------------------
hWin = Canvas_Window("Figures", 1, 1, ScreenWidth, ScreenHeight )


Canvas_Attach(hWin, 0, %TRUE) ' <- double buffer




'---Init canvas
Canvas_Clear(%BLACK)
Canvas_Width(10)
Canvas_Box(20, 50, 320, 300, 70, Rgb(255,255, 0),Rgb(205,242, 254))
Canvas_Ellipse(200, 90, 300, 140, Rgb(255, 0, 0),Rgb(0, 252, 0))
Canvas_Arc(200, 90, 300, 140, 0, Pi/2 ,Rgb(0, 0, 255) )
Canvas_Width(30)
Canvas_Ellipse(40, 70, 140, 170, Rgb(255, 0, 0),Rgb(104,96,204))
colr = Rgb(255, 81, 16) : colrFill = Rgb(0, 255, 0)
'circle(x,y,radius,colr,colrFill)
Circle(175,300,70,colr,colrFill)


Canvas_Redraw


Canvas_WaitKey
Canvas_Window End


Function Circle(x As Long, y As Long, r As Long, colr, colrFill)
Canvas_Ellipse(x-r, y-r, x+r, y+r, colr, colrFill)
End Function




PS: now in thinbasic v 1.8.8 there is a new function Canvas_Circle so you can use it instead of the function Circle in the above code