xxxxxxxxxx
57
var Windy = function (_x1, _y1,_x2, _y2,_x3,_y3){
this.x1 = _x1;
this.y1 = _y1;
this.x2 = _x2;
this.y2 = 400;
this.x3 = _x3;
this.y3 = _y3;
this.x1dir = random (-1,1);
this.y1dir = random (-1,1);
this.draw = function(){
triangle (this.x1, this.y1, this.x2, this.y2, this.x3, this.y2);
};
//the range of movement changes acording to the height of each triangle x1
this.sopla = function () {
if(this.x1<= 0 || this.x1>200){
this.x1dir *= -1;
}
this.x1 += this.x1dir;
};
};
//Is making a variable for each new hair a good practice?
var peloUno;
var peloDos;
var peloTres;
var peloCuatro;
var peloCinco;
var peloSeis;
function setup() {
createCanvas(400, 400);
//added this.x3 and it wont draw
peloUno = new Windy (30,75,0,50);
peloDos = new Windy (50,200,44,94);
peloTres = new Windy ();
peloCuatro = new Windy ();
peloCinco = new Windy ();
peloSeis = new Windy ();
}
function draw() {
background(220);
fill (250, 0, 170,60);
noStroke ();
peloUno.draw();
peloUno.sopla();
peloDos.draw();
peloDos.sopla();
}