<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>canvas 倒数计时</title>
</head>
<body>
<canvas id="canvas" style="margin-left:200px; margin-top:120px" height="500" width="700"></canvas>
<script>
var HEIGHT = 500;
var WIDTH = 700;
var r = 4;
var R = 5;
var MARGIN_TOP = 30;
var MARGIN_LEFT = 20;
window.onload = function () {
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
canvas.height = HEIGHT;
canvas.width = WIDTH;
var digit =
[
[
[0, 0, 1, 1, 1, 0, 0],
[0, 1, 1, 0, 1, 1, 0],
[1, 1, 0, 0, 0, 1, 1],
[1, 1, 0, 0, 0, 1, 1],
[1, 1, 0, 0, 0, 1, 1],
[1, 1, 0, 0, 0, 1, 1],
[1, 1, 0, 0, 0, 1, 1],
[1, 1, 0, 0, 0, 1, 1],
[0, 1, 1, 0, 1, 1, 0],
[0, 0, 1, 1, 1, 0, 0]
],//0
[
[0, 0, 0, 1, 1, 0, 0],
[0, 1, 1, 1, 1, 0, 0],
[0, 0, 0, 1, 1, 0, 0],
[0, 0, 0, 1, 1, 0, 0],
[0, 0, 0, 1, 1, 0, 0],
[0, 0, 0, 1, 1, 0, 0],
[0, 0, 0, 1, 1, 0, 0],
[0, 0, 0, 1, 1, 0, 0],
[0, 0, 0, 1, 1, 0, 0],
[1, 1, 1, 1, 1, 1, 1]
],//1
[
[0, 1, 1, 1, 1, 1, 0],
[1, 1, 0, 0, 0, 1, 1],
[0, 0, 0, 0, 0, 1, 1],
[0, 0, 0, 0, 1, 1, 0],
[0, 0, 0, 1, 1, 0, 0],
[0, 0, 1, 1, 0, 0, 0],
[0, 1, 1, 0, 0, 0, 0],
[1, 1, 0, 0, 0, 0, 0],
[1, 1, 0, 0, 0, 1, 1],
[1, 1, 1, 1, 1, 1, 1]
],//2
[
[1, 1, 1, 1, 1, 1, 1],
[0, 0, 0, 0, 0, 1, 1],
[0, 0, 0, 0, 1, 1, 0],
[0, 0, 0, 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],
[0, 0, 1, 1, 0, 0, 0]
],//7
[
[0, 1, 1, 1, 1, 1, 0],
[1, 1, 0, 0, 0, 1, 1],
[1, 1, 0, 0, 0, 1, 1],
[1, 1, 0, 0, 0, 1, 1],
[0, 1, 1, 1, 1, 1, 0],
[1, 1, 0, 0, 0, 1, 1],
[1, 1, 0, 0, 0, 1, 1],
[1, 1, 0, 0, 0, 1, 1],
[1, 1, 0, 0, 0, 1, 1],
[0, 1, 1, 1, 1, 1, 0]
],//8
[
[0, 1, 1, 1, 1, 1, 0],
[1, 1, 0, 0, 0, 1, 1],
[1, 1, 0, 0, 0, 1, 1],
[1, 1, 0, 0, 0, 1, 1],
[0, 1, 1, 1, 0, 1, 1],
[0, 0, 0, 0, 0, 1, 1],
[0, 0, 0, 0, 0, 1, 1],
[0, 0, 0, 0, 1, 1, 0],
[0, 0, 0, 1, 1, 0, 0],
[0, 1, 1, 0, 0, 0, 0]
],//9
[
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 1, 1, 0],
[0, 1, 1, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 1, 1, 0],
[0, 1, 1, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]
]//:
];
var colors = ["#def", "#FF8DB5", "#79D3FB", "#EE941B", "#4CB849"];
// 倒计时两分钟
var minutes = 2;
var seconds = 0;
var countTimes=2*60; // 所需倒计时的次数
paint(context,minutes,seconds,countTimes);
function paint(context, minutes, seconds,countTimes) {
console.log(minutes,seconds,'---------paint()-----------')
drawNum(Math.floor(minutes / 10), context, r, R, MARGIN_LEFT, MARGIN_TOP);
drawNum(minutes % 10, context, r, R, 110 + MARGIN_LEFT, MARGIN_TOP);
drawColon((digit.length) - 1, context, r, R, 220 + MARGIN_LEFT, MARGIN_TOP); // 画冒号
drawNum(Math.floor(seconds / 10), context, r, R, 330 + MARGIN_LEFT, MARGIN_TOP);
drawNum(seconds % 10, context, r, R, 440 + MARGIN_LEFT, MARGIN_TOP);
function drawNum(number, context, r, R, MARGIN_LEFT, MARGIN_TOP) {
for (var i = 0; i < digit[0].length; i++) {
for (var j = 0; j < digit[0][0].length; j++) {
if (digit[number][i][j] == 1) {
context.beginPath();
context.arc((2 * R * j + r * j) + MARGIN_LEFT, (2 * R * i + r * i) + MARGIN_TOP, r, 0, 2 * Math.PI, false);
//context.fillStyle = "#ade";
var color = Math.ceil(Math.random() * (4 - 0) + 0);
context.fillStyle = colors[color];
context.fill();
context.closePath();
}
}
}
}
function drawColon(number, context, r, R, MARGIN_LEFT, MARGIN_TOP) {
Gss__
- 粉丝: 17
- 资源: 2
最新资源
- 每周三白嫖古茗?进来看!内含百发百中教程!.mp4
- 美团2024年查看年度消费报告.mp4
- 入校申报审批-JAVA-基于springBoot入校申报审批系统的设计与实现(毕业论文)
- 美团领10亓网吧和台球团购券.mp4
- 免费PDF转换和编辑工具 PDFgear v2.1.10.mp4
- 免费领取咪咕NBA联盟通7天会员.mp4
- 免费的音乐播放器,支持本地和网络歌曲播放.mp4
- 免费录屏直播工具OBS Studio v31.0.0官方版.mp4
- 免费领取咪咕NBA联盟通7天会员活动.mp4
- 计算机学院校友网-JAVA-基于springBoot计算机学院校友网设计与实现(毕业论文)
- 免费网络验证一键加密.mp4
- 模拟来电 1.0 自定义设置来电电话.mp4
- 某宝100大洋的Java架构-黑马-Java架构师实战训练营(第4期).mp4
- 魔力自动点击器 1.4.24 自动点击器.mp4
- 内存清理工具 ReduceMemory v1.7排除线程.mp4
- 拿捏GPT,无需付费,终身Pro会员!.mp4
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