1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
#include <iostream>
#include <Grapic.h>
const int Dimw =500;
using namespace grapic;
struct Complex{
float x,y;
};
Complex make_complex(float x,float y)
{
Complex c;
c.x=x;
c.y=y;
return c;
}
float rad_to_deg(float a)
{
return(a*360.0)/(2*M_PI);
}
float deg_to_rad(float a)
{
return (a*2*M_PI)/360.0;
}
Complex make_complex_exp(float r,float theta_deg)
{
Complex c;
float a = deg_to_rad(theta_deg);
c.x=r*cos(a);
c.y=r*sin(a);
return c;
}
Complex operator+(Complex a,Complex b)
{
Complex c;
c.x=a.x+b.x;
c.y=a.y+b.y;
return c;
}
Complex operator-(Complex a,Complex b)
{
Complex c;
c.x=a.x-b.x;
c.y=a.y-b.y;
return c;
}
Complex operator*(Complex a,float lambda)
{
return(make_complex(a.x*lambda,a.y*lambda));
}
Complex scale (Complex a,float cx,float cy, float lambda)
{
Complex res;
Complex tr=make_complex(cx,cy);
res=((a-tr)*lambda+tr);
return res;
}
Complex operator*(Complex a,Complex b)
{
return (make_complex(a.x*b.x-a.y*b.y,a.x*b.y+a.y*b.x));
}
Complex Rotate(Complex p,float cx,float cy,float theta_deg)
{
Complex res,r,tr;
r=make_complex_exp(1,theta_deg);
tr=make_complex(cx,cy);
res=((p-tr)*r)+tr;
return res;
}
struct boule{
Complex c;
int bl;
};
void Draw (boule B){
circleFill(B.c.x,B.c.y, 10);
}
void init (boule &B) {
B.c=make_complex(Dimw/2,Dimw/2);
if (isKeyPressed (SDLK_SPACE)){
Draw(B);
}
}
void update (boule &B){
B.c.x =B.c.x +0.8;
}
int main (int, char**){
bool stop=false;
winInit("projet", 800, Dimw);
boule B;
init (B);
setKeyRepeatMode(true);
while( !stop )
{
winClear();
//Draw(B);
update (B);
backgroundColor(100,100,100,85);
//100,255,50,85);...........................vert
stop = winDisplay();
}
winQuit();
return 0;
} |
Partager