-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ianis Lallemand
authored and
Ianis Lallemand
committed
Nov 13, 2016
1 parent
90df2a7
commit 9cf9dcb
Showing
35 changed files
with
641 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>introduction-background-refresh</title> | ||
<script src="lib/p5.min.js"></script> | ||
<script src="sketch.js"></script> | ||
<style> body {padding: 0; margin: 0; background-color: #e6e6e6} canvas {margin: 30px auto; display: block}</style> | ||
</head> | ||
<body> | ||
</body> | ||
</html> |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
function setup() { | ||
createCanvas(540, 540); | ||
background(255); // Bonne pratique : rafraîchir l'arrière-plan une première fois dans le 'setup' | ||
} | ||
|
||
function draw() { | ||
background(255); // Rafraîchissement de l'arrière-plan | ||
// Rectangle | ||
fill('#FF0000'); | ||
stroke('rgb(0, 0, 0)'); | ||
rect(0, 0, 100, 120); | ||
// Rectangle | ||
fill(0, 200, 0); | ||
noStroke(); | ||
rect(140, 200, 20, 30); | ||
// Rectangle | ||
stroke('rgba(100, 0, 200, 0.5)'); | ||
strokeWeight(5); | ||
noFill(); | ||
rect(150, 210, 40, 40); | ||
// Ellipse | ||
stroke(100); | ||
ellipse(width/2, height/4, 50, 100); | ||
// Ellipse | ||
var c1 = color(150, 150, 150); | ||
stroke(c1); | ||
ellipse(width/2, 3*height/4, 100, 100); | ||
// Ligne | ||
var l = brightness(c1); | ||
colorMode(HSB); | ||
var c2 = color(200, 50, l); | ||
colorMode(RGB); | ||
stroke(c2); | ||
strokeWeight(1); | ||
line(200, 350, 400, 500); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>random-walk-lines</title> | ||
<script src="lib/p5.min.js"></script> | ||
<script src="sketch.js"></script> | ||
<style> body {padding: 0; margin: 0; background-color: #e6e6e6} canvas {margin: 30px auto; display: block}</style> | ||
</head> | ||
<body> | ||
</body> | ||
</html> |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Paramètres | ||
var agentSize = 2; | ||
var stepSize = 10; | ||
var timeIntervalBetweenUpdates = 100; | ||
// ---------- | ||
|
||
var agentPosition; | ||
var agentPreviousPosition; // Stockage de la position précédente | ||
var agentAngle; | ||
var timeOfLastUpdate; | ||
|
||
function setup() { | ||
createCanvas(540, 540); | ||
initPosition(); | ||
agentAngle = random(0, TWO_PI); | ||
background(255); | ||
timeOfLastUpdate = millis(); | ||
} | ||
|
||
function draw() { | ||
var currentTime = millis(); | ||
// Mise à jour de la position | ||
if (currentTime - timeOfLastUpdate > timeIntervalBetweenUpdates) { | ||
timeOfLastUpdate = currentTime; | ||
agentAngle = random(0, TWO_PI); | ||
} | ||
updatePosition(); | ||
// Conditions aux limites | ||
if (agentPosition.x < 0 || agentPosition.x > width || agentPosition.y < 0 || agentPosition.y > height) { | ||
initPosition(); | ||
} | ||
// Dessin | ||
background(255, 255, 255, 3); | ||
stroke(0); // Attention à bien adapter les méthodes de dessin. Nous utilisons 'line' et non plus 'ellipse' | ||
strokeWeight(agentSize); | ||
noFill(); | ||
line(agentPreviousPosition.x, agentPreviousPosition.y, agentPosition.x, agentPosition.y); // Tracer une ligne entre la position précédente et la nouvelle position permet d'éviter d'obtenir des trajectoires 'en pointillé'. | ||
} | ||
|
||
function initPosition() { | ||
agentPosition = createVector(random(width), random(height)); | ||
agentPreviousPosition = agentPosition.copy(); // Initialisation de la variable de stockage. Important : il faut utiliser la méthode 'copy' pour effectivement copier le vecteur. Un simple assignement ('agentPreviousPosition = agentPosition') créerait simplement une référence. | ||
|
||
} | ||
|
||
function updatePosition() { | ||
agentPreviousPosition = agentPosition.copy(); // Sauvegarde de la position précédente | ||
agentPosition.x += cos(agentAngle) * stepSize; | ||
agentPosition.y += sin(agentAngle) * stepSize; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>random-walk-lines-color</title> | ||
<script src="lib/p5.min.js"></script> | ||
<script src="sketch.js"></script> | ||
<style> body {padding: 0; margin: 0; background-color: #e6e6e6} canvas {margin: 30px auto; display: block}</style> | ||
</head> | ||
<body> | ||
</body> | ||
</html> |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Paramètres | ||
var agentSize = 20; | ||
var stepSize = 10; | ||
var timeIntervalBetweenUpdates = 50; | ||
var agentColorHue = 220; // La couleur dominante est spécifiée à l'aide de la teinte du mode de couleur HSB | ||
// ---------- | ||
|
||
var agentPosition; | ||
var agentPreviousPosition; | ||
var agentAngle; | ||
var timeOfLastUpdate; | ||
var agentColor; // Les autres paramètres de couleur seront mis à jour aléatoirement | ||
|
||
function setup() { | ||
createCanvas(540, 540); | ||
initPositionAndColor(); | ||
agentAngle = random(0, TWO_PI); | ||
background(255); | ||
timeOfLastUpdate = millis(); | ||
} | ||
|
||
function draw() { | ||
var currentTime = millis(); | ||
// Mise à jour de la position | ||
if (currentTime - timeOfLastUpdate > timeIntervalBetweenUpdates) { | ||
timeOfLastUpdate = currentTime; | ||
agentAngle = random(0, TWO_PI); | ||
} | ||
updatePosition(); | ||
// Conditions aux limites | ||
if (agentPosition.x < 0 || agentPosition.x > width || agentPosition.y < 0 || agentPosition.y > height) { | ||
initPositionAndColor(); | ||
} | ||
// Dessin | ||
background(255, 255, 255, 1); | ||
stroke(agentColor); | ||
strokeWeight(agentSize); | ||
noFill(); | ||
line(agentPreviousPosition.x, agentPreviousPosition.y, agentPosition.x, agentPosition.y); | ||
} | ||
|
||
function initPositionAndColor() { | ||
agentPosition = createVector(random(width), random(height)); | ||
agentPreviousPosition = agentPosition.copy(); | ||
colorMode(HSB, 360, 100, 100); // Pour mettre à jour la couleur aléatoirement en conservant la teinte 'agentColorHue' définie dans les paramètres, on crée la nouvelle couleur de l'agent dans l'espace HSB. Les paramètres additionnels étalonnent la plage maximale des valeurs de teinte, saturation et luminosité. Les valeurs '360, 100, 100' correspondent à l'espace HSB tel qu'il est défini dans Photoshop. | ||
var c = color(agentColorHue, random(100), random(100)); // Création de la nouvelle couleur en mode HSB | ||
var r = red(c); // Récupération des composantes RGB de la couleur | ||
var g = green(c); | ||
var b = blue(c); | ||
colorMode(RGB); // Retour en mode RGB | ||
agentColor = color(r, g, b); // Mise à jour de la couleur de l'agent en mode RGB | ||
} | ||
|
||
function updatePosition() { | ||
agentPreviousPosition = agentPosition.copy(); | ||
agentPosition.x += cos(agentAngle) * stepSize; | ||
agentPosition.y += sin(agentAngle) * stepSize; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>movement</title> | ||
<script src="lib/p5.min.js"></script> | ||
<script src="sketch.js"></script> | ||
<style> body {padding: 0; margin: 0; background-color: #e6e6e6} canvas {margin: 30px auto; display: block}</style> | ||
</head> | ||
<body> | ||
</body> | ||
</html> |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
var x; // Coordonnées de position | ||
var y; | ||
|
||
function setup() { | ||
createCanvas(540, 540); | ||
x = 0; | ||
y = height/2; | ||
background(255); | ||
} | ||
|
||
function draw() { | ||
// Mise à jour de la position | ||
x += 2; | ||
// Dessin | ||
background(255); | ||
noStroke(); | ||
fill(0); | ||
ellipse(x, y, 10, 10); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>movement-boundaries</title> | ||
<script src="lib/p5.min.js"></script> | ||
<script src="sketch.js"></script> | ||
<style> body {padding: 0; margin: 0; background-color: #e6e6e6} canvas {margin: 30px auto; display: block}</style> | ||
</head> | ||
<body> | ||
</body> | ||
</html> |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
var x; | ||
var y; | ||
|
||
function setup() { | ||
createCanvas(540, 540); | ||
x = 0; | ||
y = height/2; | ||
background(255); | ||
} | ||
|
||
function draw() { | ||
// Mise à jour de la position | ||
x += 2; | ||
// Conditions aux limites (boundary conditions) | ||
if (x > width) { | ||
x = 0; | ||
} | ||
// Dessin | ||
background(255); | ||
noStroke(); | ||
fill(0); | ||
ellipse(x, y, 10, 10); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>movement-boundaries-improved</title> | ||
<script src="lib/p5.min.js"></script> | ||
<script src="sketch.js"></script> | ||
<style> body {padding: 0; margin: 0; background-color: #e6e6e6} canvas {margin: 30px auto; display: block}</style> | ||
</head> | ||
<body> | ||
</body> | ||
</html> |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Paramètres | ||
// Bonne pratique : stocker les paramètres dans des variables initialisées en début de sketch | ||
var agentSize = 10; // Taille de l'agent | ||
var stepSize = 2; // Increment de position (vitesse de l'agent) | ||
// ---------- | ||
|
||
var agentPosition; // Les variables 'utilitaires' (qui doivent être globales mais ne sont pas des paramètres) sont placées juste avant la fonction 'setup()' | ||
|
||
function setup() { | ||
createCanvas(540, 540); | ||
agentPosition = createVector(0, height/2); // Les fonctions et variables définies par la librairie p5.js ne sont pas disponibles en dehors des fonctions 'setup()', 'draw()', etc. | ||
background(255); | ||
} | ||
|
||
function draw() { | ||
// Mise à jour de la position | ||
agentPosition.x += stepSize; | ||
// Conditions aux limites | ||
if (agentPosition.x > width) { | ||
agentPosition.x = 0; | ||
} | ||
// Dessin | ||
background(255); | ||
noStroke(); | ||
fill(0); | ||
ellipse(agentPosition.x, agentPosition.y, agentSize, agentSize); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>movement-angle</title> | ||
<script src="lib/p5.min.js"></script> | ||
<script src="sketch.js"></script> | ||
<style> body {padding: 0; margin: 0; background-color: #e6e6e6} canvas {margin: 30px auto; display: block}</style> | ||
</head> | ||
<body> | ||
</body> | ||
</html> |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Paramètres | ||
var agentSize = 10; | ||
var stepSize = 2; | ||
// ---------- | ||
|
||
var agentPosition; | ||
var agentAngle; | ||
|
||
function setup() { | ||
createCanvas(540, 540); | ||
agentPosition = createVector(random(width), random(height)); // Position aléatoire | ||
agentAngle = random(0, TWO_PI); // Direction aléatoire | ||
background(255); | ||
} | ||
|
||
function draw() { | ||
// Mise à jour de la position | ||
agentPosition.x += cos(agentAngle) * stepSize; | ||
agentPosition.y += sin(agentAngle) * stepSize; | ||
// Conditions aux limites | ||
if (agentPosition.x < 0 || agentPosition.x > width || agentPosition.y < 0 || agentPosition.y > height) { | ||
agentPosition = createVector(random(width), random(height)); // Si l'agent sort de l'espace de dessin, on lui donne une nouvelle position aléatoire | ||
} | ||
// Dessin | ||
background(255); | ||
noStroke(); | ||
fill(0); | ||
ellipse(agentPosition.x, agentPosition.y, agentSize, agentSize); | ||
} |
Oops, something went wrong.