<html lang="en"> <head> </head> <body> <h2>How to draw Rectangle?</h2> <p> Before dreaming about creating an interactive HTML5 games, let's start with the basic. </p> <canvas id="c1" width="200" height="200" style="border:solid 1px #000000;"></canvas> <br /> <button onclick="draw_square();">Red Square</button> <script> // setInterval("draw_square()",100); var n=0; function draw_square() { var c1 = document.getElementById("c1"); var c1_context = c1.getContext("2d"); if (n==0) c1_context.fillStyle = "red"; else if (n==1) c1_context.fillStyle = "green"; else c1_context.fillStyle = "yellow"; n=(n+1)%3; c1_context.fillRect(50, 50, 100, 100); } </script> </body>
Before dreaming about creating an interactive HTML5 games, let's start with the basic.