[quote=225041:@Chris Salonikas]I am used to DOS BASIC and could not find any examples on how to convert the following example to the Xojo canvas.
Does anyone have any example on how to plot as such which includes the y and x axis?
[/quote]
Ah GWBasic and Basica. Old memories…
Antonio has given you a modern way of doing what you want.
Let me show you how simple it is to go from an age old listing to Xojo :
//10 SCREEN 2,0,0 //full screen hi-res graphics mode
// Create a new picture that will be used as canvas backdrop
dim pic as new picture(Canvas1.width, Canvas1.Height, 32)
// We will use the Graphics property of that picture to draw in
dim g as graphics = pic.graphics
//15 R = 50:s = 50:N = 9
dim R as integer = 50
dim s as integer = 50
dim N as integer = 9
//20 FOR A = 0 TO 2*3.14159 STEP .1
dim X, Y as double
For A as double = 0 TO 2*3.14159 STEP .1
//30 X = R*COS(A) + S*COS(N*A) + 320 //centre pattern
X = R*COS(A) + S*COS(N*A) + 320 //centre pattern
//40 Y = R/2*SIN(A) + S/2*SIN(N*A) + 100 //centre pattern
Y = R/2*SIN(A) + S/2*SIN(N*A) + 100 //centre pattern
//50 PSET(X,Y)
g.Pixel(X, Y) = &c00000000
//60 NEXT A
next A
// Sends the picture to the canvas
Canvas1.Backdrop = pic
In Xojo, a double bar //
or an apostrophe '
replaces the GWBasic or PC Basic REM. Note I placed your code above the Xojo one for easy reference.
Here is what I did, line by line. I also added relevant links to the language reference (LR).
In Xojo, there are no line numbers.
As you can see, line 10 has been replaced by the creation of a picture and its graphics property that will be used to mimic the PC graphics mode.
http://documentation.xojo.com/index.php/picture
http://documentation.xojo.com/index.php/graphics
Line 15 has been replaced by 3 lines of declarations. Note that in Xojo you need to dim a variable and indicate its type before you use it. Note the same kind of declaration below line 20 for X and Y.
http://documentation.xojo.com/index.php/Category:Language_Data_Types-Common
Line 20 is almost identical, but again, A needs to be defined, which is achieved by the code A as double
.
30 and 40 are identical to your code. Cos and Sin are as far as I remember just the same.
http://documentation.xojo.com/index.php/Cos
http://documentation.xojo.com/index.php/sin
Line 50 has been replaced by another command, which sets the color of an individual pixel.
http://documentation.xojo.com/index.php/Graphics.Pixel
http://documentation.xojo.com/index.php/Color
60 code is identical.
Finally, the last line of the Xojo code puts the newly created picture into the canvas.
That is a long development for a short piece of code, but you may enjoy understanding better the changes and similarities involved.
Since the 640 x 200 hi res mode of the IBM-PC, screen resolution has increased dramatically. You can change the values in your program to accommodate the larger screen, and instead of plotting only one pixel, draw four at a time. I tried multiplying R, S and N by 3, that is more like the current screen size.