83 lines
1.7 KiB
C
83 lines
1.7 KiB
C
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <graph.h>
|
||
|
|
||
|
typedef struct rekt {
|
||
|
int x;
|
||
|
int y;
|
||
|
int w;
|
||
|
int h;
|
||
|
} rekt;
|
||
|
|
||
|
void drawRekt(rekt rectangle) {
|
||
|
DessinerRectangle(rectangle.x, rectangle.y, rectangle.w, rectangle.h);
|
||
|
}
|
||
|
|
||
|
rekt makeRekt() {
|
||
|
rekt toto;
|
||
|
char valid = 0;
|
||
|
while(valid != 2) {
|
||
|
if (SourisCliquee()) {
|
||
|
SourisPosition();
|
||
|
if (valid == 0) {
|
||
|
toto.x = _X;
|
||
|
toto.y = _Y;
|
||
|
valid = 1;
|
||
|
}
|
||
|
else if (valid == 1) {
|
||
|
toto.w = _X - toto.x;
|
||
|
toto.h = _Y - toto.y;
|
||
|
valid = 2;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (toto.w < 0) {
|
||
|
toto.w = -toto.w;
|
||
|
toto.x -= toto.w;
|
||
|
}
|
||
|
|
||
|
if (toto.h < 0) {
|
||
|
toto.h = -toto.h;
|
||
|
toto.y -= toto.h;
|
||
|
}
|
||
|
|
||
|
return toto;
|
||
|
}
|
||
|
|
||
|
void translate(rekt* rectangle, int x, int y) {
|
||
|
rectangle->x += x;
|
||
|
rectangle->y += y;
|
||
|
}
|
||
|
|
||
|
void rotate(rekt* rectangle, int rotation) {
|
||
|
if (rotation == 1) {
|
||
|
int buffer = rectangle->w;
|
||
|
rectangle->w = rectangle->h;
|
||
|
rectangle->h = buffer;
|
||
|
rectangle->x -= rectangle->w;
|
||
|
} else if (rotation == -1) {
|
||
|
int buffer = rectangle->w;
|
||
|
rectangle->w = rectangle->h;
|
||
|
rectangle->h = buffer;
|
||
|
rectangle->y -= rectangle->h;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
int main(void) {
|
||
|
rekt rectangle_toto = {300, 300, 200, 100};
|
||
|
rekt rectangle_toto2 = {300, 300, 200, 100};
|
||
|
|
||
|
InitialiserGraphique();
|
||
|
CreerFenetre(100, 100, 1200, 700);
|
||
|
drawRekt(rectangle_toto);
|
||
|
rotate(&rectangle_toto, 1);
|
||
|
drawRekt(rectangle_toto);
|
||
|
|
||
|
|
||
|
rotate(&rectangle_toto2, -1);
|
||
|
drawRekt(rectangle_toto2);
|
||
|
drawRekt(makeRekt());
|
||
|
Touche();
|
||
|
FermerGraphique();
|
||
|
}
|