Public Group

# draw ellipse instead of circle?

This topic is 4153 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi How could i edit this so i can supply a width and height instead of a radius, making it draw a ellipse instead of a circle? Thanks Erik
void gameGFX::circle(float x, float y, float Radius, int Segments, DWORD color)
{
x+=offsetX;
y+=offsetY;

float EachAngle;
float a;
float x1;
float x2;
float y1;
float y2;

EachAngle = 2.0 * M_PI / (float)Segments;

y2 = 0.0;

for(a=0.0; a<= (2.0*M_PI + EachAngle); a+=EachAngle) {
x1 = x2;
y1 = y2;
hge->Gfx_RenderLine(x1+x, y1+y, x2+x, y2+y, color);
}
}



##### Share on other sites
Just change

to

x2 = Width/2.0f * cos(a);
y2 = Height/2.0f * sin(a);

##### Share on other sites
works like a charm, thanks.
for anyone that wants it, here's the draw ellipse code. Just change the last line to your own drawLine function and your own color.

void gameGFX::ellipse(float x, float y, float w,float h, int Segments, DWORD color) { 	x+=offsetX;	y+=offsetY;  float EachAngle;   float a;   float x1;   float x2;   float y1;   float y2;     EachAngle = 2.0 * M_PI / (float)Segments;     x2 = w/2;   y2 = 0;    for(a=0.0; a<= (2.0*M_PI + EachAngle); a+=EachAngle){    x1 = x2;     y1 = y2; 	x2 = w/2.0f * cos(a);	y2 = h/2.0f * sin(a);     hge->Gfx_RenderLine(x1+x, y1+y, x2+x, y2+y, color);   } }

1. 1
2. 2
Rutin
22
3. 3
JoeJ
18
4. 4
5. 5

• 17
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631726
• Total Posts
3001910
×