update
This commit is contained in:
BIN
DEV.3.4/TP/TP4/stub/0Bad/Base.class
Normal file
BIN
DEV.3.4/TP/TP4/stub/0Bad/Base.class
Normal file
Binary file not shown.
BIN
DEV.3.4/TP/TP4/stub/0Bad/Exemple.class
Normal file
BIN
DEV.3.4/TP/TP4/stub/0Bad/Exemple.class
Normal file
Binary file not shown.
BIN
DEV.3.4/TP/TP4/stub/0Bad/MonBrin.class
Normal file
BIN
DEV.3.4/TP/TP4/stub/0Bad/MonBrin.class
Normal file
Binary file not shown.
BIN
DEV.3.4/TP/TP4/stub/0Bad/MonMaillon.class
Normal file
BIN
DEV.3.4/TP/TP4/stub/0Bad/MonMaillon.class
Normal file
Binary file not shown.
BIN
DEV.3.4/TP/TP4/stub/1Iterable/Base.class
Normal file
BIN
DEV.3.4/TP/TP4/stub/1Iterable/Base.class
Normal file
Binary file not shown.
BIN
DEV.3.4/TP/TP4/stub/1Iterable/Exemple.class
Normal file
BIN
DEV.3.4/TP/TP4/stub/1Iterable/Exemple.class
Normal file
Binary file not shown.
40
DEV.4.1/tp/tp1/eratosthene/eratosthene.html
Normal file
40
DEV.4.1/tp/tp1/eratosthene/eratosthene.html
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title></title>
|
||||||
|
<link rel="stylesheet"
|
||||||
|
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.classless.min.css"
|
||||||
|
>
|
||||||
|
<script src="eratosthene.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<main>
|
||||||
|
|
||||||
|
<form role="search">
|
||||||
|
<input name="limit" type="text">
|
||||||
|
<input type="submit" value="compute">
|
||||||
|
</form>
|
||||||
|
<article>
|
||||||
|
<p>time : <span id="time1"></span></p>
|
||||||
|
<p>time : <span id="time2"></span></p>
|
||||||
|
<p id="primes"></p>
|
||||||
|
</article>
|
||||||
|
</main>
|
||||||
|
<script>
|
||||||
|
document.querySelector("form").addEventListener("submit",ev => {
|
||||||
|
ev.preventDefault();
|
||||||
|
|
||||||
|
let start,end;
|
||||||
|
|
||||||
|
start = performance.now();
|
||||||
|
primes = eratosthene1(ev.target.limit.value);
|
||||||
|
end = performance.now();
|
||||||
|
|
||||||
|
document.getElementById("time1").textContent = end - start;
|
||||||
|
document.getElementById("primes").textContent = primes;
|
||||||
|
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
23
DEV.4.1/tp/tp1/eratosthene/eratosthene.js
Normal file
23
DEV.4.1/tp/tp1/eratosthene/eratosthene.js
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
|
||||||
|
function eratosthene(n)
|
||||||
|
{
|
||||||
|
let primes = [];
|
||||||
|
let filterArray = [];
|
||||||
|
for(let i = 2; i <=n; i++){
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
return primes;
|
||||||
|
}
|
||||||
|
|
||||||
|
function eratosthene1(n)
|
||||||
|
{
|
||||||
|
let numbers = Array.from({length : n - 2}, (v,k) => k + 2);
|
||||||
|
let p ,primes = [];
|
||||||
|
|
||||||
|
while(numbers.length){
|
||||||
|
[p,...numbers] = numbers;
|
||||||
|
numbers = numbers.filter( x => x%p != 0);
|
||||||
|
primes = [...primes,p];
|
||||||
|
}
|
||||||
|
return primes;
|
||||||
|
}
|
||||||
65
DEV.4.1/tp/tp1/langton/app.js
Normal file
65
DEV.4.1/tp/tp1/langton/app.js
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
import render from "./modules/langton-renderer-canvas2d";
|
||||||
|
import Ant from "./modules/Ant.js";
|
||||||
|
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
antStateColors : ['red','yellow'],
|
||||||
|
tileStateColors : ['white','black'],
|
||||||
|
tileSize : 5
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// For the view
|
||||||
|
|
||||||
|
const STEP_INTERVAL = 5;
|
||||||
|
const BTN_AUTOPLAY_ID = 'autoplay';
|
||||||
|
const BTN_NEXT_MOVE_ID = 'next-move';
|
||||||
|
const MOVE_VAL_ID = 'move-value';
|
||||||
|
const BTN_PLUS_100_ID = 'plus-100';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
let autoplayInterval;
|
||||||
|
let canvas = document.querySelector("canvas");
|
||||||
|
|
||||||
|
|
||||||
|
canvas.width = window.innerWidth ;
|
||||||
|
canvas.height = window.innerHeight;
|
||||||
|
|
||||||
|
let ant = new Ant(Math.floor(canvas.width / options.tileSize),Math.floor(canvas.height/options.tileSize));
|
||||||
|
|
||||||
|
document.getElementById(BTN_AUTOPLAY_ID).addEventListener('click', () => {
|
||||||
|
if (autoplayInterval) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// TODO
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
document.getElementById(BTN_PLUS_100_ID).addEventListener('click', () => {
|
||||||
|
if (autoplayInterval) {
|
||||||
|
clearInterval(autoplayInterval);
|
||||||
|
autoplayInterval = null;
|
||||||
|
}
|
||||||
|
// TODO
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById(BTN_NEXT_MOVE_ID).addEventListener('click', () => {
|
||||||
|
if (autoplayInterval) {
|
||||||
|
clearInterval(autoplayInterval);
|
||||||
|
autoplayInterval = null;
|
||||||
|
}
|
||||||
|
ant.moveForward();
|
||||||
|
updateView(ant,canvas,options)
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
function updateView(ant,canvas,options)
|
||||||
|
{
|
||||||
|
document.getElementById(MOVE_VAL_ID).textContent = `${ant.move}`;
|
||||||
|
render(ant,canvas,options);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
updateView(ant,canvas,options);
|
||||||
8
DEV.4.1/tp/tp1/langton/css/style.css
Normal file
8
DEV.4.1/tp/tp1/langton/css/style.css
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
canvas {
|
||||||
|
position : absolute ;
|
||||||
|
top : 0;
|
||||||
|
left : 0;
|
||||||
|
z-index : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
42
DEV.4.1/tp/tp1/langton/index.html
Normal file
42
DEV.4.1/tp/tp1/langton/index.html
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="fr">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="initial-scale=1,witdh=device-width">
|
||||||
|
|
||||||
|
<title>Fourmi de Langton</title>
|
||||||
|
<link
|
||||||
|
rel="stylesheet"
|
||||||
|
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.classless.min.css"
|
||||||
|
>
|
||||||
|
<!--link
|
||||||
|
rel="stylesheet"
|
||||||
|
href="https://cdn.jsdelivr.net/npm/bulma@1.0.4/css/bulma.min.css"
|
||||||
|
-->
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="./css/style.css">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<main>
|
||||||
|
<h4>
|
||||||
|
Fourmi de Langton
|
||||||
|
</h4>
|
||||||
|
|
||||||
|
<nav>
|
||||||
|
<ul>
|
||||||
|
<li><a href="#" id="next-move">Next</a></li>
|
||||||
|
<li><a href="#" id="autoplay">Auto</a></li>
|
||||||
|
<li><a href="#" id="plus-100">+100</a></li>
|
||||||
|
</ul>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<small>Nombre de mouvements : <span id="move-value"></span></small>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
</main>
|
||||||
|
<canvas></canvas>
|
||||||
|
<script type="module" src="app.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
62
DEV.4.1/tp/tp1/langton/modules/Ant.js
Normal file
62
DEV.4.1/tp/tp1/langton/modules/Ant.js
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
class Ant {
|
||||||
|
x = 0; // position
|
||||||
|
y = 0;
|
||||||
|
move = 0;
|
||||||
|
|
||||||
|
w = 0; // universe dimensions
|
||||||
|
h = 0;
|
||||||
|
|
||||||
|
direction = 0; // 0 90 180 270
|
||||||
|
state = 0;
|
||||||
|
tiles = null;
|
||||||
|
|
||||||
|
constructor (w,h)
|
||||||
|
{
|
||||||
|
this.tiles = new Array(w).fill(null);
|
||||||
|
this.tiles.forEach((el,i) => this.tiles[i] = new Array(h).fill(0));
|
||||||
|
this.w = w;
|
||||||
|
this.h = h;
|
||||||
|
this.x = Math.floor(w/2);
|
||||||
|
this.y = Math.floor(h/2);
|
||||||
|
}
|
||||||
|
|
||||||
|
moveForward()
|
||||||
|
{
|
||||||
|
switch (this.direction) {
|
||||||
|
case 0:
|
||||||
|
this.x = ((this.x + 1) + this.w) % this.w;
|
||||||
|
break
|
||||||
|
case 90:
|
||||||
|
this.y = ((this.y + 1) + this.h) % this.h;
|
||||||
|
break
|
||||||
|
case 180:
|
||||||
|
this.x = ((this.x - 1) + this.w) % this.w;
|
||||||
|
break
|
||||||
|
case 270:
|
||||||
|
this.y = ((this.y - 1) + this.h) % this.h;
|
||||||
|
break
|
||||||
|
}
|
||||||
|
this.move ++;
|
||||||
|
this.computeNextState();
|
||||||
|
}
|
||||||
|
rotateRight() {
|
||||||
|
this.direction = (this.direction + 90)%360;
|
||||||
|
}
|
||||||
|
|
||||||
|
rotateLeft() {
|
||||||
|
this.direction = (this.direction + 270)%360;
|
||||||
|
}
|
||||||
|
|
||||||
|
computeNextState() {
|
||||||
|
if(this.tiles[this.x][this.y] === 1) { //On vérifie si la prochaine case est noire
|
||||||
|
//On fait en sorte à ce qu'elle soit repeinte en blanc et tourne de 90° à gauche.
|
||||||
|
this.tiles[this.x][this.y] = 0;
|
||||||
|
this.rotateLeft();
|
||||||
|
} else { //Dans ce cas si la prochaine case est blanche
|
||||||
|
// On fait en sorte à ce qu'elle soit repeinte en noir et tourne de 90° à droite.
|
||||||
|
this.tiles[this.x][this.y] = 1;
|
||||||
|
this.rotateRight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Ant;
|
||||||
99
DEV.4.1/tp/tp1/langton/modules/langton-renderer-canvas2d.js
Normal file
99
DEV.4.1/tp/tp1/langton/modules/langton-renderer-canvas2d.js
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
/**
|
||||||
|
* render - renders the universe to a 2D canvas.
|
||||||
|
*
|
||||||
|
* @param langtonsAnt - the universe.
|
||||||
|
* @param canvas - The 2D canvas.
|
||||||
|
* @param options - The rendering options (all optional).
|
||||||
|
* @returns {undefined} - Nothing is returned.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function render(langtonsAnt, canvas, options) {
|
||||||
|
|
||||||
|
// Grab our options.
|
||||||
|
const {
|
||||||
|
tileStateColors,
|
||||||
|
antStateColors,
|
||||||
|
tileSize
|
||||||
|
} = options;
|
||||||
|
|
||||||
|
|
||||||
|
// Drawing style.
|
||||||
|
const backgroundColor = '#FFFFFF';
|
||||||
|
|
||||||
|
// Size constants.
|
||||||
|
const w = canvas.width;
|
||||||
|
const h = canvas.height;
|
||||||
|
|
||||||
|
// Bounds constants.
|
||||||
|
const gridSizeW = langtonsAnt.tiles.length;
|
||||||
|
const gridSizeH = langtonsAnt.tiles[0].length;
|
||||||
|
|
||||||
|
// We're going to draw each square with a given edge size
|
||||||
|
|
||||||
|
const tileSizeW = tileSize;//w / gridSizeW ;
|
||||||
|
const tileSizeH = tileSize; //h / gridSizeH ;
|
||||||
|
|
||||||
|
// Get the drawing context.
|
||||||
|
var ctx = canvas.getContext('2d');
|
||||||
|
|
||||||
|
// Clear the background.
|
||||||
|
ctx.fillStyle = backgroundColor;
|
||||||
|
ctx.fillRect(0, 0, w, h);
|
||||||
|
|
||||||
|
// Draw the grid.
|
||||||
|
ctx.strokeStyle='#00000011';
|
||||||
|
for (let x = 0; x <= gridSizeW; x++) {
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.moveTo(x * tileSizeW , 0);
|
||||||
|
ctx.lineTo(x * tileSizeW , h);
|
||||||
|
ctx.closePath();
|
||||||
|
ctx.stroke();
|
||||||
|
}
|
||||||
|
for (let y = 0 ; y <= gridSizeH; y++) {
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.moveTo(0, y * tileSizeH);
|
||||||
|
ctx.lineTo(w, y * tileSizeH);
|
||||||
|
ctx.closePath();
|
||||||
|
ctx.stroke();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Start drawing those tiles.
|
||||||
|
langtonsAnt.tiles.forEach((tileRow,i) => {
|
||||||
|
tileRow.forEach((tile,j)=>{
|
||||||
|
|
||||||
|
// Get the tile state index.
|
||||||
|
|
||||||
|
// Skip state zero tiles (i.e. white tiles)
|
||||||
|
if (tile !== 0) {
|
||||||
|
// Set the tile colour, defaulting to grey if it is not set.
|
||||||
|
ctx.fillStyle = tileStateColors[tile] || '#CCCCCC';
|
||||||
|
ctx.fillRect(i * tileSizeW + 1, j * tileSizeH +1, tileSizeW - 1, tileSizeH - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
// Draw the ant.
|
||||||
|
var antX = langtonsAnt.x * tileSizeW,
|
||||||
|
antY = langtonsAnt.y * tileSizeH;
|
||||||
|
const antState = langtonsAnt.state;
|
||||||
|
|
||||||
|
ctx.fillStyle = antStateColors[antState];
|
||||||
|
// Tranform before we draw the ant, it makes it easier.
|
||||||
|
//
|
||||||
|
ctx.save();
|
||||||
|
ctx.translate(antX + tileSizeW/2, antY+tileSizeH/2);
|
||||||
|
ctx.rotate((langtonsAnt.direction / 180) * Math.PI);
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.moveTo(-tileSizeW/2, -tileSizeH/2);
|
||||||
|
ctx.lineTo(tileSizeW/2, 0);
|
||||||
|
ctx.lineTo(-tileSizeW/2, tileSizeH/2);
|
||||||
|
ctx.fill();
|
||||||
|
ctx.closePath();
|
||||||
|
ctx.restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export default render;
|
||||||
Reference in New Issue
Block a user