fork download
  1. //1)Style tag goes in header
  2. <style>
  3. canvas{ border: 1px solid black; }
  4.  
  5. </style>
  6.  
  7. //2)Add following to body tag
  8.  
  9. <canvas id="myCanvas" ></canvas>
  10.  
  11. //3)add following to top of Script tag
  12.  
  13. var canvas = document.getElementById("myCanvas");
  14. var ctx = canvas.getContext("2d");
  15. ctx.canvas.width = 500;
  16. ctx.canvas.height = 250;
  17.  
  18. //4) add following to script tag
  19. function draw() {
  20. ctx.clearRect(0, 0, canvas.width, canvas.height);
  21. ctx.fillStyle = "gray";
  22. ctx.fillRect(0, 0, canvas.width, canvas.height);
  23.  
  24. }
  25.  
  26. //5 controls speed of animation - smaller number the faster
  27. setInterval(draw, 10);
  28.  
  29.  
  30. //6) draw Circle to screen
  31. ctx.beginPath();
  32. ctx.arc(100, 100, 40, 0, Math.PI*2, false);//40 is the size
  33. ctx.fillStyle = "green";
  34. ctx.fill();
  35. ctx.closePath();
  36.  
  37. //END
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:2: error: class, interface, or enum expected
<style>
^
Main.java:3: error: class, interface, or enum expected
        canvas{ border: 1px solid black; }
                                         ^
Main.java:14: error: class, interface, or enum expected
    var ctx = canvas.getContext("2d");
    ^
Main.java:15: error: class, interface, or enum expected
        ctx.canvas.width  = 500;
        ^
Main.java:16: error: class, interface, or enum expected
        ctx.canvas.height = 250;
        ^
Main.java:19: error: class, interface, or enum expected
 function draw() {
 ^
Main.java:21: error: class, interface, or enum expected
             ctx.fillStyle = "gray";
             ^
Main.java:22: error: class, interface, or enum expected
            ctx.fillRect(0, 0, canvas.width, canvas.height);
            ^
Main.java:24: error: class, interface, or enum expected
}
^
Main.java:31: error: class, interface, or enum expected
        ctx.beginPath();
        ^
Main.java:32: error: class, interface, or enum expected
        ctx.arc(100, 100, 40, 0, Math.PI*2, false);//40 is the size
        ^
Main.java:33: error: class, interface, or enum expected
        ctx.fillStyle = "green";
        ^
Main.java:34: error: class, interface, or enum expected
        ctx.fill();
        ^
Main.java:35: error: class, interface, or enum expected
        ctx.closePath();
        ^
14 errors
stdout
Standard output is empty