Advertisement
476179

8.1Act4fish

Dec 11th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1.  
  2. <!DOCTYPE html>
  3. <html lang="en">
  4.  
  5. <head>
  6. <meta charset="utf-8">
  7. <title>flowers</title>
  8. </head>
  9. <canvas id="canvas1" width="640" height="480" style="border: 1px solid black;
  10. position: absolute; left: 0; top: 0; z-index: 0;"></canvas>
  11. <canvas id="canvas2" width="640" height="480" style="border: 1px solid black;
  12. position: absolute; left: 0; top: 0; z-index: 1;"></canvas>
  13. <body>
  14.  
  15. <script>
  16.  
  17. var layer1 = document.getElementById("canvas1");
  18. var dt1 = layer1.getContext("2d");
  19. var layer2 = document.getElementById("canvas2");
  20. var dt2 = layer2.getContext("2d");
  21.  
  22.  
  23. // Draw water.
  24. dt1.fillStyle = "#99ffff"
  25. dt1.fillRect(0, 0, 640, 350);
  26.  
  27. //Draw the sand.
  28. dt1.fillStyle = "#ffcc99";
  29. dt1.fillRect(0, 300, 640, 180);
  30.  
  31. //call the "runFunc" when mouse is clicked
  32. document,addEventListener("click",runFunc);
  33.  
  34. function runFunc()
  35. {
  36. dt2.clearRect(0,0,canvas2.width,canvas2.height);
  37. for (var i = 1; i<=200;i++)
  38. {
  39. //flower(Math.ceil(Math.random()*canvas2.width),Math.floor(Math.random()*canvas2.height),"#663399")
  40. flower(Math.ceil(Math.random()*640),Math.floor(Math.random()*480),randomColour())
  41. }
  42. }
  43.  
  44.  
  45.  
  46.  
  47. function flower(xPos, yPos, colour)
  48. {
  49. // Draw the stem.
  50. dt2.strokeStyle = "#ff9900";
  51. dt2.lineWidth = 3;
  52. dt2.beginPath();
  53. dt2.strokeRect(xPos,yPos,30,50)
  54. dt2.fillRect();
  55.  
  56. // Draw petal in specified colour.
  57. dt2.fillStyle = colour;
  58. dt2.beginPath();
  59. dt2.arc(xPos, yPos, 15, 0, 2*Math.PI);
  60. dt2.fill();
  61.  
  62. // Draw yellow stamen.
  63. dt2.fillStyle = "#FFFF71";
  64. dt2.beginPath();
  65. dt2.arc(xPos, yPos, 10, 0, 2*Math.PI);
  66. dt2.fill();
  67. }
  68.  
  69. function randomColour()
  70. {
  71. red = Math.floor(Math.random()*255)+1;
  72. green = Math.floor(Math.random()*255)+1;
  73. blue = Math.floor(Math.random()*255)+1;
  74.  
  75. return "rgb("+red+","+green+","+blue+")";
  76. }
  77.  
  78. </script>
  79.  
  80. </body>
  81. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement