xxxxxxxxxx
80
// MANTRA CLASS
// Creation d'une classe Objet Mantra qui permet de recuperer toutes les fonctions d'objet aleatoire
function Mantra(numlist) {
this.serie = numlist;
}
Mantra.prototype.getValue = function () {
var index = Math.floor(Math.random()*this.serie.length);
return this.serie[index];
};
function randomHueLike() {
var h;
do {
h = Math.floor(Math.random()*360);
} while(h>40 && h<180);
return h;
};
// Retourne une position 3D aleatoire en fonction de la liste Mantra
Mantra.prototype.getMantraPosition = function () {
var v;
// axe x
v = min(this.getValue()*2, 400);
pos_x = random(-v, v);
// axe y
v = min(this.getValue()*2, 400);
pos_y = random(-v, v);
// axe z
pos_z = -random(min(1000, this.getValue()*4));
let pos = createVector(pos_x, pos_y, pos_z);
return pos;
}
// MAIN FUNCTION
let v1;
var colorrun = '#F6E2F4'
function setup() {
createCanvas(windowWidth, windowHeight);
var mant = new Mantra([1,2,3]);
console.log(mant.getValue());
var h = randomHueLike()
console.log(h);
let v1 = mant.getMantraPosition();
console.log(v1);
//code issu du tuto sur les vector
v1 = createVector(width / 2, height / 2);
}
function draw() {
//stroke(colorrun);
if (mouseIsPressed) {
fill('#1E93EA');
} else {
fill('#62D8A0');
}
ellipse(mouseX, mouseY, 80, 80);
//line(v1.x, v1.y, mouseX, mouseY);
}
function keyPressed() {
if (keyCode === LEFT_ARROW) {
colorrun = '#FF5500';
}
else{colorrun = '#F6E2F4';
}
stroke(colorrun);
return false
}