From 252880196654635c59330f987231edb96827eaea Mon Sep 17 00:00:00 2001 From: HORVILLE Ewen Date: Mon, 10 Jan 2022 17:28:28 +0100 Subject: [PATCH] =?UTF-8?q?TP=2008=20R=C3=A9cursivit=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- APL1.2/TP08/fibonacci.c | 13 ++++++++ APL1.2/TP08/graph_sup.c | 71 +++++++++++++++++++++++++++++++++++++++++ APL1.2/TP08/graph_sup.h | 32 +++++++++++++++++++ APL1.2/TP08/hanoi.c | 57 +++++++++++++++++++++++++++++++++ APL1.2/TP08/phases.c | 17 ++++++++++ APL1.2/TP08/tableau.c | 17 ++++++++++ 6 files changed, 207 insertions(+) create mode 100644 APL1.2/TP08/fibonacci.c create mode 100644 APL1.2/TP08/graph_sup.c create mode 100644 APL1.2/TP08/graph_sup.h create mode 100644 APL1.2/TP08/hanoi.c create mode 100644 APL1.2/TP08/phases.c create mode 100644 APL1.2/TP08/tableau.c diff --git a/APL1.2/TP08/fibonacci.c b/APL1.2/TP08/fibonacci.c new file mode 100644 index 0000000..e1855fd --- /dev/null +++ b/APL1.2/TP08/fibonacci.c @@ -0,0 +1,13 @@ +#include +#include + +int fib(int n) { + if (n > 1) return n + fib(n-1); + else if (n == 1) return 1; + else return 0; +} + +int main(void) { + fibp(15); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/APL1.2/TP08/graph_sup.c b/APL1.2/TP08/graph_sup.c new file mode 100644 index 0000000..c008e65 --- /dev/null +++ b/APL1.2/TP08/graph_sup.c @@ -0,0 +1,71 @@ +#include "utils.h" +#include +#include +#include +#include +#include "graph_sup.h" + +#define FPS 2.0 + +/*La liste des bouttons et leur nombre*/ +button* Buttons; +int BT_Count = 0; + +/*Des variables afin de faciliter le calcul du temps entre chaque image pour int DrawNextFrame().*/ +double delta = (1/FPS)*1000000; +unsigned long suivant = (1/FPS)*1000000; + +/*Un set de fonction permettant de facilement mettre en place des boutons, pouvoir les manipuler et les supprimer + Ces fonctions utilisent la structure struct Button.*/ +void ClearButtons() { + BT_Count = 0; + Buttons = (button*)realloc(Buttons, sizeof(button) * 1); +} + +void AddButton(int x, int y, int w, int h, int id) { + button BT = {x, y, w, h, id}; + BT_Count++; + Buttons = (button*) realloc(Buttons, (BT_Count+1) * sizeof(button)); + Buttons[BT_Count-1] = BT; +} + +int GetButton(int x, int y) { + for (int ID = 0; ID < BT_Count; ID++) { + button BT = Buttons[ID]; + if (x >= BT.x && y >= BT.y && x <= BT.x + BT.w && y <= BT.y + BT.h) { + return BT.id; + } + } + return -1; +} + +/*Des fonctions appelant celles de la bibliothèque graphique afin de réduire la longueur des noms..*/ +couleur GetColorN(char* name) { + return CouleurParNom(name); +} + +couleur GetColor(unsigned char r, unsigned char g, unsigned char b) { + return CouleurParComposante(r, g, b); +} + +void SetColor(unsigned char r, unsigned char g, unsigned char b) { + ChoisirCouleurDessin(CouleurParComposante(r, g, b)); +} + +void SetColorC(couleur Color) { + ChoisirCouleurDessin(Color); +} + +void SetColorN(char* name) { + ChoisirCouleurDessin(CouleurParNom(name)); +} + +/*Permet de faire tourner la partie graphique à X images par secondes définit par la constante FPS.*/ +int DrawNextFrame() { + if (Microsecondes() >= suivant) { + suivant = Microsecondes() + delta; + return 1; + } + + return 0; +} \ No newline at end of file diff --git a/APL1.2/TP08/graph_sup.h b/APL1.2/TP08/graph_sup.h new file mode 100644 index 0000000..f6247c7 --- /dev/null +++ b/APL1.2/TP08/graph_sup.h @@ -0,0 +1,32 @@ +#ifndef _GRAPH_SUP_H +#define _GRAPH_SUP_H + +#define WIDTH 1600 +#define HEIGHT 300 + +struct Button { + int x; + int y; + int w; + int h; + int id; +}; + +typedef struct Button button; + +extern button* Buttons; +extern int BT_Count; + +void ClearButtons(); +int GetButton(int x, int y); +void AddButton(int x, int y, int w, int h, int id); + +int DrawNextFrame(void); + +couleur GetColorN(char* name); +couleur GetColor(unsigned char r, unsigned char g, unsigned char b); +void SetColor(unsigned char r, unsigned char g, unsigned char b); +void SetColorC(couleur Color); +void SetColorN(char* name); + +#endif \ No newline at end of file diff --git a/APL1.2/TP08/hanoi.c b/APL1.2/TP08/hanoi.c new file mode 100644 index 0000000..3853ff0 --- /dev/null +++ b/APL1.2/TP08/hanoi.c @@ -0,0 +1,57 @@ +#include +#include +#include +#include "graph_sup.h" + +int game_size; + +unsigned char* makeSite(unsigned char size) { + unsigned char* site = calloc(size, sizeof(unsigned char)); + return site; +} + +void populateSite(unsigned char* site, int size) { + for (int i = 0; i < size; i++) { + site[i] = i+1; + } +} + +void showSite(unsigned char* site, int pos) { + for (int i = 0; i < game_size; i++) { + + } +} + +int main(void) { + printf("Number of plates : "); + scanf("%d", &game_size); + unsigned char* site1 = makeSite(game_size); + unsigned char* site2 = makeSite(game_size); + unsigned char* site3 = makeSite(game_size); + + int block_size = ((HEIGHT - HEIGHT/10) / game_size); + + populateSite(site1, game_size); + + InitialiserGraphique(); + CreerFenetre(100, 100, WIDTH, HEIGHT); + + SetColor(100, 100, 200); + RemplirRectangle(0, 0, WIDTH, HEIGHT); + SetColor(0, 170, 0); + RemplirRectangle(0, HEIGHT - block_size, WIDTH, block_size); + SetColor(255, 255, 255); + + for (int i = 0; i < game_size; i++) { + for (int j = 0; j < 3; j++) { + + } + } + + while (1) { + if (DrawNextFrame()) { + + } + } + FermerGraphique(); +} \ No newline at end of file diff --git a/APL1.2/TP08/phases.c b/APL1.2/TP08/phases.c new file mode 100644 index 0000000..24f4b54 --- /dev/null +++ b/APL1.2/TP08/phases.c @@ -0,0 +1,17 @@ +#include +#include + +void exemple(unsigned n) { + if (n != 0) { + putchar('>'); + exemple(n-1); + putchar('<'); + } else { + putchar('O'); + } +} + +int main(void) { + exemple(5); + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/APL1.2/TP08/tableau.c b/APL1.2/TP08/tableau.c new file mode 100644 index 0000000..ffe0bb4 --- /dev/null +++ b/APL1.2/TP08/tableau.c @@ -0,0 +1,17 @@ +#include +#include + +void printTable(double* t, int n) { + if (n > 0) { + printf("%.5lf", *t); + if (n > 1) printf(", "); + printTable(t+1, n-1); + } else puts(""); +} + +int main(void) { + double t[5] = {1.72, 5.28, 9.025, 36.14, 3.14159}; + + printTable(t, 5); + return EXIT_SUCCESS; +} \ No newline at end of file