Révisions
This commit is contained in:
83
Révisions/Structures/alterations.c
Normal file
83
Révisions/Structures/alterations.c
Normal file
@@ -0,0 +1,83 @@
|
||||
#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();
|
||||
}
|
117
Révisions/Structures/combinaisons.c
Normal file
117
Révisions/Structures/combinaisons.c
Normal file
@@ -0,0 +1,117 @@
|
||||
#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);
|
||||
}
|
||||
|
||||
int max(int x, int y) {
|
||||
return x > y ? x : y;
|
||||
}
|
||||
|
||||
int min(int x, int y) {
|
||||
return x < y ? x : y;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
rekt intersection(rekt rect1, rekt rect2) {
|
||||
rekt rect_inter;
|
||||
rect_inter.x = max(rect1.x, rect2.x);
|
||||
rect_inter.y = max(rect1.y, rect2.y);
|
||||
|
||||
rect_inter.w = min(rect1.x + rect1.w, rect2.x + rect2.w);
|
||||
rect_inter.h = min(rect1.y + rect1.h, rect2.y + rect2.h);
|
||||
|
||||
rect_inter.w -= rect_inter.x;
|
||||
rect_inter.h -= rect_inter.y;
|
||||
|
||||
return rect_inter;
|
||||
}
|
||||
|
||||
rekt mariage(rekt rect1, rekt rect2) {
|
||||
rekt rect_inter;
|
||||
rect_inter.x = min(rect1.x, rect2.x);
|
||||
rect_inter.y = min(rect1.y, rect2.y);
|
||||
|
||||
rect_inter.w = max(rect1.x + rect1.w, rect2.x + rect2.w);
|
||||
rect_inter.h = max(rect1.y + rect1.h, rect2.y + rect2.h);
|
||||
|
||||
rect_inter.w -= rect_inter.x;
|
||||
rect_inter.h -= rect_inter.y;
|
||||
|
||||
return rect_inter;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
rekt rectangle_toto1 = {300, 300, 300, 200};
|
||||
rekt rectangle_toto2 = {350, 400, 200, 250};
|
||||
|
||||
InitialiserGraphique();
|
||||
CreerFenetre(100, 100, 1200, 700);
|
||||
drawRekt(rectangle_toto1);
|
||||
drawRekt(rectangle_toto2);
|
||||
ChoisirCouleurDessin(CouleurParComposante(255, 0, 0));
|
||||
drawRekt(intersection(rectangle_toto1, rectangle_toto2));
|
||||
ChoisirCouleurDessin(CouleurParComposante(0, 0, 255));
|
||||
drawRekt(mariage(rectangle_toto1, rectangle_toto2));
|
||||
Touche();
|
||||
FermerGraphique();
|
||||
}
|
23
Révisions/Structures/complexes.c
Normal file
23
Révisions/Structures/complexes.c
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
struct complexe {
|
||||
double x;
|
||||
double y;
|
||||
};
|
||||
|
||||
typedef struct complexe complexe;
|
||||
|
||||
double module(complexe z) {
|
||||
return sqrt(pow(z.x, 2) + pow(z.y, 2));
|
||||
}
|
||||
|
||||
complexe conjugue(complexe z) {
|
||||
z.y = -z.y;
|
||||
return z;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
|
||||
}
|
10
Révisions/Structures/date.c
Normal file
10
Révisions/Structures/date.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
int main(void) {
|
||||
time_t stamp = time(NULL);
|
||||
struct tm* temps = localtime(&stamp);
|
||||
|
||||
printf("Nous sommes le : %4d-%02d-%02d\n", temps->tm_year + 1900, temps->tm_mon + 1, temps->tm_mday);
|
||||
}
|
57
Révisions/Structures/rectangles.c
Normal file
57
Révisions/Structures/rectangles.c
Normal file
@@ -0,0 +1,57 @@
|
||||
#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;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
rekt rectangle_toto = {100, 100, 200, 50};
|
||||
|
||||
InitialiserGraphique();
|
||||
CreerFenetre(100, 100, 1200, 700);
|
||||
drawRekt(rectangle_toto);
|
||||
drawRekt(makeRekt());
|
||||
Touche();
|
||||
FermerGraphique();
|
||||
}
|
14
Révisions/Structures/tailles.c
Normal file
14
Révisions/Structures/tailles.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
struct toto {
|
||||
int a;
|
||||
char b;
|
||||
char c;
|
||||
};
|
||||
|
||||
typedef struct toto toto;
|
||||
|
||||
int main(void) {
|
||||
printf("%d\n", sizeof(toto));
|
||||
}
|
Reference in New Issue
Block a user