Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $( document ).ready(function() {
  2.     $("body").append($("<button id='btn'>play</button>"));
  3.     $("body").append("<canvas id='cnv'></canvas>");
  4.     var canvas = $("#cnv")[0];
  5.     canvas.width = 800 //document.width is obsolete
  6.     canvas.height = 800 //document.height is obsolete
  7.    // canvasW = canvas.width;
  8.    // canvasH = canvas.height;
  9.     $("#btn").click(play);
  10.    
  11. });
  12.  
  13. function loadTimer()
  14. {
  15.     $("#timers").append(createTimer());
  16. }
  17.  
  18. function createTimer()
  19. {
  20.     var timer = "<div class='timer'>End: <input type='text'><button>delete</button></div>";
  21.     return timer;
  22. }
  23.  
  24. function play()
  25. {
  26.     var timer = setInterval(timerFunction, 1000);
  27. }
  28.  
  29. function drawCircle(x,y)
  30. {
  31.     var canvas = $("#cnv")[0];
  32.     var ctx = canvas.getContext('2d');
  33.     ctx.beginPath();
  34.     ctx.arc(x,y,50,0,2*Math.PI);
  35.     ctx.fill();
  36. }
  37.  
  38. function timerFunction()
  39. {
  40.     var width = document.body.clientWidth;
  41.     height = document.body.clientHeight;
  42.     var x = getRandomInt(0, 800);
  43.     var y = getRandomInt(0, 800);
  44.     drawCircle(x,y);
  45. }
  46.  
  47. function getRandomInt(min, max) {
  48.     var value = Math.floor(Math.random() * (max - min + 1)) + min;
  49.     if (value + 50 > 800)
  50.         value -= 800-50;
  51.     return value;
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement