Curved Line and Oval Help

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
Me
Newbie
Posts: 1
Joined: Fri Jul 30, 2004 7:59 pm

Curved Line and Oval Help

Post by Me »

I am having troubles with Qbasic making a Curved line and a oval, Could someone please tell me the command to make a curved line and oval?
Thanks
User avatar
Pete
Site Admin
Posts: 887
Joined: Sun Dec 07, 2003 9:10 pm
Location: Candor, NY
Contact:

Post by Pete »

Ovals and Arcs (which are curved lines of sorts) are really easy with the CIRCLE command. Here's a tutorial I found that explains this pretty well:
* 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:

Code: Select all

SCREEN 12  'creates a white (default color) circle
CIRCLE (300, 200), 150
END
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: Select all

SCREEN 12 'like the other graphics commands, the color
COLOR 4   'will be that of the last COLOR command.
CIRCLE (80, 240), 50
END
or:

Code: Select all

SCREEN 12
CIRCLE (100, 100), 20, 7  '7 (gray) is the color 
END
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.

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):

Code: Select all

CLS
INPUT "What is the angle in degrees?: ", degrees
radians = degrees * (3.141593 / 180)
PRINT degrees; "degrees ="; radians; "radians"
END 
Here is a program that makes a half circle:

Code: Select all

SCREEN 13
CIRCLE (160, 100), 50, 14, 0, 3.1416
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: Select all

SCREEN 13
CIRCLE (160, 100), 50, 14, , 3.1416
END
Alright, so do you got that concept down? Do realize that 0 radians is to the right, not up.

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:

Code: Select all

SCREEN 12
CIRCLE (240, 240), 200, 13, -1.5708, -3.1416
END
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.

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:

Code: Select all

SCREEN 12
RANDOMIZE TIMER             'creates a circle in
colour = INT(RND * 15) + 1  'random color and
endpoint = RND * 6.2832     'a random ending point
CIRCLE (200, 200), 150, colour, -.0001, -endpoint
END
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.

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):

Code: Select all

SCREEN 12  'the row of commas is where the start 
           'and end properties would be
CIRCLE (320, 240), 100, 15, , , .5
END
You can also have the height greater than the width, by having a number greater than 1:

Code: Select all

SCREEN 12
CIRCLE (320, 240), 100, 15, , , 2
END
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.
This tutorial was originally here: http://www.geocities.com/alipha87/pkchap08.html


Play around with this command. The best way to learn this is by experimentation.
Guest

Post by Guest »

Thansks, You rock.
Post Reply