Jump to content

Javascript analog clock help needed!

- - - - -

  • Please log in to reply
1 reply to this topic

#1
welton122

welton122

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
hi all,

okay i got this script off the internet for a javascript analog clock but i am having some trouble making the clock smaller.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 

<html lang="en"> 

<head> 

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 

<title>Triqui Clock</title> 

<script type="text/javascript" src="javascript/raphael-min.js"></script> 

<script type="text/javascript"> 


function draw_clock(){ 

canvas = Raphael("clock_id",200, 200); 

var clock = canvas.circle(100,100,95); 

clock.attr({"fill":"#f5f5f5","stroke":"#444444","stroke-width":"5"}) 

var hour_sign; 

for(i=0;i<12;i++){ 

var start_x = 100+Math.round(80*Math.cos(30*i*Math.PI/180)); 

var start_y = 100+Math.round(80*Math.sin(30*i*Math.PI/180)); 

var end_x = 100+Math.round(90*Math.cos(30*i*Math.PI/180)); 

var end_y = 100+Math.round(90*Math.sin(30*i*Math.PI/180)); 

hour_sign = canvas.path("M"+start_x+" "+start_y+"L"+end_x+" "+end_y); 

} 

hour_hand = canvas.path("M100 100L100 50"); 

hour_hand.attr({stroke: "#444444", "stroke-width": 6}); 

minute_hand = canvas.path("M100 100L100 40"); 

minute_hand.attr({stroke: "#444444", "stroke-width": 4}); 

second_hand = canvas.path("M100 110L100 25"); 

second_hand.attr({stroke: "#444444", "stroke-width": 2}); 

var pin = canvas.circle(100, 100, 5); 

pin.attr("fill", "#000000"); 

update_clock() 

setInterval("update_clock()",1000); 

} 


function update_clock(){ 

var now = new Date(); 

var hours = now.getHours(); 

var minutes = now.getMinutes(); 

var seconds = now.getSeconds(); 

hour_hand.rotate(30*hours+(minutes/2.5), 100, 100); 

minute_hand.rotate(6*minutes, 100, 100); 

second_hand.rotate(6*seconds, 100, 100); 


} 


</script> 


</head> 

<body> 

<div id="clock_id"></div> 

<script>draw_clock()</script> 

</body> 

</html>

can anyone help??

Thanks
J

#2
cdg10620

cdg10620

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 389 posts
You need to include the code in the raphael-min.js as well. It looks like the size is probably declared in the first two lines of the function. Have you tried making those numbers smaller?

Also, programming rule of thumb. If you are going to get stuff off the internet and then turn around to use it (which we all do from time to time), you should always make sure you know exactly what the code does before you use it. It is not recommended to just blindly use code. Just a helpful hint from a fellow programmer. :) Let me know if you need help with anything else.
-CDG10620
Software Developer




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users