Hacker News new | comments | show | ask | jobs | submit login
The Colour Clock (thecolourclock.co.uk)
271 points by huangm 2065 days ago | hide | past | web | 86 comments | favorite

Awesome idea. I took some time to rewrite in HTML5: http://brisy.info/colors/

Though the colours I'm getting are different. I wonder why.

Here's a version that cycles through the colors continuously (without jumps). Now the numbers do not directly corespond to the color code anymore (they alternate going up-down). Also you can multiply by 256, as the maximum is not reached for any of the values.

I uploaded it here: http://lkozma.net/colorclock/

  d     = t.getTime()/(1000 * 60 * 60 * 24),


                 "rgb(" + 
		  (((d%2)==1) ? parseInt((h / 24) * 256) : (255-parseInt((h / 24) * 256))) + "," +
                  (((h%2)==1) ? parseInt((m / 60) * 256) : (255-parseInt((m / 60) * 256))) + "," +
                  (((m%2)==1) ? parseInt((s / 60) * 256) : (255-parseInt((s / 60) * 256))) + ")"});

cool....I hacked in some timezones - 4 clocks on the page - local, london, new york, tokyo...if I got my maths right that is:


someone should make the timezones selectable :)

I appreciate the pointlessness of being yet-another recreator, but hey, why not: http://davidlynch.org/toys/colorclock/ :D

My quirk is that you can stick a fragment on the end to change the mapping of time to hex. e.g. http://davidlynch.org/toys/colorclock/#smh is seconds=red, minutes=green, hours=blue.

It'd be great if you could add the necessary meta tags to make this fullscreen when saved to home screen on a iOS device. No need for an icon -- iOS already frames the time nicely.

Heh, sure, why not? It now has apple-mobile-web-app-capable=yes.

... perhaps because it should be h / 24 instead of h / 60 ?

                 "rgb(" + parseInt((h / 60) * 255) + "," +
                      parseInt((m / 60) * 255) + "," +
                      parseInt((s / 60) * 255) + ")"});

Yes, just corrected this thanks.

Haha, I just did the same thing: http://nerdlife.net/colorclock.html

Guys, get these on github. That way we can fork it & make it awesome as a team faster and better.


HTML5, CSS3, webfonts, and jQuery

Similar pull request sent to you too! :)

Behind the curve here: https://github.com/kemayo/colorclock

Small bug: Single digit hex codes are showing without the leading zero - it's probably affecting the colors as well.

Fixed, thanks.

Great minds and all. If you replace the html file in the screensaver bundle you can use yours (or mine) instead of the flash one.

Instead of:

  window.setInterval(frame, 1000);

  window.setTimeout('window.setInterval(frame, 1000)', 999-(new Date()).getMilliseconds());
That way the seconds will be properly synchronized.

Instead of a string containing code, you should use an anonymous function.

I'm on a P4 3Ghz at the moment, whereby I can hear my CPU buzzing away when its under load. On the .co.uk site the buzzing is audible, its taking >70% of the CPU, whereas on your site its nice and quiet taking just 6% of the CPU.

