Rattrapage commits

This commit is contained in:
HORVILLE 2022-01-18 12:52:55 +01:00
parent 2528801966
commit d1869af19f
21 changed files with 1010 additions and 2 deletions

71
APL1.2/FUn/flocon.c Normal file
View File

@ -0,0 +1,71 @@
#include <stdio.h>
#include <stdlib.h>
#include <graph.h>
#include <math.h>
#include <time.h>
#include "graph_sup.h"
struct vertex {
double x;
double y;
struct vertex* next;
};
typedef struct vertex vert;
typedef vert* poly;
double rad(double deg) {
return deg/180 * M_PI;
}
double a = 0.0;
poly makePoly(double x, double y, double r, double s) {
int max = 600;
double delta_ang = rad(360/(double)max);
vert* last_v = NULL;
vert* first_v = NULL;
for (int i = 0; i < s; i++) {
vert * v
}
first_v->next = last_v;
return last_v;
}
void drawPoly(poly tri) {
vert* start = tri;
int has_started = 0;
while (tri != start || has_started == 0) {
has_started = 1;
int x = tri->x;
int y = tri->y;
vert* next = tri->next;
int xx = next->x;
int yy = next->y;
tri = tri->next;
DessinerSegment(x, y, xx, yy);
}
}
int main(int argc, char * argv[]) {
InitialiserGraphique();
CreerFenetre(100, 100, 1920, 1080);
while (1) {
if (DrawNextFrame()) {
a += 0.01;
SetColor(255, 255, 255);
RemplirRectangle(0, 0, 1920, 1080);
SetColor(255, 0, 0);
poly pol = makePoly(1920/2, 1080/2, 400);
drawPoly(pol);
}
}
FermerGraphique();
return EXIT_SUCCESS;
}

71
APL1.2/FUn/graph_sup.c Normal file
View File

@ -0,0 +1,71 @@
#include "utils.h"
#include <graph.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "graph_sup.h"
#define FPS 60.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;
}

32
APL1.2/FUn/graph_sup.h Normal file
View File

@ -0,0 +1,32 @@
#ifndef _GRAPH_SUP_H
#define _GRAPH_SUP_H
#define WIDTH 1200
#define HEIGHT 700
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

13
APL1.2/TP09/curiosite.c Normal file
View File

@ -0,0 +1,13 @@
#include <stdio.h>
#include <stdlib.h>
int f(int n) {
if (n>100)
return n-10;
else
return f(f(n+11));
}
int main(void) {
}

67
APL1.2/TP09/dragon.c Normal file
View File

@ -0,0 +1,67 @@
#include <stdio.h>
#include <stdlib.h>
#include <graph.h>
#include <math.h>
#include "graph_sup.h"
struct vec2_ {
double x;
double y;
};
typedef struct vec2_ vec2;
vec2 VRotate(vec2 vec, double theta) {
vec2 new_vec = {0, 0};
theta = theta / 180 * M_PI;
new_vec.x = cos(theta) * vec.x - sin(theta) * vec.y;
new_vec.y = sin(theta) * vec.x + cos(theta) * vec.y;
return new_vec;
}
vec2 MakeFractal(vec2 pos, int n, double size, double theta, double a) {
if (n > 1) {
SetColor(0, 0, 255);
//RemplirRectangle(pos.x - 5, pos.y - 5, 10, 10);
vec2 vect1 = MakeFractal(pos, n-1, size / sqrt(2), theta + 45, a);
vec2 offset = {-size * sqrt(2), 0};
offset = VRotate(offset, theta - 45);
pos.x += offset.x;
pos.y += offset.y;
vec2 vect2 = MakeFractal(pos, n-1, -size / sqrt(2), theta - 45 + a, a);
} else {
vec2 vec = {size, size};
vec = VRotate(vec, theta + 90);
SetColor(0, 0, 0);
DessinerSegment(pos.x, pos.y, pos.x + vec.x, pos.y + vec.y);
SetColor(255, 0, 0);
//RemplirRectangle(pos.x + vec.x - 6, pos.y + vec.y - 6, 12, 12);
return vec;
}
}
int main(void) {
int level;
/*printf("Niveau de complexité : ");
scanf("%d", &level);*/
level = 14;
vec2 vec = {WIDTH/2, 200};
double a = 0;
InitialiserGraphique();
CreerFenetre(100, 100, WIDTH, HEIGHT);
SetColor(255, 0, 0);
//DessinerRectangle(vec.x-300, vec.y, 300, 300);
while (1) {
if (DrawNextFrame()) {
a += 2.5;
SetColor(255, 255, 255);
RemplirRectangle(0, 0, WIDTH, HEIGHT);
SetColor(0, 0, 0);
MakeFractal(vec, level, 200, 0, a);
}
}
Touche();
FermerGraphique();
}

71
APL1.2/TP09/graph_sup.c Normal file
View File

@ -0,0 +1,71 @@
#include "utils.h"
#include <graph.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "graph_sup.h"
#define FPS 10.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;
}

32
APL1.2/TP09/graph_sup.h Normal file
View File

@ -0,0 +1,32 @@
#ifndef _GRAPH_SUP_H
#define _GRAPH_SUP_H
#define WIDTH 1200
#define HEIGHT 700
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

13
APL1.2/TP09/mystere.c Normal file
View File

@ -0,0 +1,13 @@
#include <stdio.h>
#include <stdlib.h>
unsigned int mystere(unsigned int a,unsigned int b) {
if (b==0)
return 0;
else
return a*(b & 1)+mystere(a<<1,b>>1);
}
int main(void) {
printf("%d\n", mystere(105, 50));
}

79
APL1.2/TP09/triangle.c Normal file
View File

@ -0,0 +1,79 @@
#include <stdio.h>
#include <stdlib.h>
#include <graph.h>
#include <math.h>
#include "graph_sup.h"
struct vec2_ {
double x;
double y;
};
typedef struct vec2_ vec2;
struct tri_ {
vec2 p1;
vec2 p2;
vec2 p3;
};
typedef struct tri_ tri;
int level;
void drawTri(tri trig) {
vec2 p1 = trig.p1;
vec2 p2 = trig.p2;
vec2 p3 = trig.p3;
DessinerSegment(p1.x, p1.y, p2.x, p2.y);
DessinerSegment(p2.x, p2.y, p3.x, p3.y);
DessinerSegment(p3.x, p3.y, p1.x, p1.y);
}
tri makeTri(vec2 pos, double size) {
vec2 p1 = pos;
vec2 p2 = pos;
vec2 p3 = pos;
p2.x += size / 2;
p3.x -= size / 2;
p2.y += sqrt((3 * pow(size, 2)) / 4);
p3.y += sqrt((3 * pow(size, 2)) / 4);
tri trig = {p1, p2, p3};
return trig;
}
vec2 makeFractal(vec2 pos, double size, int n) {
if (n == 0) {
drawTri(makeTri(pos, size));
makeFractal(pos, size/2, n+1);
} else if (n < level) {
tri trig1 = makeTri(pos, size);
tri trig2 = makeTri(trig1.p2, size);
tri trig3 = makeTri(trig1.p3, size);
drawTri(trig1);
drawTri(trig2);
drawTri(trig3);
makeFractal(trig1.p1, size / 2, n+1);
makeFractal(trig2.p1, size / 2, n+1);
makeFractal(trig3.p1, size / 2, n+1);
}
}
int main(int argc, char* argv) {
printf("Niveau de complexité : ");
scanf("%d", &level);
vec2 vec = {WIDTH/2, 100};
InitialiserGraphique();
CreerFenetre(100, 100, WIDTH, HEIGHT);
SetColor(0, 0, 0);
makeFractal(vec, HEIGHT-200, 0);
Touche();
FermerGraphique();
}

44
APL1.2/TP10/chainee.c Normal file
View File

@ -0,0 +1,44 @@
#include <stdio.h>
#include <stdlib.h>
struct maillon_ {
char c;
struct maillon_* prev;
};
typedef struct maillon_ maillon;
typedef maillon* pile;
void push(pile* p, char c) {
maillon* m = calloc(1, sizeof(maillon));
m->c = c;
m->prev = *p;
*p = m;
}
char pop(pile* p) {
char c = (*p)->c;
*p = (*p)->prev;
return c;
}
int empty(pile p) {
return p == NULL;
}
char top(pile p) {
return p->c;
}
void clear(pile* p) {
*p = NULL;
}
pile create() {
return NULL;
}
void destroy(pile* p) {
free(p);
}

View File

@ -0,0 +1,37 @@
#include <stdio.h>
#include <stdlib.h>
typedef char* pile;
void push(pile* p, char c) {
p = (pile*)realloc(p, sizeof(*p) + sizeof(char));
(*p)[(sizeof(*p)/sizeof(char))-1] = c;
}
char pop(pile* p) {
char c = (*p)[(sizeof(*p)/sizeof(char))-1];
p = realloc(p, sizeof(*p) - sizeof(char));
return c;
}
int empty(pile p) {
return p[0] == 0;
}
char top(pile p) {
return p[(sizeof(p)/sizeof(char))-1];
}
void clear(pile* p) {
p = realloc(p, sizeof(char));
(*p)[0] = 0;
}
pile create() {
pile p = (pile)calloc(1, sizeof(char));
return p;
}
pile destroy(pile* p) {
free(p);
}

14
APL1.2/TP10/extras.c Normal file
View File

@ -0,0 +1,14 @@
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[]) {
pile p = create();
push(&p, 'O');
push(&p, 'N');
push(&p, 'C');
push(&p, 'R');
push(&p, 'S');
printf("%c\n", top(p));
clear(&p);
printf("%d\n", empty(p));
}

44
APL1.2/TP10/parentheses.c Normal file
View File

@ -0,0 +1,44 @@
#include <stdio.h>
#include <stdlib.h>
#include "chainee.h"
int opening(char c) {
return c == '{' || c == '(' || c == '[';
}
int isPar(char c) {
return c == '{' || c == '}' || c == '(' || c == ')' || c == '[' || c == ']';
}
int isMatching(char a, char b) {
return (a == '(' && b == ')') || (a == '{' && b == '}') || (a == '[' && b == ']');
}
int main(int argc, char* argv[]) {
FILE* f = fopen(argv[1], "r");
pile p;
if (f) {
int valid = 1;
while (!feof(f)) {
char c = fgetc(f);
if (isPar(c)) {
if (opening(c)) push(&p, c);
else {
char par = pop(&p);
if (!isMatching(par, c)) {
printf("Le fichier %s est mal parenthesé !\n", argv[1]);
valid = 0;
break;
}
}
}
}
if (valid) printf("Le fichier %s est bien parenthesé !\n", argv[1]);
fclose(f);
} else puts("Error opening file.");
return EXIT_SUCCESS;
}

View File

@ -0,0 +1,22 @@
#include <stdio.h>
#include <stdlib.h>
#include "chainee_tables.c"
int main(int argc, char* argv[]) {
pile p = create();
puts("La pile attend vos ordres.");
char input[10];
do {
fgets(input, 10, stdin);
if (input[0] == '+') {
push(&p, input[1]);
printf("Le caractère %c a été ajouté.\n", input[1]);
} else if (input[0] == '-') {
if (!empty(p)) {
char c = pop(&p);
printf("Le caractère %c à été supprimé\n", c);
} else puts("La pile est vide !");
}
} while (input[0] != 'q' && input[0] != 'Q');
}

View File

