Discuss Anything: Analog Clock - Discuss Anything

Jump to content


Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
Page 1 of 1

Analog Clock Rate Topic: -----

#1 User is offline   galexcd 

  • Define:EVIL PROGRAMMER (ē'vəl prō'grăm'ər)- n. An organism that converts caffeine into evil software.
  • PipPipPipPipPipPipPipPipPipPipPip
  • View gallery
  • Group: [MODERATOR]
  • Posts: 1,327
  • Joined: 25-September 05
  • Gender:Male
  • Location:Los Angeles, California
  • myCENT:33.67
  • Current Mood: Current Mood: None Chosen

Posted 09 January 2008 - 06:46 PM

ok so i was bored and was inspired by the php clock topic to make this dynamic image of an analog clock:
Posted Image



so anyway here's the source code:
<?php
/*
All images and lines of code were written/drawn from scratch by alex...
*/
header("Content-type: image/jpeg");
function newclockhand($time,$color,$length,$thickness){
global $clock;
imagefilledpolygon($clock,array(96,89,99-$thickness+cos(deg2rad($time+90)
)*2,92+$thickness+sin(deg2rad($time+90))*2,$length*cos(deg2rad(
$time))+165-$length,$length*sin(deg2rad($time))+165-$
length),3,$color);
}
$clock=imagecreatetruecolor(200,200);
$back=imagecreatefromjpeg("back.jpg");
$dot=imagecreatefromjpeg("dot.jpg");
imagecopy($clock,$back,0,0,0,0,200,200);
newclockhand(intval(date("i"))/60*360-90,imagecolorallocate($clock,
0,0,0),70,3);
newclockhand(intval(date("g"))/12*360-80+30*intval(date("i"
))/60,imagecolorallocate($clock,10,10,10),55,5);
newclockhand(intval(date("s"))/60*360-90,imagecolorallocate($clock,
255,0,0),70,1);
imagecopy($clock,$dot,97,91,0,0,6,6);
imagejpeg($clock);
imagedestroy($clock);
?>

and attached are all the images needed.

but if you refresh a bit you can tell there are a few bugs... especially with the thickness of the hands changing. I'm not that great at trig functions, I just know the basic unit circle which I used to make this, but i had to play around with some of the numbers to get it right, but I never got the thickness to work quite right. If any of you math whizzes out there want to improve my code go for it. Also changing the length of the hands affects the time sometimes so make sure you compensate for it by adding degrees within the deg2rad() function.

But other than those 2 the clock works pretty good. Have fun!

Attached File(s)

  • Attached File  back.jpg (4.01K)
    Number of downloads: 23
  • Attached File  dot.jpg (357bytes)
    Number of downloads: 11

0


Page 1 of 1

Other Replies To This Topic

#2 User is offline   kobra500 

  • Inane and Inept
  • PipPipPipPipPipPipPipPipPip
  • Group: Kontributors
  • Posts: 592
  • Joined: 08-January 08
  • Gender:Male
  • Location:UK - Kent
  • myCENT:29.45
  • Current Mood: Current Mood: None Chosen

Posted 09 January 2008 - 07:19 PM

Good enough... I'm sure they're are better ones but that one works good. Well doen
0

#3 User is offline   gogoily 

  • Member [Level 3]
  • PipPipPipPipPipPip
  • Group: Kontributors
  • Posts: 99
  • Joined: 30-October 05
  • Current Mood: Current Mood: None Chosen

Posted 10 January 2008 - 02:02 AM

This code is excellent !!
But I'd like JavaScript clock more, it's real-time and it doesn't use server resource.
0

#4 User is offline   galexcd 

  • Define:EVIL PROGRAMMER (ē'vəl prō'grăm'ər)- n. An organism that converts caffeine into evil software.
  • PipPipPipPipPipPipPipPipPipPipPip
  • View gallery
  • Group: [MODERATOR]
  • Posts: 1,327
  • Joined: 25-September 05
  • Gender:Male
  • Location:Los Angeles, California
  • myCENT:33.67
  • Current Mood: Current Mood: None Chosen

Posted 10 January 2008 - 03:40 AM

Yes it isn't very useful but like I said I only did it because I was bored and wanted to do something random in php
0

#5 User is offline   Liam_CF 

  • Super Member
  • PipPipPipPipPipPipPipPipPip
  • Group: Kontributors
  • Posts: 403
  • Joined: 14-October 07
  • Location:ERROR 404
  • Current Mood: Current Mood: None Chosen

Posted 10 January 2008 - 05:55 PM

Woah, nice coding. Well done.
0

Share this topic:


Page 1 of 1


Similar Topics Collapse

  Topic Forum Started By Stats Last Post Info
New Replies Icon The Deathclock
how much time you got to live
Website Discussion buciaer 
  • 4 Replies
  • 2,136 Views
Hot Topic (New) Icon Background Image Swap Script
Change a Background Image based on clock time
Tutorials jlhaslip 
  • 15 Replies
  • 6,281 Views
Hot Topic (New) Icon X86 Clocking Assembler and Delphi osknockout 
  • 32 Replies
  • 13,754 Views
*Hot Topic (New) Icon 0v3rclockin9 yr processor General Talk Guest_l33tg33k_* 
  • 16 Replies
  • 2,163 Views
New Replies Icon Overclocking On A Laptop?
advice needed
Hardware Styx 
  • 4 Replies
  • 3,544 Views
New Replies Icon Cpu Overclocking
Power failure on some components
Hardware Galahad 
  • 6 Replies
  • 1,914 Views
New Replies Icon Flash Clock
Great for your website
3D/Large Pieces Lyon 
  • 4 Replies
  • 4,570 Views
New Replies Icon Free Mccartneys Clock
no surfboard included
Freebie Stuff IamAg 
  • 0 Replies
  • 505 Views
New Replies Icon Image Clocks Java, Java Servlets, Java Script, & JSP Nani Cheri 
  • 2 Replies
  • 1,529 Views
New Replies Icon How To Put Your Name Beside The Clock[windows]
costumize
Tutorials trapp17 
  • 9 Replies
  • 846 Views
New Replies Icon Case Mods, Overclocking, Etc....
need someone with some experience
Website Showcase millertime 
  • 1 Reply
  • 596 Views
New Replies Icon Overclocking Hardware Corey 
  • 2 Replies
  • 2,452 Views
New Replies Icon Set Alarm Clock
set alarm clock in your computer
Software vinayak 
  • 4 Replies
  • 1,494 Views
New Replies Icon Elprime Clock Pro - Review * * * * *
a very nice visual enhancement
Giveaway of the Day electriic ink 
  • 1 Reply
  • 1,143 Views
New Replies Icon Overclocking My Processor N Motherboard
Did some crazy overclocking here
Hardware odomike 
  • 3 Replies
  • 1,690 Views
Hot Topic (New) Icon Intel’s Pentium 4 Overclocked To 7.1ghz!
Now thats what I'd like to have;)
Hardware heavensounds 
  • 21 Replies
  • 3,709 Views
Hot Topic (New) Icon Overclocking
How-To on Overclocking
Tutorials amhso 
  • 17 Replies
  • 3,215 Views
Hot Topic (New) Icon Flying Alarm Clock
yes its true
Science & Technology fraudulentpeanut 
  • 33 Replies
  • 5,082 Views
Hot Topic (New) Icon How Do I Overclock My Processor?
Im a newbie at all this.
Hardware cragllo 
  • 19 Replies
  • 5,444 Views
Hot Topic (New) Icon 140 Flash Clocks * * * * *
Awsome clocks, don't miss them!
Freebie Stuff Lyon 
  • 19 Replies
  • 11,477 Views

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Google Fan :-) We Recommend Firefox.     Customize / Settings Connect Us on facebook