Skip to main content
gamedev.net
🔒 Locked

simple C++ shapes

Started by srocky26 Oct 31, 2004 at 9:53 AM 14 replies 2.9k views
Original Post
srocky26
srocky26
Ok, I have been trying for hours to do this and finally came for some help. I need help drawing an unfilled right triangle in C++ as well as an unfilled isosceles triangle in C++. I was able to draw both of these filled, but I cant get them unfilled.
srocky26
srocky26
I'm using windows xp with visual c++. All I have to make is something like this.

right triangle -
- *
- **
- * *
- * *
- *****

isosceles triangle -
- *
- * *
- * *
- *******


RLigon
RLigon
An unfilled triangle is just 3 connected lines. OpenGL, Direct3D, and GDI all provide functionality for line drawing. Or you could look into line tracing algorithms like Brensenham's.
srocky26
srocky26
Here is the code I used for the isosceles triangle:

void filled_iso ()
{
int b; //////b=base

cout << "Please enter the size of the base for your isosceles (must be odd): ";
cin >> b;

if (b<0 || b>80 || b%2 !=1)
{
cout<<"The size of the base must be and odd number greater than zero and less than 80!\n";
cin>> b;
}


for (int j = 0; j < b/2 + 1; j++)
{
// for (int i = 0 ; i < 2 * j + 1; i++)
int temp1 = j * 2 + 1;
int temp2 = (b - temp1);
int disp = (temp2 / 2);

for (int i = 0 ; i < b; i++)
{
if ((i < disp) || (i > b - disp -1 ))

cout << " ";
else
cout << "*";
}
cout << endl;
}
}


I need a code similar to draw an unfilled isosceles triangle and a right triangle
Pipo DeClown
Pipo DeClown
Me thinks he is refering to console (prompt) graphics?
Alpha_ProgDes
Alpha_ProgDes
Quote:
Original post by srocky26
I'm using windows xp with visual c++. All I have to make is something like this.
right triangle - -     *-     **-     * *-     *  *-     *****isosceles triangle - -       *-      * *-     *   *-    *******
Beginner in Game Development?  Read here. And read here.  
Alpha_ProgDes
Alpha_ProgDes
Quote:
Original post by Pipo DeClown
Me thinks he is refering to console (prompt) graphics?
he is.
Beginner in Game Development?  Read here. And read here.  
srocky26
srocky26
yes
RLigon
RLigon
could this be a homework problem? ;)
srocky26
srocky26
yeah, it is homework, ive been working on it for about 3 hours, trying to find a way to do it, but i can't figure it out :(
Alpha_ProgDes
Alpha_ProgDes
Quote:
Original post by RLigon
could this be a homework problem? ;)

goes with out saying, don't you think?
in any case, a little help won't hurt.
Beginner in Game Development?  Read here. And read here.  
SnprBoB86
SnprBoB86
Simplify the problem!

Make the first and last lines special cases.
The first line is only a single * in the center or on the far left. That is easy.
The last line is all stars. That is also easy.

All the lines inbetween are [k spaces]*[i spaces]*[k spaces]
If i goes from 0 to width of base - 2, then all you need to is set k equal to the width of the base - i - 2
SnprBoB86
SnprBoB86
Opps:

[k spaces]*[i spaces]*[k spaces] is for isosceles, and u need to use (width of the base - i - 2)/2 for k

and then its:
[i spaces]*[k spaces] for right, but do not devide by 2

I need 2 re-read my posts :-/
Oxyd
Oxyd
Quote:
Original post by srocky26
yeah, it is homework, ive been working on it for about 3 hours, trying to find a way to do it, but i can't figure it out :(


Only 3 hours? That's not too much [smile] We don't give much help with homeworks here...

But I'll throw something in. When drawing an unfilled right triangle - normally it's filled with '*', right? So, what about drawing the triangle like it was filled, but printing ' ' (a space), instead of '*' when you're not printing out first / last asterisk on the given line?

Oxyd

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.