Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** My First Class
- *
- * This is abouts cats
- * @Author: Allen Thoe
- */
- var myKitty;
- var yourKitty;
- function setup() {
- createCanvas(400, 400);
- myKitty = new Cat();
- yourKitty = new Cat();
- }
- function draw() {
- background(220);
- myKitty.show();
- yourKitty.show();
- }
- function mousePressed(){
- myKitty.eats();
- }
- /* This class will have red color and age*/
- class Cat{
- constructor(){
- this.red = random(255); //RED
- this.blue = random(255);
- this.age = 0;
- this.x = random(width);
- this.y = random(height);
- }
- eats(){
- this.age += 1;
- }
- show(){
- fill(this.red, 0, this.blue);
- rect(this.x, this.y, 20, 20);
- fill(0);
- text("MY AGE: " + this.age, this.x +40, this.y+10);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment