Et voici donc ma contribution pour fêter les 8 ans Codelab... ![]()
>>> C8deLabyrinth <<<
(Bien entendu, si certaines bouboules ne coopèrent pas, c'est le fait d'un l’algorithme savamment étudié pour qu'elles se comportent ainsi. Cela va de soi.
)
// Copyright Olivier Baudu 2016
// Published under the terms of GPL v3.0
var masterPiece;
var img = [];
var labyrinth = [];
var non_modifiable;
var wait;
var bouboule;
var mesBoules = [];
var vitesse;
var reload;
function preload() {
img[0] = loadImage("0.png");
img[1] = loadImage("1.png");
bouleNoire = loadImage("bouleNoire.png");
bouleJaune = loadImage("bouleJaune.png");
}
function setup() {
masterPiece = createCanvas(600, 600);
masterPiece.parent('tableau');
noStroke();
frameRate(60);
for(var i=0; i<900; i++) {
labyrinth[i] = new Couloir(i);
labyrinth[i].show();
}
loadPixels();
reload = false;
if (wait == 0) {
non_modifiable = -1;
} else wait--;
vitesse = createVector(0, 1);
}
function draw() {
background(0);
imageMode(CORNER);
for(var i=0; i<labyrinth.length; i++) {
labyrinth[i].show();
if (labyrinth[i].survol(mouseX, mouseY) &&
mouseY < height &&
mouseIsPressed &&
non_modifiable != i ) {
labyrinth[i].onOff();
reload = true;
non_modifiable = i;
wait = 60;
}
}
if(frameCount%30 == 0) {reload = true;}
if (reload) {loadPixels();}
reload = false;
imageMode(CENTER);
if (frameCount%20 == 0 & mesBoules.length < 100) {
mesBoules.push(new Boule(int(random(2))));
}
for(var i=0; i<mesBoules.length; i++) {
mesBoules[i].show();
}
}
function Couloir(num) {
this.nbImgPerLine = 30;
this.size = img[0].width;
this.x = num%this.nbImgPerLine * this.size;
this.y = int(num/this.nbImgPerLine) * this.size;
this.on = false;//int(num/this.nbImgPerLine)%2 == 0;
this.index = 0;
this.show = function(xM, yM) {
image(img[this.on ? 0 : 1], this.x, this.y);
// if(int(random(5000)) == 0) {
// this.onOff();
// }
}
this.survol = function(xM, yM) {
return xM > this.x &
xM <= this.x+this.size &
yM > this.y &
yM <= this.y+this.size;
}
this.onOff = function() {
this.on = !this.on;
}
}
function Boule(coul) {
this.centre;
this.ble;
this.val;
if (coul == 0) {
this.centre = createVector(int(random(4)+20)*20+19,0);
this.val = 0
this.ble = bouleNoire;
}
else {
this.centre = createVector(int(random(4)+20)*20+9,0);
this.val = 255
this.ble = bouleJaune;
}
this.show = function() {
this.testDroit = pixels[4*((this.centre.y+3)*width+this.centre.x+2)] == this.val;
this.testGauche = pixels[4*((this.centre.y+3)*width+this.centre.x-2)] == this.val;
if (this.testDroit && !this.testGauche) {this.centre.x--;}
if (this.testGauche && !this.testDroit) {this.centre.x++;}
if (this.testGauche && this.testDroit) {vitesse.y = 0;}
else {vitesse.y = 1;}
this.centre.add(vitesse);
for (var i=mesBoules.length-1; i >= 0; i--) {
this.element = mesBoules[i];
this.distance = this.centre.dist(this.element.centre);
if (this.distance < 6 &&
this.distance != 0.0 &&
this.centre.y <= this.element.centre.y
) {
this.target = p5.Vector.sub(this.centre, this.element.centre);
this.target.setMag(6);
this.target.add(this.element.centre);
this.centre.set(round(this.target.x), round(this.target.y));
}
}
image(this.ble, this.centre.x, this.centre.y);
}
}Hors ligne
Trop bien !!
Hors ligne
Superbe !
Hors ligne
trop bien aussi
Hors ligne
Ca sert à quoi ? ![]()
Hors ligne
- Bonjour Codelab,
- je me sens très heureuse de pouvoir vous parler un peu :
- ! e n f i n vous dire :
- m a g n i f i q u e !
- m a g i q u e !
- tous vos formidables projets ! ![]()
- Merci
A bientôt
Dernière modification par Mona-Lou (2016-06-06 15:07:05)
Hors ligne