Advertisement
Guest User

Untitled

a guest
Nov 21st, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. function circle(x,y,r) {
  2. ctx.beginPath();
  3. ctx.arc(x, y, r, 0, Math.PI*2, true);
  4. ctx.fill();
  5. }
  6.  
  7. // draws circle
  8.  
  9.  
  10.  
  11. function rect(x,y,w,h) {
  12. ctx.beginPath();
  13. ctx.rect(x,y,w,h);
  14. ctx.closePath();
  15. ctx.fill();
  16. ctx.stroke();
  17. }
  18.  
  19. function clear() {
  20. ctx.clearRect(0, 0, WIDTH, HEIGHT);
  21. }
  22.  
  23. //this draws the circle and clears it
  24.  
  25. function init() {
  26. canvas = document.getElementById("canvas");
  27. ctx = canvas.getContext("2d"); // sets drawing contex (2d) has built in functions (getContext function 2d means somethingto it
  28. return setInterval(draw, 10); // draws the screen every 10 milliseconds
  29. }
  30.  
  31.  
  32.  
  33. function draw() {
  34. clear();
  35. ctx.fillStyle = "white";
  36. ctx.strokeStyle = "black";
  37. rect(0,0,WIDTH,HEIGHT);
  38. ctx.fillStyle = "purple";
  39. circle(x, y, 10);
  40.  
  41. //draw function I use
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement