MrThoe

KittyCode

Oct 7th, 2020
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. /** My First Class
  2. *
  3. * This is abouts cats
  4. * @Author: Allen Thoe
  5. */
  6.  
  7. var myKitty;
  8. var yourKitty;
  9.  
  10. function setup() {
  11. createCanvas(400, 400);
  12. myKitty = new Cat();
  13. yourKitty = new Cat();
  14. }
  15.  
  16. function draw() {
  17. background(220);
  18. myKitty.show();
  19. yourKitty.show();
  20. }
  21.  
  22. function mousePressed(){
  23. myKitty.eats();
  24. }
  25.  
  26. /* This class will have red color and age*/
  27. class Cat{
  28. constructor(){
  29. this.red = random(255); //RED
  30. this.blue = random(255);
  31. this.age = 0;
  32. this.x = random(width);
  33. this.y = random(height);
  34. }
  35. eats(){
  36. this.age += 1;
  37. }
  38. show(){
  39. fill(this.red, 0, this.blue);
  40. rect(this.x, this.y, 20, 20);
  41. fill(0);
  42. text("MY AGE: " + this.age, this.x +40, this.y+10);
  43. }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment