Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. function setup() {
  2. createCanvas(windowWidth, windowHeight);
  3. trees = new Trees(200, 200);
  4. }
  5.  
  6. class Trees {
  7. constructor(x, y) {
  8. this.x = x,
  9. this.y = y,
  10. this.a = 0
  11. }
  12. trunk() {
  13. noStroke();
  14. fill(126, 60, 1);
  15. rect(this.x + 3, this.y, 14, 40);
  16. triangle(this.x + 10, this.y + 30, this.x - 4, this.y + 40, this.x + 24, this.y + 40);
  17. }
  18. leaves() {
  19. fill(71, 215, 45);
  20. ellipse(this.x + 3, this.y - 5, 25);
  21. ellipse(this.x + 10, this.y - 15, 25);
  22. ellipse(this.x + 17, this.y - 5, 25);
  23. }
  24. shudder() {
  25. if (mouseIsPressed) {
  26. this.a = 4;
  27. if (this.x < this.x - 2 || this.x > this.x + 2) { // this won't work
  28. this.a = this.a * -1;
  29. }
  30. } else {
  31. this.a = 0;
  32. }
  33. this.x = this.x + this.a;
  34. }
  35. }
  36.  
  37. function setup() {
  38. createCanvas(windowWidth, windowHeight);
  39. trees = new Trees(200, 200, 198, 202); // not what I want
  40. }
  41.  
  42. class Trees {
  43. constructor(x, y, l, r) {
  44. this.x = x,
  45. this.y = y,
  46. this.l = l,
  47. this.r = r,
  48. this.a = 0
  49. }
  50. trunk() {
  51. noStroke();
  52. fill(126, 60, 1);
  53. rect(this.x + 3, this.y, 14, 40);
  54. triangle(this.x + 10, this.y + 30, this.x - 4, this.y + 40, this.x + 24, this.y + 40);
  55. }
  56. leaves() {
  57. fill(71, 215, 45);
  58. ellipse(this.x + 3, this.y - 5, 25);
  59. ellipse(this.x + 10, this.y - 15, 25);
  60. ellipse(this.x + 17, this.y - 5, 25);
  61. }
  62. shudder() {
  63. if (mouseIsPressed) {
  64. this.a = 4;
  65. if (this.x < this.l || this.x > this.r) {
  66. this.a = this.a * -1;
  67. }
  68. } else {
  69. this.a = 0;
  70. }
  71. this.x = this.x + this.a;
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement