-
Notifications
You must be signed in to change notification settings - Fork 0
/
clock_b3.html
159 lines (131 loc) · 5.27 KB
/
clock_b3.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Clock</title>
<link rel="stylesheet" href="style.css">
<script type="text/javascript" src="lib/paper.js"></script>
<script type="text/paperscript" canvas="canvas">
var alarms = new Array();
var centre_radius = 10;
var hour_radius = 50;
var min_radius = 30;
var sec_radius = 10;
// create background
var bg = new Path.Rectangle(new Point(0,0),new Size(view.bounds.width,view.bounds.height));
bg.fillColor = '#000000';
// create centre of clock
var circle_centre = new Path.Circle(new Point(0,0), centre_radius);
circle_centre.strokeColor = '#ffffff';
circle_centre.strokeWidth = 3.0;
// create hour 'hand'
var circle_hour = new Path.Circle(new Point(0,0), hour_radius);
circle_hour.strokeColor = '#ffffff';
circle_hour.fillColor = '#ffffff';
var group_hour = new Group(circle_hour); //,text_hour);
var text_hour = new PointText(new Point(0,0));
text_hour.fontSize = hour_radius;
text_hour.font = "American Typewriter, Courier, typewriter";
text_hour.justification = "center";
text_hour.fillColor = "#000000";
// create minutes 'hand'
var circle_min = new Path.Circle(new Point(0,0), min_radius);
circle_min.strokeColor = '#ffffff';
circle_min.fillColor = '#ffffff';
var group_min = new Group(circle_min); //,text_min);
var text_min = new PointText(new Point(100,50));
text_min.fontSize = min_radius;
text_min.font = "American Typewriter, Courier, typewriter";
text_min.justification = 'center';
text_min.fillColor = '#000000';
// create seconds 'hand'
var circle_sec = new Path.Circle(new Point(0,0), sec_radius);
circle_sec.strokeColor = '#ffffff';
circle_sec.fillColor = '#ffffff';
var group_sec = new Group(circle_sec);
var text_sec = new PointText(new Point(0,0));
text_sec.fontSize = sec_radius;
text_sec.font = "American Typewriter, Courier, typewriter";
text_sec.justification = 'center';
text_sec.fillColor = '#000000';
var debug = new PointText(new Point(100,100));
debug.fillColor = '#ff0000';
//debug.content = "hello";
var nowDate = new Date();
addAlarm( new Date(79,5,24,6,45,0) );
addAlarm( new Date(79,5,24,nowDate.getHours(),nowDate.getMinutes()+2,0) );
function onFrame(event) {
var d = new Date();
positionHands(d,group_hour,group_min,group_sec,text_hour,text_min,text_sec);
}
function positionHands(d,g_hour,g_min,g_sec,t_hour,t_min,t_sec){
var time_hour = d.getHours() % 12;
var time_min = d.getMinutes();
var time_sec = d.getSeconds();
var perc_milli = d.getMilliseconds() / 1000;
var perc_sec = (time_sec+perc_milli)/60;
var perc_min = (time_min+perc_sec)/60;
var perc_hour = (time_hour+perc_min)/12;
var angle_hour = (perc_hour*(2*Math.PI))-(Math.PI/2.0);
var angle_min = (perc_min*(2*Math.PI))-(Math.PI/2.0);
var angle_sec = (perc_sec*(2*Math.PI))-(Math.PI/2.0);
positionItem(g_hour, view.center, angle_hour, centre_radius+hour_radius);
positionItem(g_min, g_hour.position, angle_min, hour_radius+min_radius+(sec_radius*2));
positionItem(g_sec, g_min.position, angle_sec, min_radius+sec_radius);
// looks a bit shite, as the text wobbles around (doesn't appear to be subpixel)
//text_hour.content = time_hour; //Math.round(angle_hour*10)/10;
//text_min.content = time_min; //Math.round(angle_min*10)/10;
//text_sec.content = time_sec; //Math.round(angle_sec*10)/10;
if (t_hour != undefined){
var angle_txt_hour = ((time_hour/12)*(2*Math.PI))-(Math.PI/2.0);
positionItem(t_hour, view.center, angle_txt_hour, centre_radius+hour_radius);
t_hour.content = time_hour;
}
if (t_min != undefined){
var angle_txt_min = ((time_min/60)*(2*Math.PI))-(Math.PI/2.0);
positionItem(t_min, g_hour.position, angle_txt_min, hour_radius+min_radius+(sec_radius*2));
t_min.content = time_min;
}
if (t_sec != undefined){
var angle_txt_sec = ((time_sec/60)*(2*Math.PI))-(Math.PI/2.0);
positionItem(t_sec, g_min.position, angle_txt_sec, min_radius+sec_radius);
t_sec.content = time_sec;
}
}
function onResize(){
circle_centre.position = view.center;
bg.bounds = view.bounds;
moveAlarms();
}
function positionItem(item, anchor, angle, distance){
var xp = anchor.x + Math.cos(angle)*distance;
var yp = anchor.y + Math.sin(angle)*distance;
//debug.content = angle + "\n"+ Math.round(xp) + "\n" + yp;
item.position = new Point( xp, yp );
}
function addAlarm(d){
var radius_border = 3.0;
var c_hour = new Path.Circle(new Point(0,0), hour_radius+radius_border);
c_hour.strokeColor = '#ff0000';
c_hour.strokeWidth = 0.5;
var c_min = new Path.Circle(new Point(0,0), min_radius+radius_border);
c_min.strokeColor = '#ff0000';
c_min.strokeWidth = 0.5;
var c_sec = new Path.Circle(new Point(0,0), sec_radius+radius_border);
c_sec.strokeColor = '#ff0000';
c_sec.strokeWidth = 0.5;
positionHands(d,c_hour,c_min,c_sec);
alarms.push({date:d,hour:c_hour,min:c_min,sec:c_sec});
}
function moveAlarms(){
for(var i=0;i<alarms.length;i++){
var alarm = alarms[i];
positionHands(alarm['date'],alarm['hour'],alarm['min'],alarm['sec']);
}
}
</script>
</head>
<body>
<canvas id="canvas" resize></canvas>
</body>
</html>