Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1.  
  2. //Intro to Programming - JavaScript
  3. //Fish Tank - Making a fish tank with functions.
  4.  
  5. background(89, 216, 255);
  6.  
  7. var centerX = 200;
  8. var centerY = 100;
  9. var bodyLength = 118;
  10. var bodyHeight = 74;
  11. var bodyColor = color(224, 32, 224);
  12. var greenTail = random(1,255);
  13. var blueTail = random(1,255);
  14. var tailColor = color(224,greenTail,blueTail);
  15.  
  16. var drawFish = function(centerX, centerY, bodyLength, bodyHeight, bodyColor, tailColor) {
  17. // body
  18. noStroke();
  19. fill(bodyColor);
  20. ellipse(centerX, centerY, bodyLength, bodyHeight);
  21. // tail
  22. fill(tailColor);
  23. var tailWidth = bodyLength/4;
  24. var tailHeight = bodyHeight/2;
  25. triangle(centerX-bodyLength/2, centerY,
  26. centerX-bodyLength/2-tailWidth, centerY-tailHeight,
  27. centerX-bodyLength/2-tailWidth, centerY+tailHeight);
  28. // eye
  29. fill(33, 33, 33);
  30. ellipse(centerX+bodyLength/4, centerY, bodyHeight/5, bodyHeight/5);
  31.  
  32. };
  33.  
  34. drawFish(100,100,80,30,color(255, 0, 0),color(random(0,256),random(0,255),random(0,256)));
  35. drawFish(192,182,60,10,color(255, 255, 255), color(random(0,256),random(0,255),random(0,256)));
  36. drawFish(296,100,179,125,color(34, 255, 0), color(random(0,256),random(0,255),random(0,256)));
  37. drawFish(279,211,-125,75,color(96, 0, 105), color(random(0,256),random(0,255),random(0,256)));
  38. drawFish(208,292,45,30,color(255, 0, 0), color(random(0,256),random(0,255),random(0,256)));
  39. drawFish(96,223,70,57,color(255, 204, 0), color(random(0,256),random(0,255),random(0,256)));
  40. drawFish(81,312,-154,120,color(20, 153, 0), color(random(0,256),random(0,255),random(0,256)));
  41. drawFish(328,315,107,75,color(4, 0, 105), color(random(0,256),random(0,255),random(0,256)));
  42.  
  43. //background / seaweed
  44.  
  45. //var x = 11;
  46.  
  47. var drawSeaweed = function (x) {
  48. strokeWeight(5);
  49. stroke(0, 105, 0);
  50. fill(64, 255, 0);
  51. ellipse(x+25,363,54,225);
  52. ellipse(x+39,417,54,225);
  53. ellipse(x+12,440,54,225);
  54. ellipse(x+73,426,54,225);
  55. };
  56. drawSeaweed(10);
  57. drawSeaweed(143);
  58. drawSeaweed(279);
  59.  
  60. mouseClicked = function() {
  61. drawFish(mouseX,mouseY,random(20,100),random(10,100), color(random(0,256),random(0,255),random(0,256)),color(random(0,256),random(0,256),random(0,256)));
  62. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement