xxxxxxxxxx
70
// thanks coding train for this lesson
//I want to modify the way i create an object. and the way taht i do that is adding
//stuff in newBubble(); in set up. I add arguements to the constructor
//just liek passing arguemtns to a function, you can pass arguemtns to a constructor
//i want the constructor to receive those arguements , so if you are giving it 3
//arguemtns you need to define it with 3 parameters.
// the argeuments are the things that are passed in,
//the parameters are the variables that go inside the actual definition of the function
//in this case a constructor
// the variabels inside the constructor are temperary local variables just for the
//sole purpose of recieving the value and quickly passing it to the variable that
//matters (this.x) is what counts, its how you keep track of where to draw it and how
//to move it
let bubble1 ;
let bubble2
function setup() {
createCanvas(600, 400);
bubble1 = new Bubble(200,200,40,40,200,255);
bubble2 = new Bubble(400,300,20,30,54,100);
}
function draw() {
background(220);
bubble1.show();
bubble1.move();
bubble2.show();
bubble2.move();
bubble1.randomcolors();
bubble2.randomcolors();
}
class Bubble{
constructor(x,y,r,red, g,b){
this.x =x;
this.y= y;
this.r= r;
this.red =red;
this.g=g;
this.b= b;
}
move(){
this.x= this.x+random(-5,5);
this.y= this.y +random (-5,5);
}
show(){
stroke(255);
strokeWeight(4);
fill(this.red,this.g, this.b);
ellipse( this.x, this.y, this.r*2);
}
randomcolors(){
this.red = (random(0,255));
this.g = (random(0.255));
}
}