-
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
Dec 6, 2016
1 parent
30f46ac
commit dd35fb6
Showing
3,997 changed files
with
565,619 additions
and
6 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,2 @@ | ||
.DS_Store | ||
cours-hetic-2016.zip | ||
node_modules/ | ||
|
||
# Ignore course packages until they are ready ;) | ||
p28-image-field/ | ||
p29-arduino-server/ | ||
cours-hetic-2016.zip |
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,60 @@ | ||
// Un fonction 'usine' fabriquant un agent. Les options d'initialisation | ||
// sont volontairement restreintes au maximum : la fonction ne prend | ||
// qu'un argument (optionnel), permettant de spécifier la position | ||
// de l'agent lors de sa création. | ||
// | ||
// La philosophie derrière ce choix est qu'il est très facile, | ||
// si le besoin s'en fait sentir, de modifier 'manuellement' les | ||
// propriétés de l'objet après sa création. L'option de créer directement | ||
// l'agent à la position souhaitée est en revanche fournie car l'édition | ||
// manuelle de la propriété 'position' présente des risques : on pourrait | ||
// oublier de mettre à jour la copie 'previousPosition'. | ||
|
||
function createAgent(position) { | ||
|
||
// Création du nouvel objet 'Agent' | ||
var a = {}; | ||
|
||
// Initialisation | ||
a.position = typeof position !== 'undefined' ? position : createVector(random(width), random(height)); // Si aucune position n'est fournie, initialisation avec une position aléatoire | ||
a.previousPosition = a.position.copy(); | ||
a.angle = random(TWO_PI); | ||
a.stepSize = 1; | ||
a.isPositionResetWhenOutside = true; | ||
|
||
// Une méthode mettant à jour de la position de l'agent en fonction de son angle actuel | ||
a.updatePosition = function() { | ||
a.previousPosition = a.position.copy(); | ||
a.position.x += cos(a.angle) * a.stepSize; | ||
a.position.y += sin(a.angle) * a.stepSize; | ||
if (a.isPositionResetWhenOutside && a.isOutsideSketch() > 0) { | ||
a.position = createVector(random(width), random(height)); | ||
a.previousPosition = a.position.copy(); | ||
} | ||
}; | ||
|
||
// Une méthode permettant de vérifier si l'agent est sorti des limites de l'espace du sketch (+ marges) | ||
// La méthode renvoie les valeurs suivantes : | ||
// 0: l'agent n'est pas sorti des limites de l'espace du sketch | ||
// 1: l'agent est sorti par le haut | ||
// 2: l'agent est sorti par la droite | ||
// 3: l'agent est sorti par le bas | ||
// 4: l'agent est sorti par la gauche | ||
a.isOutsideSketch = function() { | ||
if (a.position.y < 0) { | ||
return 1; | ||
} else if (a.position.x > width) { | ||
return 2; | ||
} else if (a.position.y > height) { | ||
return 3; | ||
} else if (a.position.x < 0) { | ||
return 4; | ||
} else { | ||
return 0; | ||
} | ||
}; | ||
|
||
// Retour de l'objet 'Agent' | ||
return a; | ||
|
||
} |
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,26 @@ | ||
// Une fonction 'usine' fabriquant un champ de force basé sur la luminosité des pixels d'une image | ||
|
||
function createImageField(fieldIntensity, image) { | ||
|
||
// Création du nouvel objet 'Image Field' | ||
var f = {}; | ||
|
||
// Initialisation | ||
f.fieldIntensity = fieldIntensity; | ||
f.image = image; | ||
|
||
// Une méthode permettant d'obtenir la valeur du champ de force à une position donnée | ||
f.getFieldValue = function(position) { | ||
var c = f.image.get(floor(position.x/width * image.width), floor(position.y/height * image.height)); // Obtention de la couleur de l'image à une position donnée. L'image est automatiquement ajustée aux dimensions du canvas. | ||
return brightness(c) * f.fieldIntensity; | ||
}; | ||
|
||
// Une méthode permettant d'appliquer un flou à l'image | ||
f.applyBlur = function(level) { | ||
f.image.filter(BLUR, level); | ||
} | ||
|
||
// Retour de l'object 'Image Field' | ||
return f; | ||
|
||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,14 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>image-field</title> | ||
<script src="lib/p5.min.js"></script> | ||
<script language="javascript" type="text/javascript" src="agent.js"></script> | ||
<script language="javascript" type="text/javascript" src="field-image.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,39 @@ | ||
// Paramètres | ||
var fieldIntensity = 0.005; | ||
var agentCount = 10; | ||
var agentSize = 1.5; | ||
var agentAlpha = 120; | ||
var stepSize = 10; | ||
///////////// | ||
|
||
var image; | ||
var agents; | ||
var field; | ||
|
||
function preload() { | ||
image = loadImage('img/x.jpg'); // En appelant la fonction asynchrone 'loadImage' dans la méthode 'preload', on garantit que la suite du sketch ne s'exécutera qu'une fois l'image chargée | ||
} | ||
|
||
function setup() { | ||
createCanvas(540, 540); | ||
agents = []; | ||
var a; | ||
for (var i = agentCount - 1; i >= 0; i--) { | ||
a = createAgent(); | ||
a.stepSize = stepSize; | ||
agents.push(a); | ||
}; | ||
field = createImageField(fieldIntensity, image); | ||
field.applyBlur(10); | ||
background(255); | ||
} | ||
|
||
function draw() { | ||
agents.forEach(function(a) { | ||
a.angle = field.getFieldValue(a.position); | ||
a.updatePosition(); | ||
stroke(0, agentAlpha); | ||
strokeWeight(agentSize); | ||
line(a.previousPosition.x, a.previousPosition.y, a.position.x, a.position.y); | ||
}); | ||
} |
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,60 @@ | ||
// Un fonction 'usine' fabriquant un agent. Les options d'initialisation | ||
// sont volontairement restreintes au maximum : la fonction ne prend | ||
// qu'un argument (optionnel), permettant de spécifier la position | ||
// de l'agent lors de sa création. | ||
// | ||
// La philosophie derrière ce choix est qu'il est très facile, | ||
// si le besoin s'en fait sentir, de modifier 'manuellement' les | ||
// propriétés de l'objet après sa création. L'option de créer directement | ||
// l'agent à la position souhaitée est en revanche fournie car l'édition | ||
// manuelle de la propriété 'position' présente des risques : on pourrait | ||
// oublier de mettre à jour la copie 'previousPosition'. | ||
|
||
function createAgent(position) { | ||
|
||
// Création du nouvel objet 'Agent' | ||
var a = {}; | ||
|
||
// Initialisation | ||
a.position = typeof position !== 'undefined' ? position : createVector(random(width), random(height)); // Si aucune position n'est fournie, initialisation avec une position aléatoire | ||
a.previousPosition = a.position.copy(); | ||
a.angle = random(TWO_PI); | ||
a.stepSize = 1; | ||
a.isPositionResetWhenOutside = true; | ||
|
||
// Une méthode mettant à jour de la position de l'agent en fonction de son angle actuel | ||
a.updatePosition = function() { | ||
a.previousPosition = a.position.copy(); | ||
a.position.x += cos(a.angle) * a.stepSize; | ||
a.position.y += sin(a.angle) * a.stepSize; | ||
if (a.isPositionResetWhenOutside && a.isOutsideSketch() > 0) { | ||
a.position = createVector(random(width), random(height)); | ||
a.previousPosition = a.position.copy(); | ||
} | ||
}; | ||
|
||
// Une méthode permettant de vérifier si l'agent est sorti des limites de l'espace du sketch (+ marges) | ||
// La méthode renvoie les valeurs suivantes : | ||
// 0: l'agent n'est pas sorti des limites de l'espace du sketch | ||
// 1: l'agent est sorti par le haut | ||
// 2: l'agent est sorti par la droite | ||
// 3: l'agent est sorti par le bas | ||
// 4: l'agent est sorti par la gauche | ||
a.isOutsideSketch = function() { | ||
if (a.position.y < 0) { | ||
return 1; | ||
} else if (a.position.x > width) { | ||
return 2; | ||
} else if (a.position.y > height) { | ||
return 3; | ||
} else if (a.position.x < 0) { | ||
return 4; | ||
} else { | ||
return 0; | ||
} | ||
}; | ||
|
||
// Retour de l'objet 'Agent' | ||
return a; | ||
|
||
} |
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,14 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>arduino-server</title> | ||
<script src="lib/p5.min.js"></script> | ||
<script language="javascript" type="text/javascript" src="agent.js"></script> | ||
<script language="javascript" type="text/javascript" src="server/node_modules/socket.io-client/dist/socket.io.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.
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,25 @@ | ||
// Serveur permettant d'afficher la position d'un agent à l'aide d'une LED | ||
|
||
// Paramètres | ||
var webPort = 8080; // Port utilisé pour la communication avec le navigateur | ||
///////////// | ||
|
||
var server = require('http').createServer(), | ||
io = require('socket.io')(server), | ||
five = require("johnny-five"); | ||
|
||
var board = new five.Board({'repl': false}); // Initialisation de la connexion avec la carte Arduino (avec désactivation du REPL fourni par Johnny Five) | ||
board.on('ready', function() { | ||
// Démarrage du serveur Web | ||
server.listen(webPort); | ||
io.on('connection', function(client) { | ||
console.log('Connected with browser'); | ||
var led = new five.Led(13); // Création d'un objet représentant une LED (nous utilisons ici la LED intégrée de la carte Arduino) | ||
client.on('led', function(data) { | ||
data.on ? led.on() : led.off(); | ||
}); | ||
client.on('disconnect', function() { | ||
led.off(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.