The Story of SunClock

I first encountered SunClock while using Sun workstations (it was a SunView application) at Rensselaer Polytechnic Institute, and thought it was pretty neat. When I moved on to the graduate program in Computer Sciences at the University of Wisconsin, Madison I had to suffer with lesser workstations and the X window system. I eventually did track down source for a ported version of SunClock, and installed it locally.

Naturally, as a graduate student, at times powerful distractions were needed in order to meet my procrastination quota, especially when faced with studying for qualifying exams. So I tended to go on fun programming binges when faced with such crises. For one exam I ported SunClock to my HP 48sx calculator If you have one of these calculators, or its successor, the GX, you can download the package. (I also discovered that this program is available on the HP Calculator Archive.)

Doing the port to RPL (the language supported by the calculator) I became quite intimate with the algorithms, because RPL is completely different than C, and the limitations and features of the calculator's processor and display are worlds apart from Unix windowing systems. I was glad that the original source included good comments. The public domain version on which I based my ports was written by John Walker when he was working at AutoDesk. You can see his more recent cool stuff at Fourmilab in Switzerland. In particular, check out EarthViewer!

As noted in the original comments, the algorithm used to calculate the position of the Sun is given in chapter 18 of Astronomical Formulae for Calculators by Jean Meeus, Third Edition, Richmond: Willmann-Bell, 1985. I was able to track down a copy of this interesting book in the UW libraries while working on the port.

Later I ported it to the Mac OS and made it colorful (previous versions were black and white). Of course, this was back before Mac OS was a Unix, and had an X server. There would have been no challenge in porting, otherwise! At that time I also added animation features so that you could watch time change at an accelerated rate. I never polished that version enough to release it to the world, and as I kept changing to new development environments (various incarnations of Symantec's Think Class Library, which I eventually gave up on in favor of Metrowerks CodeWarrior and PowerPlant) I was spending all of my hobby programming time just keeping up with the changes in operating system features and application frameworks.

So when I decided it was time to really learn Java, porting my colorful, animated version of SunClock (so that I could finally release it) was the perfect first project. And the cross-platform nature of Java gave me an even wider potential audience. The experience of moving SunClock over to Java has definitely given me a great deal of respect for the language, and excitement about the opportunities that it's helping create.

If you can see this text, your browser does not support Java, and you will not be able to see the SunClock applet.

Feel free to link this applet into your own pages, if you'd like. Here is the tag that is used to make it appear as it does on this page:

<applet Archive="http://www.brunchboy.com/Java/SunClock.jar"
Code="SunClock.class" Width=364 Height=180>
<param Name=showControls Value=false>
<param name=showTimes Value=none>
If you can see this text, your browser does not support Java, and you
will not be able to see the SunClock applet.
</applet>

There are several parameters that you can use to customize the interface and behavior. Note that you'll need to adjust the height and width if you turn on any of the display and interface options, and that the additional size requirements will vary depending on what browser and what operating system is being used to run the applet, so you're probably best off leaving extra padding. Here are the parameters that SunClock currently supports:

Parameter Type or Values Description
startDate Date Sets the date and time which will be displayed initially. Any string which can be parsed by the Java Date class can be used (dates earlier than 1970 don't seem to be supported).
updateRate Never, Minute, Second or Continuous Sets how often the displayed image is recomputed and redisplayed. Never yields a static image, while at the opposite extreme, Continuous attempts to display the next time as quickly as possible.
updateDelta Realtime, Minute, Hour, Day, Week or Month Each time the display is updated, a new time is shown. This parameter determines how that time is chosen. Realtime means the current actual time is used. The other choices add a fixed interval to the previous time displayed. Using multiples of a day keeps "noon" at the same point on the map but shows how the seasonal illumination curve changes.
showTimes None, UTC, Local or Both Controls whether the date and time represented by the map should be displayed above the map. Either the local time, Universal time, both or neither can be displayed.
showControls boolean Determines whether a user interface should be provided for manipulating the applet. If true, it will be built below the map.
dayImage URL Specifies an image file to use for drawing daytime portions of the map. You can use any image file Java can load, but see below for some notes.
nightImage URL Specifies an image file to use for drawing nighttime portions of the map. You can use any image file Java can load, but see below for some notes.

The Map Images

When I was starting work on the Mac version of SunClock I noticed that the clip-art world map included in the standard Scrapbook (which you can paste into the Mac's Date and Time Control Panel to colorize it) was perfectly suited to the SunClock application, since it used the same standard projection as the black and white images in the original program.

All I needed to do, then, was make a nighttime version of the map, which was easy and fun using Photoshop. Since the original map indicated cities with a hard-to-see but distinctive red color, I was also able to make them "light up" at night by mapping that to a bright yellow in my nighttime map.

I also had to come up with a new way of drawing the daylight curve. The black and white versions simply use an exclusive-OR operation on the one-bit map pixels. This won't look like night (or even like anything you want to look at) on a color image. QuickDraw's flexible Region support allowed an elegant approach on the Mac OS. My Java solution was simply to expand the images into pixel arrays and pick the appropriate pixels out of each image. I was impressed by how quickly this more tedious approach ran in Java.

If you want to install your own map images, note that Java security features will probably not let you specify arbitrary URLs to load, so you'll either need to copy the class files to your own server where the images also reside, or (and I'd prefer this) let me know about the images so I can add them to my own server where they can be used as alternatives.

Your map images will need to have exactly the same pixel dimensions as each other, but need not be the same size as mine. They should, however, use the same map projection, with the International Date Line in the same place as it is on the maps I use.

Let me know if there are any other cool map images out there that can be used with SunClock, or if you create any yourself!


This page was last modified Sunday, 13-May-2007 00:07:45 CDT.
Return to Home Page.