LinuxQuestions.org
Have you heard the LinuxQuestions.org Podcast?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Thread Tools
Old 11-08-2009, 10:22 AM   #1
Raymii
LQ Newbie
 
Registered: Nov 2009
Posts: 1
Thanked: 0
[bash] Current time to degrees for clock wallpaper


[Log in to get rid of this advertisement]
I'm trying to make a script which transforms the current time into a clock image.
I'm doing it with imagemagick and bash. What I already have is a script which makes the clock from out nothing:
http://raymii.org/test/clock.sh
(It looks like: http://raymii.org/test/clock.png )
But now the time has to be shown with hands.
What I was thinking is to call the script from a crontab every minute.
It then takes the current time with the date command, strips it so that the HHSS is left (with sed maybe). Then it makes a line with convert that is in the angle it should according to the current time(The Minute hand) and it does that also for the hour hand. Then it composites it all together.

I have a center dot, and the hands should come out of it. In the script I'm using percentages because the plan is to make it work at 1280x1024 and 1920x1280.

But the whole date to hand conversion part is to difficult for me. I totally do not know how to do that.

My bash skills are limited, and what I have can probably be done better, so i'd love some tips and suggestions. Especially for the time to hand part.
linuxmint Raymii is offline     Reply With Quote
Old 11-08-2009, 01:37 PM   #2
slimm609
Member
 
Registered: May 2007
Location: Chas, SC
Distribution: slackware, gentoo, fedora, LFS, sidewinder G2, solaris, FreeBSD, RHEL, SUSE, Backtrack
Posts: 332
Thanked: 13
MINHAND and HRHAND will give the proper degrees for hands.

i just havent used imagemagick enough to draw out the hands.

hope this helps

Code:
HR=`date +%l`
MIN=`date +%M`
#convert minutes to give the proper angle for hour
M4H=`echo "$MIN * 1.666666" | bc`
if [ "$HR" = "12" ]; then
   HRHAND=`echo "($HR.$M4H * 30) - 360" | bc`
else 
   HRHAND=`echo "$HR.$M4H * 30" | bc`
fi
MINHAND=`echo "$MIN * 6" | bc`
windows_98_nt_2000 slimm609 is offline     Reply With Quote
Old 11-10-2009, 07:01 PM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Puppy
Posts: 2,715
Thanked: 21
it's easy.

360 degrees in a circle, 60 minutes in a circle.

1 minute = 6 degrees.

cron is not accurate. I really wouldn't.
freebsd bigearsbilly is online now     Reply With Quote

Reply

Bookmarks


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hardware clock time differs from system time after setting maxgsp Linux - Software 2 02-28-2009 08:15 AM
bash: display CURRENT time in prompt? exscape Linux - Software 7 01-19-2009 08:06 AM
clock-adjustment time is offseet from clock-display time bezdomny Linux - Desktop 2 11-19-2008 03:48 PM
Where does RH8 daily set system time to hardware clock time smartnorman Red Hat 1 05-24-2006 03:42 PM
Various clock issues: Clock shows wrong time only in Knoppmyth, & CMOS time change ? davidbix General 1 04-05-2006 10:58 PM


All times are GMT -5. The time now is 06:59 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration