-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcanvas_photo.html
88 lines (60 loc) · 1.79 KB
/
canvas_photo.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>canvas-时钟</title>
<style>
body{background:#000;}
#c1{background:#fff;}
</style>
<script>
function d2a(n){
return n*Math.PI/180;
}
window.onload = function(){
var oC = document.getElementById("c1");
var gd = oC.getContext("2d");
var cx = 300;
var cy = 200;
setInterval(function(){
gd.clearRect(0,0,oC.width,oC.height);
var oDate = new Date();
var iH = oDate.getHours();
var iM = oDate.getMinutes();
var iS = oDate.getSeconds();
var iMs = oDate.getMilliseconds();
drawArc(cx,cy,80,0,iH%12*30 + iM/60*30,"pink");
drawArc(cx,cy,100,0,iM*6 + iS/60*6,"orange");
drawArc(cx,cy,120,0,iS*6 + iMs/1000*6,"#ccc");
var str = [iH,iM,iS].join(":");
var h = 30;
gd.font = "bold " +h + "px kaiti";
var w = gd.measureText(str).width;
gd.fillText(str,cx - w/2,cy + h/2);
},16);
function drawArc(cx,cy,r,start,end,color){
start -= 90;
end -= 90;
gd.beginPath();
gd.lineWidth = "20";
gd.strokeStyle = color;
gd.arc(cx,cy,r,d2a(start),d2a(end),false);
gd.stroke();
}
var oBtn = document.getElementById("btn1");
//var oImg = document.getElementById("img1");
oBtn.onclick = function(){
//
//var str = oC.toDataURL("image/jpeg");
//var str = oC.toDataURL("image/png");
var str = oC.toDataURL("image/gif");//不支持
window.open(str);
};
};
</script>
</head>
<body>
<input id="btn1" type="button" value="拍照" />
<canvas id="c1" width="800" height="500" ></canvas>
</body>
</html>