I can not figure out how such a simple program can manage to take up 100% of my CPU, and despite that not be in sync with my actual clock (it's a random fraction of a second off).

Has he not heard of sleep(1) ? Saying "it's flash" is no excuse, flash is perfectly capable of sleeping.

Updating a clock to display the correct time is actually difficult and involved, sleep(1) will not work! The problem reminds me of this Intel article on syncing video output [1]

Basically, sleep(1) won't always align with clock updates, so sometimes a given time will display for more or less time than a second. This can be observed by opening the clock widget on Windows XP for example, it's very noticeable. I don't actually know a nice way to do it, maybe updating 10 times per second or so?

[1] http://software.intel.com/en-us/articles/video-frame-display... - it's down right now, one of the diagrams illustrates the problem well though: http://software.intel.com/file/3984

On POSIX systems, clock_nanosleep() can accept an absolute time argument.

  // In a real program one would probably not use time()
  // Also, some older pre-release versions of the realtime
  // kernel patches had the clock_nanosleep() and time() 
  // clocks out of sync by 0.5s (IIRC)
  for(;;) {
    struct timespec after_epoch = { .tv_sec = time(NULL) + 1, .tv_nsec = 0 };
    // Check for EINTR in a real program
    clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &after_epoch, NULL);

Unfortunately, this probably doesn't help with Flash or JavaScript clock demos.

Rather useful in this case could be an adaptive method. First, you update every 50ms until you circled in the moment when the second toggles. Then you can do sleep(1) again and save resources.

Alternatively, use time() to only sleep the remaining timespan until the next second.

Well to get technical there isn't a "sleep" function in flash. The best you can do is use setTimeout, which will call a function back in a specified amount of time. Everything including screen drawing, mouse interaction, effects/animations, code execution, etc all run in a single thread, which means if you could actually sleep(1) it would lock everything up for the full second.

Your solution, unlike the Flash one, utterly fails to spike my CPU.

That's a new one on me for things labelled "HTML5". :D

Honest question - what is the HTML5 part in here (as opposed to I rewrote it in HTML+CSS+JS)?

Even though the implementation above doesn't use any HTML5-specific features, the term is becoming a synonym for Dynamic HTML.

I'd also argue it's becoming a synonym for "Not Flash!?!"

Since we're sharing our HTML5 clocks which peg the processor: http://sandbox.mikepurvis.com/js/clock/

This seemed like a fun idea: Here's my remix of it, a bit more HTML5-ish:


And by HTML5 I mean HTML5+CSS3

It's a bit wonky when you use a variable-width font.

Yeah. I moved to ems, thinking that would help, but it's still an issue.

If you don't set a width then you get awkward spacing reflow when the digits change.

I did something very similar some time ago: http://pedro.si/experiments/color-clock/ It's CSS3 and some Javascript.

maybe they literally encode 9:27:40 as #092740

edit: definitely not, but I think there's a gradient overlay, which is causing the colors to appear brighter in the center.

Jim Blandy wrote a similar program for X Windows around 1992: a beautiful color clock that would sit on your desktop's root windown and slowly cycle through the colors over the course of an hour. It didn't even show digits -- you just had to learn the colors :-). I think it depended on X supporting writeable color cells, though, so it would need to be rewritten to work on most modern systems (which generally seem to not be set up that way).

Hmm, but that's after I started making some mods. For best results, try an earlier rev (this was converted from CVS, hence the weird log message):


Simple & beautiful.

Small criticism: Why Flash?

That "full screen" button in the top-right.

Or, at least, that's the only thing I see there that you can't do with HTML/JS.

You can actually, F11

Well, yeah, but you can't have a handy button for it on the page.

Not in Safari. It doesn't have fullscreen.

It should be simple enough to implement in HTML - it looks like it's just doing (seconds since midnight × 16777215 / 86400), converting to hex and using that as a colour. Toggling between "clock" and "colour" mode would be a bit more difficult, but doable.

Anyone feeling up to the challenge?

Here's my attempt: http://brisy.info/colors It treats each section of the time as a hex pair, see colors.js for implementation.

edit: Hours corrected. Thanks wladimir

Nice! One small correction: ((h / 60) * 255) should be ((h / 24) * 255) probably

Probably easier to port it to a screensaver.

The state of the art for custom geek clocks is in hardware AFAIC.

RGB LED color clock: http://www.youtube.com/watch?v=BKT-0qB9l8A&feature=relat...

I also enjoy the classic 'pong clocks' http://www.youtube.com/watch?v=PHxbknBYYAQ&feature=playe...

Clocks are a common beginner project in DIY hardware, they are both simple to make and have good potential for adding stuff like RSS readers and so on when you want to branch out.


It would be nice if the colour was meaningful, i.e. if one could, at least roughly, guess the time based on the colour. Say, that the brightness would reflect time of day (brightest at noon, darkest at midnight) and the hue the time within the hour.

HSL might work better for that, though I'd cycle it around the spectrum, with the seconds value being the saturation percentage.

I feel like this would make an awesome desk or wall clock.

Maybe load it up on a Chumby? http://chumby.com

It's also on the iPhone app store (for £0.59), but it might be a different author.

Associating time with colour has been tried many times - eg the Chromachron watch was briefly famous:


I had done something similar around 2000 though I wasn't very sophisticated at programming so I think it's off...


Last year I re-made it as a free iOS app which takes the time and converts it using a RGB>HEX function I found that I think is correct:


I also made one that sets Hour, Minute to latitude,longitude in Google maps which I like looking at: http://itunes.apple.com/us/app/time-as-place/id336539483?mt=...

(edited second link)

Very similar to the Chromo http://prote.in/chromo colour clock, which has been around for a few years.

This is pretty impressive. Would you consider porting to other OS'? I.e., Linux.

I know I'd be happy to run this on my monitors!

Regardless, great job!

This is cool, but does the screensaver also have to be in Flash? I'd prefer my fans to not spin up when my screensaver kicks in.

A shame that the fastest-moving value is placed in the portion of the spectrum where we have the least colour sensitivity. I'd have put hours in blue, myself. If I'd thought of it.

Any order, yes, but things like http://davidlynch.org/toys/colorclock/#hsh do not work yet.

Yeah, okay, they'll work now.

That's rather nice.

I'm quite sure there are much more mappings from hh:mm:ss -> rgb which would be even more interesting or even practical. For sure the internet will iterate on this idea in just a few seconds :)

Yeah, HMS->HSL would be quite intriguing.

I wonder how well the color blind can detect second to second changes in hue? Not a complaint, just a genuine curiosity.

Any color blind out there care to comment?

I'm red-green colour blind but have difficulty in describing colours in general (I see them and know what they are but sometimes (and especially if they're under a coloured light) I can't specifically say what colour a wall is, for example).

This is quite interesting as I can't really see second-by-second changes; at most I can see small jumps (not the radically large ones) you get every few seconds.

I'm not color blind, yet that is what I see, too. Makes me wonder about the brain's color-processing. My guess is small variations are ignored by the brain because slightly changing light conditions can cause all colors to vary slightly over time. Your brain filters them out so you can only tell when something really is changing.

I still like the Polar Clock best... http://blog.pixelbreaker.com/polarclock

My favorite clock remains the Uniqlock: http://www.uniqlo.jp/uniqlock/

That's hilarious!

It would be interesting to see what would happen if the colors were given by following a space-filling curve in three dimensions, like the last figure at http://mathworld.wolfram.com/HilbertCurve.html

The switch from 22:59 to 23:00 was stunning.

I can't wait for the switch at midnight (#FFFFFF -> #000000).

I missed it. It basically goes from white (well, very pale cyan) to bright red, right?

#FFFFFF to #000000 would be white to black.

I made my comment at about 23:05 last night, my local time; I was talking about 22:59:59 to 23:00:00, or (approximately) #F5FFFF to #FF0000.

Feel free to modify your computer clock :)

Seems like cheating.

The hex clock seems to jump every once in a while, probably compensating for the large difference in the number of hexadecimal color values and seconds in a 24 hour day.

How are the color values related to the seconds here?

As I understand: hours are red, minutes are green, seconds are blue. Simply formulated as HTML color #HHMMSS (and with each component scaled appropriately to 00..FF so that 00:00:00 is #000000, 23:59:59 is #FFFFFF)

I'd like one that doesn't show the seconds (but does change the color every second). This is too distracting for me to really use.

Funny and original idea though!

Nice job, but why screensaver only for MacOS?

I've turned off sleep mode so I can actually see this as my screensaver now.

that's quite beautiful

iPhone app?


Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact