Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. poles(20); // this number is the x position at which the line (pole) will be generated
  2. ctx.clearRect(0, 0, WIDTH, HEIGHT);
  3. poles(140)
  4.  
  5. poles(20);
  6. ctx.clearRect(0, 0, WIDTH, HEIGHT);
  7.  
  8. poles(20);
  9. ctx.clearRect(0, 0, WIDTH, HEIGHT);
  10. setTimeout(function () {
  11. poles(140)
  12. }, 1000);
  13.  
  14. function poles(x) {
  15. var bottomH = getRandomInt(20, 180)
  16. // using seperate rectangles will make a break
  17. rect(40, 220 - bottomH, x, 0); // first section of line
  18. rect(40, bottomH, x, HEIGHT - bottomH); // second section of line
  19. }
  20.  
  21. var canvas = document.getElementById("canvas"),
  22. WIDTH = canvas.width,
  23. HEIGHT = canvas.height;
  24. var ctx = canvas.getContext("2d");
  25.  
  26. function getRandomInt(min, max) {
  27. return Math.floor(Math.random() * (max - min + 1)) + min;
  28. }
  29.  
  30. function rect(w, h, x, y) {
  31. ctx.rect(x, y, w, h);
  32. ctx.fill();
  33. }
  34.  
  35. function poles(x) {
  36. var bottomH = getRandomInt(20, 180); // determine where the line break will be
  37. rect(40, 220 - bottomH, x, 0);
  38. rect(40, bottomH, x, HEIGHT - bottomH);
  39. }
  40.  
  41. poles(20);
  42. ctx.clearRect(0, 0, WIDTH, HEIGHT);
  43. setTimeout(function () {
  44. poles(140)
  45. }, 1000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement