Drawing a Circle with PSET
Just a few lines of code are needed..

If you want to code your own circle routine in QB there is only a little need of mathmatical knowledge about Sin and Cos.

With Sin and Cos you can get the coordinates of a point on the circle line.
Both functions have one parameter, an angle in radians. So a full circle doesn't have 360°, but 2Pi. When we want to draw every single pixel of one degree we have to do this in a for-loop like the following one:

```
Const Pi# = 3.141592654#
For n! = 0 to 2 * Pi# Step ( 1 / 180 ) * Pi#
'Here comes the drawing code
Next n!
```

To calculate the coordinates of every single pixel of the circle you have to use these formulas:

```
x% = Sin( n ) * radius%
y% = Cos( n ) * radius%
```

So we can draw a primitive circle:

```
Screen 13
Const Pi# = 3.141592654#
color% = 15
xCenter% = 160
yCenter% = 100
For n! = 0 to 2 * Pi# Step ( 1 / 180 ) * Pi#
x% = Sin( n! ) * radius%
y% = Cos( n! ) * radius%
Pset ( x% + xCenter% , y% + yCenter% ), color%
Next n!
```

When you run this code, you will see that the circle is a little bit deformed, but there's a solution:

```
x% = Sin( n! ) * radius% * ( 5 / 6 )
y% = Cos( n! ) * radius% * ( 5 / 6 )
```

With this you can code ellipses, too. You just have to change the '( 5 / 6 )' to another factor and you'll get another circle.

akOOma

DrawingCirclesPsetGeneral - page last edited 2004-02-10 12:32:06 by 172.167.146.22 (home) (edit)
Blast WIKI - by RoboticBoy - edited and tweaked for our evil purposes by Hexadecimal Disaster