HTML5-Canvas plotting and animation of dazzling clock Effects

Source: Internet
Author: User

HTML5-Canvas plotting and animation of dazzling clock Effects

<Script type = "text/javascript" src = "digit. js "> </script> <script type =" text/javascript "> var WINDOW_WIDTH = 1024; var WINDOW_HEIGHT = 600; var MARGIN_TOP = 60; var MARGIN_LEFT = 30; // store the color ball var bils = []; const colors = ["#33B5E5", "# 0099CC", "# AA66CC", "#669900", "# FFBB33 ", "# FF8800", "# FF4444", "CC0000"]; var digit = [[[, 0], [,], [, 1], [, 1], [, 1], [, 1], [1, 1, 0, 0, 0 ,], [, 1], [,], [, 0], // 0 [[, 0], [, 0], [, 0,, 0], [, 0], [, 0], [, 0,, 0], [, 0], [, 1], // 1 [[, 0], [, 1], [, 1], [, 0], [, 0], [, 0], [, 0], [, 0], [, 1], [, 1], // 2 [, 1, ], [, 1], [,], [, 0, 0], [, 0], [, 1], [, 1, 1], [, 0], // 3 [[, 0], [,], [, 0], [,], [,], [, 1],, 1], // 4 [[, 1], [, 0], [, 0, 0], [, 0], [, 1], [, 1], [, 1], [, 1], [, 1], [, 0], // 5 [[, 0], [, 0, 0, 0, 0], [, 0, 0], [, 0], [, 1], [, 0,, 1], [, 1], [, 1], [, 0], // 6 [[, 1], [, 1,, 0], [, 0], [, 0], [, 0,, 0], [, 0], [, 1, ,], // 7 [[, 0], [, 1], [, 1], [, 1], [,], [, 1], [, 1], [, 1], [, 1], [,], // 8,, 0], [, 1], [, 1], [, 1, 0, 1], [0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 1], [0, 0, 0, 0], [0, 0,, 0], [, 0], // 9 [[,], [,], [,], [,], [,], [, 0, 0], [,], [,], [,], [,] //:]; var r = 8; // circle radius window. onload = function () {var canvas = document. getElementById ("canvas"); var context = canvas. getContext ("2d"); canvas. width = WINDOW_WIDTH; canvas. height = WINDOW_HEIGHT; window. setInterval (function () {var curr = new Date (); var curHours = curr. getHours (); var curMinutes = curr. getMinutes (); var curSeconds = curr. getSeconds (); // Add the color ball if (preSeconds! = CurSeconds) {if (parseInt (curHours/10 )! = ParseInt (preHours/10) {addBall (MARGIN_LEFT, MARGIN_TOP, parseInt (curHours/10);} if (parseInt (curHours % 10 )! = ParseInt (preHours % 10) {addBall (MARGIN_LEFT + 15 * (r + 1), MARGIN_TOP, parseInt (curHours % 10 ));} if (parseInt (curMinutes/10 )! = ParseInt (preMinutes/10) {addBall (MARGIN_LEFT + 39 * (r + 1), MARGIN_TOP, parseInt (curMinutes/10 ));} if (parseInt (curMinutes % 10 )! = ParseInt (preMinutes % 10) {addBall (MARGIN_LEFT + 54 * (r + 1), MARGIN_TOP, parseInt (curMinutes % 10 ));} if (parseInt (curSeconds/10 )! = ParseInt (preSeconds/10) {addBall (MARGIN_LEFT + 78 * (r + 1), MARGIN_TOP, parseInt (curSeconds/10 ));} if (parseInt (curSeconds % 10 )! = ParseInt (preSeconds % 10) {addBall (MARGIN_LEFT + 93 * (r + 1), MARGIN_TOP, parseInt (curSeconds % 10);} render (context );}, 50);} // Add the ball (color ball on the numeric num, x, y: vertex coordinate in the upper left corner of the digital box container) function addBall (x, y, num) {for (var I = 0; I = WINDOW_HEIGHT) {bils [I]. y = WINDOW_HEIGHT-r; bils [I]. vy =-bils [I]. vy * 0.6 ;}}var preHours; var preMinutes; var preSeconds; // render the entire canvas function render (context) {context. clearRect (0, 0, WINDOW_WIDTH, WINDOW_HEIGHT) var now = new Date (); var hours = now. getHours (); var minutes = now. getMinutes (); var seconds = now. getSeconds (); preHours = hours; preMinutes = minutes; preSeconds = seconds; // --- renderDigit (MARGIN_LEFT, MARGIN_TOP, parseInt (hours/10), context ); renderDigit (MARGIN_LEFT + 15 * (r + 1), MARGIN_TOP, hours % 10, context); renderDigit (MARGIN_LEFT + 30 * (r + 1), MARGIN_TOP, 10, context ); // --- renderDigit (MARGIN_LEFT + 39 * (r + 1), MARGIN_TOP, parseInt (minutes/10), context); renderDigit (MARGIN_LEFT + 54 * (r + 1 ), MARGIN_TOP, minutes % 10, context); renderDigit (MARGIN_LEFT + 69 * (r + 1), MARGIN_TOP, 10, context ); // --- seconds renderDigit (MARGIN_LEFT + 78 * (r + 1), MARGIN_TOP, parseInt (seconds/10), context); renderDigit (MARGIN_LEFT + 93 * (r + 1 ), MARGIN_TOP, seconds % 10, context); // --- draw the renderbils ball (context); // --- change the ball path updatebils ();} // render each number function renderDigit (x, y, num, context) {context. fillStyle = "green"; for (var I = 0; I

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.