Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function() {
- var baseR = 31;
- var r = [baseR*2.657, baseR*1.815, baseR];
- var colors = [154, 180, 200];
- var center = {x:150, y:150};
- var polar2cart = function(theta, r, shift){
- return {x: r*Math.cos(theta)+shift.x, y: r*Math.sin(theta)+shift.y };
- };
- var redraw = function() {
- d3.select
- var date = new Date();
- var s = date.getSeconds();
- var m = date.getMinutes() + s/60;
- var h = date.getHours()%12 + m/60;
- to3.selectAll('#kol').remove();
- // akrep
- theta = 2*Math.PI*(h-3)/12;
- start = polar2cart(theta, 0, center);
- end = polar2cart(theta, r[2], center);
- to3.append('line')
- .attr('id', 'kol')
- .attr('x1', start.x)
- .attr('y1', start.y)
- .attr('x2', end.x)
- .attr('y2', end.y)
- .attr('stroke', "black")
- .attr('stroke-width', 2);
- // yelkovan
- theta = 2*Math.PI*(m-15)/60;
- start = polar2cart(theta, r[2], center);
- end = polar2cart(theta, r[1], center);
- to3.append('line')
- .attr('id', 'kol')
- .attr('x1', start.x)
- .attr('y1', start.y)
- .attr('x2', end.x)
- .attr('y2', end.y)
- .attr('stroke', "black")
- .attr('stroke-width', 2);
- }
- var to3 = d3.select('svg');
- // circles
- to3.selectAll('circle')
- .data(r)
- .enter().append('circle')
- .attr('r', function(d) {
- return d;
- })
- .attr('cx', center.x)
- .attr('cy', center.y)
- .style('fill', function(d, i) {
- return 'hsl(0,0%,'+(colors[i]*100/255.0).toString()+'%)';
- });
- // hour ticks
- for (var i=0; i!=12; i++)
- {
- var theta = 2*Math.PI*i/12.0;
- start = polar2cart(theta, r[1], center);
- end = polar2cart(theta, r[0], center);
- to3.append('line')
- .attr('x1', start.x)
- .attr('y1', start.y)
- .attr('x2', end.x)
- .attr('y2', end.y)
- .attr('stroke', 'hsl(0,0%,75%)')
- .attr('stroke-width', 1);
- }
- redraw();
- setInterval(redraw, 1000);
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement