Esempio n. 1
0
void renderEllipse(SDL_Renderer* renderer, Coordinate center, int a, int b, SDL_Color color) {
	SetRenderDrawColor(renderer, color);

	int xc = center.x;
	int yc = center.y;
	int a2 = a * a;
	int b2 = b * b;
	int twoa2 = 2 * a2;
	int twob2 = 2 * b2;
	int p;
	int x = 0;
	int y = b;
	int px = 0;
	int py = twoa2 * y;

	/* Plot the initial point in each quadrant. */
	ellipsePlotPoints(renderer, xc, yc, x, y);

	/* Region 1 */
	p = std::round (b2 - (a2 * b) + (0.25 * a2));
	while (px < py) {
		x++;
		px += twob2;
		if (p < 0)
			p += b2 + px;
		else {
			y--;
			py -= twoa2;
			p += b2 + px - py;
		}
		ellipsePlotPoints(renderer, xc, yc, x, y);
	}

	/* Region 2 */
	p = std::round (b2 * (x+0.5) * (x+0.5) + a2 * (y-1) * (y-1) - a2 * b2);
	
	while (y > 0) {
		y--;
		py -= twoa2;
		if (p > 0)
			p += a2 - py;
		else {
			x++;
			px += twob2;
			p += a2 - py + px;
		}
		ellipsePlotPoints(renderer, xc, yc, x, y);
	}
}
Esempio n. 2
0
void Ellipse::ellipseMid(){
	int Rx2 = Rx * Rx;
	int Ry2 = Ry * Ry;
	int twoRx2=2*Rx2;
	int twoRy2=2*Ry2;
	int p;
	int x=0;
	int y=Ry;
	int px=0;
	int py=twoRx2*y;
	ellipsePlotPoints(center.X,center.Y,x,y);
	p=round(Ry2 - (Rx2 * Ry) + (0.25 * Rx2));
	while(px < py){
		x++;
		px += twoRy2;
		if(p < 0)
			p += Ry2 + px;
		else{
			y--;
			py -= twoRx2;
			p += Ry2 + px -py;
		}
		ellipsePlotPoints(center.X,center.Y,x,y);
	}

	p = round(Ry2 * (x + 0.5) * (x + 0.5) + Rx2 * (y - 1) * (y - 1) - Rx2 * Ry2);
	while(y > 0){
		y--;
		py -= twoRx2;
		if(p > 0)
			p += Rx2 - py;
		else{
			x++;
			px += twoRy2;
			p += Rx2 - py + px;
		}
		ellipsePlotPoints(center.X,center.Y,x,y);
	}
	Ellquesize = Ellque.size();
}