This tutorial was originally here: http://www.geocities.com/alipha87/pkchap08.html* 8.6 Creating Circles, Arcs, and Ovals
Another useful graphics command is CIRCLE. With CIRCLE, you need to not only specify its coordinates, but also its radius:The above will make a circle with a radius of 150 (remember, radius is the length from the center of the circle to its edge) at location (300, 200). The color of the circle is 15 (white) because that's the default color. To change the color, you can either:Code:
SCREEN 12 'creates a white (default color) circleCIRCLE (300, 200), 150END
or:Code:
SCREEN 12 'like the other graphics commands, the colorCOLOR 4 'will be that of the last COLOR command.CIRCLE (80, 240), 50END
With the CIRCLE command, you can create arcs or parts of a circle, using the start and end items. Start is where the circle will start, end is where the circle will end, both in radians.Code:
SCREEN 12CIRCLE (100, 100), 20, 7 '7 (gray) is the color END
Radians is a measurement of angles used in QBasic. There are 2 pi radians in a circle, where pi = 3.141593. So to convert degrees into radians, you multiply the degrees by (Pi / 180):Here is a program that makes a half circle:Code:
CLSINPUT "What is the angle in degrees?: ", degreesradians = degrees * (3.141593 / 180)PRINT degrees; "degrees ="; radians; "radians"END
Since 2 Pi makes a full circle, what makes a half circle was easy to figure out (Pi). Notice that 0 is the default starting point, so I don't really need it there. I could have done:Code:
SCREEN 13CIRCLE (160, 100), 50, 14, 0, 3.1416END
Alright, so do you got that concept down? Do realize that 0 radians is to the right, not up.Code:
SCREEN 13CIRCLE (160, 100), 50, 14, , 3.1416END
Now there is another thing that we can do with the start and end arguments. If you make the start negative, then it will also draw a line from the starting point to the center of the circle. If the end is negative, then a line is drawn from the ending point to the center:Remember that 1.5708 radians is up and 3.1416 radians is left. As you can see from running this program, that it makes a quarter pi shape figure.Code:
SCREEN 12CIRCLE (240, 240), 200, 13, -1.5708, -3.1416END
An interesting problem arises with negative numbers in this situation. If you use a -0, then QBasic will treat it as a positive 0. What is one to do? We'll have to use a really small negative number opposed to using 0:I decided to add a little mystery to the above program, just for a change of pace Notice that I used negative endpoint to make a line from the ending point to the center. I could have done RND * -6.2832, but I think it makes it slightly more readable the way I did it, but it doesn't really matter.Code:
SCREEN 12RANDOMIZE TIMER 'creates a circle incolour = INT(RND * 15) + 1 'random color andendpoint = RND * 6.2832 'a random ending pointCIRCLE (200, 200), 150, colour, -.0001, -endpointEND
The last topic, of many, on CIRCLE is creating ovals. To create a oval, you must specific how many times higher the oval is than its width (this is called the aspect). So in this next example, the width is 100 and the height is 50 (.5 * 100):You can also have the height greater than the width, by having a number greater than 1:Code:
SCREEN 12 'the row of commas is where the start 'and end properties would beCIRCLE (320, 240), 100, 15, , , .5END
However, notice that the height is 100 and the width is 50, not the height is 200 and the width is 100, like you'd think. I'm not quite sure why they did this, but when the aspect (the 2 in the above example) is greater than 1, the height is equal to the radius. However, if the aspect is less than 1, the width is equal to the radius. If you didn't just understand what I just said, you don't need to worry about it. You'll figure it out once you work with ovals.Code:
SCREEN 12CIRCLE (320, 240), 100, 15, , , 2END
Statistics: Posted by Pete — Fri Jul 30, 2004 10:32 pm
Statistics: Posted by Me — Fri Jul 30, 2004 8:17 pm