@ -0,0 +1,15 @@
#include <stdio.h>
#include <stdlib.h>
#include "chainee.h"
int main(int argc, char* argv[]) {
pile p;
push(&p, 'O');
push(&p, 'N');
push(&p, 'C');
push(&p, 'R');
push(&p, 'S');
printf("%c\n", top(p));
clear(&p);
printf("%d\n", empty(p));
}

View File

@ -2,6 +2,8 @@ body {
display: grid;
grid-template-columns: 2fr 1fr;
padding: 0% 15% 0% 15%;
height: 100vh;
margin: 0%;
}
p {
@ -84,10 +86,11 @@ aside>p>em:nth-child(1) {
}
footer {
margin-top: 50px;
grid-column: 1 / span 2;
width: 100%;
margin: auto;
}
footer>p {
display: inline;
display: inline-block;
}

51
HTML/TP05/index.html Normal file
View File

@ -0,0 +1,51 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
.menu {
text-align: center;
}
.row {
display: flex;
align-items: center;
justify-content: center;
}
.cell {
width: 10px;
height: 10px;
font-size: 10px;
border: 1px solid black;
display: inline-flex;
justify-content: center;
align-items: center;
font-weight: bold;
}
</style>
</head>
<body>
<menu class="menu">
<button id="save">Sauvegarder</button>
<button id="load">Reprendre</button>
<button id="next-gen">Prochaine Génération</button>
<button id="autoplay">Auto Play</button>
<button id="reset">Reset</button>
<button id="gridsize">Taille Grille</button>
<button id="x1">x1</button>
<button id="x2">x2</button>
<button id="x10">x10</button>
<button id="x100">x100</button>
<br><br>
Génération numéro: <span id="generation-value"></span> | Taille de la grille: <span id="grid-size-value"></span>
</menu>
<div id="container"></div>
</body>
<script src="script.js"></script>
</html>

308
HTML/TP05/script.js Normal file
View File

@ -0,0 +1,308 @@
// -----------------------------------------------------------------------------------------------------------------
/**
* Cette partie du code, vous n'avez pas besoin d'y toucher. Elle permet de gérer la grille et l'affichage des cellules
*/
class GridManager {
ACTIVE_COLOR = 'black';
INACTIVE_COLOR = 'grey';
gridContainerId;
gridSize;
grid = [];
constructor(gridSize, gridContainerId) {
if (!gridSize || gridSize < 30) {
throw new Error('The grid size must be at least 30');
}
if (!gridContainerId) {
throw new Error('gridContainerId must be set');
}
this.gridSize = gridSize;
this.gridContainerId = gridContainerId;
this.createGrid();
}
createGrid() {
const container = document.getElementById(this.gridContainerId);
for (let i = 0; i < this.gridSize; i++) {
const row = document.createElement('div');
row.className = 'row';
const gridRow = [];
for (let j = 0; j < this.gridSize; j++) {
const cell = document.createElement('div');
cell.className = 'cell';
cell.style.backgroundColor = this.INACTIVE_COLOR;
row.appendChild(cell);
gridRow.push(cell);
}
container.appendChild(row);
this.grid.push(gridRow);
}
}
destroyGrid() {
for (let x = 0; x < this.gridSize; x++) {
for (let y = 0; y < this.gridSize; y++) {
const node = this.grid[y][x];
node.parentNode.removeChild(node);
}
}
const container = document.getElementById(this.gridContainerId);
while (container.firstChild) {
container.removeChild(container.lastChild);
}
this.grid = [];
}
setInitialState(initialState) {
const coords = initialState.split(';').map(coord => coord.split(','));
coords.forEach((coord) => this.activeCell(+coord[0], +coord[1]));
}
isInGridRange(x, y) {
return x >= 0 && x < this.gridSize && y >= 0 && y < this.gridSize;
}
isActiveCell(x, y) {
return this.isInGridRange(x, y) && this.grid[y][x].style.backgroundColor === this.ACTIVE_COLOR;
}
activeCell(x, y) {
if (!this.isInGridRange(x, y)) {
return;
}
this.grid[y][x].style.backgroundColor = this.ACTIVE_COLOR;
}
deactiveCell(x, y) {
if (!this.isInGridRange(x, y)) {
return;
}
this.grid[y][x].style.backgroundColor = this.INACTIVE_COLOR;
}
getNumberActiveNeighbourCells(x, y) {
const neighbours = [
[x-1, y-1], [x, y-1], [x+1, y-1],
[x-1, y], [x+1, y],
[x-1, y+1], [x, y+1], [x+1, y+1],
];
return neighbours.map(cell => this.isActiveCell(cell[0], cell[1])).filter(cell => cell === true).length;
}
logCurrentGridState() {
const activeCells = [];
for (let x = 0; x < this.gridSize; x++) {
for (let y = 0; y < this.gridSize; y++) {
if (this.isActiveCell(x, y)) {
activeCells.push(`${x},${y}`);
}
}
}
console.log(activeCells.join(';'));
}
getCurrentGridState() {
const activeCells = [];
for (let x = 0; x < this.gridSize; x++) {
for (let y = 0; y < this.gridSize; y++) {
if (this.isActiveCell(x, y)) {
activeCells.push(`${x},${y}`);
}
}
}
return activeCells.join(';');
}
}
// -----------------------------------------------------------------------------------------------------------------
const INITIAL_STATE = '11,1;12,1;10,2;9,3;9,4;9,5;10,6;11,7;12,7;2,4;1,5;2,5;18,28;17,28;19,27;20,26;20,25;20,24;19,23;18,22;17,22;27,25;28,24;27,24;11,28;12,28;10,27;9,26;9,25;9,24;10,23;11,22;12,22;2,25;1,24;2,24;18,1;17,1;19,2;20,3;20,4;20,5;19,6;18,7;17,7;27,4;28,5;27,5';
const GENERATION_INTERVAL = 1000; // 1 seconde
const DIV_CONTAINER_ID = 'container';
const BTN_AUTOPLAY_ID = 'autoplay';
const BTN_NEXT_GEN_ID = 'next-gen';
const BTN_RESET_ID = 'reset';
const BTN_GRIDSIZE_ID = 'gridsize';
const BTN_SAVE_ID = 'save';
const BTN_LOAD_ID = 'load';
const GENERATION_VAL_ID = 'generation-value';
const GRID_SIZE_VAL_ID = 'grid-size-value';
function computeNextGeneration(gridManager, generation) {
// incrémenter la valeur de la génération et l'afficher à côté de 'Génération numéro:'
const nextGrid = [];
for (let x = 0; x < gridManager.gridSize; x++) {
const row = [];
for (let y = 0; y < gridManager.gridSize; y++) {
const isActive = gridManager.isActiveCell(x, y);
const numberActiveNeighbourCells = gridManager.getNumberActiveNeighbourCells(x, y);
if (!isActive) {
row.push(numberActiveNeighbourCells === 3 ? true : false);
} else {
row.push(numberActiveNeighbourCells === 2 || numberActiveNeighbourCells === 3 ? true : false);
}
}
nextGrid.push(row);
}
for (let x = 0; x < nextGrid.length; x++) {
for (let y = 0; y < nextGrid[x].length; y++) {
nextGrid[x][y] ? gridManager.activeCell(x,y) : gridManager.deactiveCell(x,y);
}
}
generation++;
document.getElementById(GENERATION_VAL_ID).textContent = generation;
gridManager.logCurrentGridState();
return generation;
}
// Fonction principale du jeu
function main() {
let autoplayInterval;
let gridSize = 30;
let generation = 0;
let generationInterval = GENERATION_INTERVAL;
let gridManager = new GridManager(gridSize, DIV_CONTAINER_ID);
gridManager.setInitialState(INITIAL_STATE);
document.getElementById(GRID_SIZE_VAL_ID).textContent = gridSize;
document.getElementById(GENERATION_VAL_ID).textContent = generation;
document.getElementById(BTN_SAVE_ID).addEventListener('click', () => {
if (gridManager) {
gridState = gridManager.getCurrentGridState();
localStorage.setItem("gridState", gridState);
localStorage.setItem("generation", generation);
}
});
document.getElementById(BTN_LOAD_ID).addEventListener('click', () => {
if (gridManager) {
gridState = localStorage.getItem("gridState");
if (gridState != null) {
if (autoplayInterval) {
clearInterval(autoplayInterval);
autoplayInterval = null;
}
gridManager.destroyGrid();
gridManager = new GridManager(gridSize, DIV_CONTAINER_ID);
gridManager.setInitialState(gridState);
document.getElementById(GENERATION_VAL_ID).textContent = localStorage.getItem("generation");
}
}
});
// Lorsqu'un utilisateur clique sur 'Auto Play'
document.getElementById(BTN_AUTOPLAY_ID).addEventListener('click', () => {
if (autoplayInterval) {
return;
}
autoplayInterval = setInterval(() => {
generation = computeNextGeneration(gridManager, generation);
}, generationInterval);
});
// Lorsqu'un utilisateur clique sur 'Prochaine Génération'
document.getElementById(BTN_NEXT_GEN_ID).addEventListener('click', () => {
if (autoplayInterval) {
clearInterval(autoplayInterval);
autoplayInterval = null;
}
generation = computeNextGeneration(gridManager, generation);
});
document.getElementById(BTN_RESET_ID).addEventListener('click', () => {
if (autoplayInterval) {
clearInterval(autoplayInterval);
autoplayInterval = null;
}
generation = 0;
document.getElementById(GENERATION_VAL_ID).textContent = generation;
gridManager.destroyGrid();
gridManager = new GridManager(gridSize, DIV_CONTAINER_ID);
gridManager.setInitialState(INITIAL_STATE);
});
document.getElementById(BTN_GRIDSIZE_ID).addEventListener('click', () => {
let new_size = prompt("Nouvelle taille :");
if (new_size != null) {
let new_size_int = parseInt(new_size);
if (new_size_int != NaN && new_size_int >= 30) {
gridSize = new_size_int;
document.getElementById(GRID_SIZE_VAL_ID).textContent = new_size_int;
document.getElementById(BTN_RESET_ID).click();
}
}
});
document.getElementById("x1").addEventListener('click', () => {
generationInterval = GENERATION_INTERVAL;
if (autoplayInterval) {
clearInterval(autoplayInterval);
autoplayInterval = null;
document.getElementById(BTN_AUTOPLAY_ID).click();
}
});
document.getElementById("x2").addEventListener('click', () => {
generationInterval = GENERATION_INTERVAL / 2;
if (autoplayInterval) {
clearInterval(autoplayInterval);
autoplayInterval = null;
document.getElementById(BTN_AUTOPLAY_ID).click();
}
});
document.getElementById("x10").addEventListener('click', () => {
generationInterval = GENERATION_INTERVAL / 10;
if (autoplayInterval) {
clearInterval(autoplayInterval);
autoplayInterval = null;
document.getElementById(BTN_AUTOPLAY_ID).click();
}
});
document.getElementById("x100").addEventListener('click', () => {
generationInterval = GENERATION_INTERVAL / 100;
if (autoplayInterval) {
clearInterval(autoplayInterval);
autoplayInterval = null;
document.getElementById(BTN_AUTOPLAY_ID).click();
}
});
}
// Le jeu est démarré ici
main();

BIN
HTML/Test/BAHNSCHRIFT.TTF Normal file

Binary file not shown.

9
HTML/Test/style.css Normal file
View File

@ -0,0 +1,9 @@
@font-face {
font-family: myFirstFont;
src: url(BAHNSCHRIFT.TTF);
}
h2 {
font-family: myFirstFont;
color: darkgreen;
}

12
HTML/Test/test.html Normal file
View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content=
"width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
</head>
<body>
<h2>This font is awesome</h2>
</body>
</html>