Let's make a clock!
We are going to draw an analog clock and make it work as a real clock. In your body part of the HTML document, type the following code:
<canvas id="myclock" height="500" width="500"></canvas> In your <script></script> tags, take the following variables: Var canvas; // the clock canvas var canvasElement; // canvas's elements // clock settings var cX = 0; var cY = 0; var radius = 150;
Here, cX
and cY
are the center coordinates of our clock. We took 150 px as the clock's radius. You can increase or decrease it.
Then, we need to initialize the variables. Make an init();
function after defining the preceding variables.
The function should look similar to the following:
function init() { canvas = document.getElementById("myclock"); //Called ...
Get JavaScript Projects for Kids now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.