Cercles et ellipses
A propos du code
Cercle polaire
 
				 
				 
				
		cos θ = x / R
		sin θ = y / R
				
		x = R * cos θ
		y = R * sin θ
				
		x = xC + R * cos θ
		y = yC + R * sin θ
				
		#define DEG_TO_RAD(_x)  ((_x) * M_PI / 180.0)
				
		#include <stdio.h>
		#include <stdlib.h>
		#include <math.h>
		#include "main.h"
		#include "Graphics.h"
		#include "System.h"
		#define SCREEN_WIDTH    640
		#define SCREEN_HEIGHT   480
		#define DEG_TO_RAD(_x)  ((_x) * M_PI / 180.0)
		int main(int argc, char* argv[])
		{
			// init the window
			gfx.init("Circle", SCREEN_WIDTH, SCREEN_HEIGHT);
			gfx.init2D();
			gfx.clearScreen(Color(0, 0, 0, SDL_ALPHA_OPAQUE));
			int centerX = SCREEN_WIDTH / 2;
			int centerY = SCREEN_HEIGHT / 2;
			int radius = 200;
			for (int i = 0; i < 360; i++)
			{
				float angle = DEG_TO_RAD(i);
				int x = centerX + radius * cos(angle);
				int y = centerY + radius * sin(angle);
				gfx.setPixel(x, y, Color(255, 255, 255));
				gfx.render();
				sys.wait(20);
			}
			// wait until we quit
			while (sys.isQuitRequested() == false)
			{
				gfx.render();
				sys.wait(20);
				sys.processEvents();
			}
			gfx.quit();
			return EXIT_SUCCESS;
		}
		
		Télécharger le code source
		Télécharger l'exécutable pour Windows
				 
				
Boucher les trous
		gfx.setPixel(x, y, Color(255, 255, 255));
				
		gfx.line(centerX, centerY, x, y, Color(255, 255, 255));
		
		Télécharger le code source
		Télécharger l'exécutable pour Windows
				
 
				
		for (int i = 0; i < 360; i++)
		{
			float angle0 = DEG_TO_RAD(i);
			int x0 = centerX + radius * cos(angle0);
			int y0 = centerY + radius * sin(angle0);
			float angle1 = DEG_TO_RAD(i + 1);
			int x1 = centerX + radius * cos(angle1);
			int y1 = centerY + radius * sin(angle1);
			gfx.line(x0, y0, x1, y1, Color(255, 255, 255));
			gfx.render();
			sys.wait(20);
			sys.processEvents();
		}
	
		Télécharger le code source
		Télécharger l'exécutable pour Windows
				 
				
Changer les paramètres
		x = xC + R * cos θ
		y = yC + R * sin θ
				
		int centerX = SCREEN_WIDTH / 2;
		int centerY = SCREEN_HEIGHT / 2;
		int radiusX = 200;
		int radiusY = 100;
		for (int i = 0; i < 360; i++)
		{
			float angle0 = DEG_TO_RAD(i);
			int x0 = centerX + radiusX * cos(angle0);
			int y0 = centerY + radiusY * sin(angle0);
			float angle1 = DEG_TO_RAD(i + 1);
			int x1 = centerX + radiusX * cos(angle1);
			int y1 = centerY + radiusY * sin(angle1);
			gfx.line(x0, y0, x1, y1, Color(255, 255, 255));
			gfx.render();
			sys.wait(20);
		}
	
		Télécharger le code source
		Télécharger l'exécutable pour Windows
				 
				
		int centerX = SCREEN_WIDTH / 2;
		int centerY = SCREEN_HEIGHT / 2;
		int radius = 200;
		float angleAdd = DEG_TO_RAD(20);
		for (int i = 0; i < 360; i++)
		{
			float angle0 = DEG_TO_RAD(i);
			int x0 = centerX + radius * cos(angle0 + angleAdd);
			int y0 = centerY + radius * sin(angle0);
			float angle1 = DEG_TO_RAD(i + 1);
			int x1 = centerX + radius * cos(angle1 + angleAdd);
			int y1 = centerY + radius * sin(angle1);
			gfx.line(x0, y0, x1, y1, Color(255, 255, 255));
			gfx.render();
			sys.wait(20);
		}
	
		Télécharger le code source
		Télécharger l'exécutable pour Windows
				 
				
		for (int i = 0; i < 360; i++)
		{
			for (int j = -90; j <= 90; j += 10)
			{
				float angleAdd = DEG_TO_RAD(j);
				float angle0 = DEG_TO_RAD(i);
				int x0 = centerX + radius * cos(angle0 + angleAdd);
				int y0 = centerY + radius * sin(angle0);
				float angle1 = DEG_TO_RAD(i + 1);
				int x1 = centerX + radius * cos(angle1 + angleAdd);
				int y1 = centerY + radius * sin(angle1);
				gfx.line(x0, y0, x1, y1, Color(255, 255, 255));
			}
			gfx.render();
			sys.wait(20);
		}
	
		Télécharger le code source
		Télécharger l'exécutable pour Windows
				