xxxxxxxxxx
54
class textform{//class decleration
constructor(tempX,tempY,tempspeedX=random(0,5),tempspeedY=random(0,5),a=random(0,255),b=random(0,255),c=random(0,255)){//constructor that has random initial values for some situations
this.x = tempX;//x coordinate of the object to be created
this.y = tempY;//y coordinate of the object to be created
this.xspeed = tempspeedX;//if user enters the speed through the x-axis, set the speed of the object to this speed.
this.yspeed = tempspeedY; //if user enters the speed through the y-axis, set the speed of the object to this speed.
this.a=a;//if the user enters the value for red in rgb, set red of this object withthis value
this.b=b;//if the user enters the value for green in rgb, set green of this object withthis value
this.c=c;//if the user enters the value for blue in rgb, set blue of this object withthis value
this.happytext=['Strong','Good','Cool','Chill','Amazing','Wonderful','Beautiful','Funny','Special','Awesome','Brave','Courageous','Delightful'];//Array of text that the objects will take form of
this.arrlen=int(random(0,this.happytext.length-1));//getting the array length
}
move() {//function to move the object
this.x +=this.xspeed;//increase or decrease the x-coordinate
this.y += this.yspeed;//increase or decrease the x-coordinate
}
display() {//function to show the object on the canvas
if(this.x>width-120||this.y<20||this.y>height-5){
return;//if the person clicks on an area that will cause bugs, do not display
}
stroke(random(0,255));//change the stroke color to create a flashy look
rectMode(CENTER)//set the text to center
fill(this.a, this.b, this.c,random(0,255));//fill the objects with a color
textSize(40);//set the Size of the text to 40
text(this.happytext[this.arrlen],this.x, this.y);// draw and display a text
}
bounce() {//function to bounce the object
if (this.x > width-120 || this.x < 0) {//settiing boundaries
this.xspeed = this.xspeed * -1;//change increament of the x-coordinate to a decreament value
this.colorChange();//change color
}
if (this.y > height-5 || this.y < 20) {//settiing boundaries
this.yspeed = this.yspeed * -1;//change increament of the x-coordinate to a decreament value
this.colorChange();//change colour
}
}
colorChange(){
this.a=random(0,255);//changing red value with a random number
this.b=random(0,255);//changing red value with a random number
this.b=random(0,255);//changing red value with a random number
}
intro(){//creating the intro object
fill(0,0,255,random(0,255));//cause a flashy look using opacity
stroke(255);//setting outline of text to white
strokeWeight(2);//setting outline thickness to 2
textSize(50);//setting text size to 50
text('You Are :',200,200);//display the text for the intro.
}
}