Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialNick Pettit
Treehouse TeacherForum Contest: Create an Analog Clock
EDIT: This contest has ended! Congrats to Christine Dawson for her winning grandfather clock entry. The next forum contest is all about designing a responsive data table.
Hi everybody,
It's time for a new Treehouse Forum contest! First, watch this video to learn more:
After you've watched the video, please read the details below carefully. I'm looking forward to your entries!
How to Enter: Create your analog clock entry as a "pen" on Codepen.io and then post the link to your pen as an answer to this post.
Due Date: All entries must be submitted by Monday, May 26th at 11:45pm ET. Here's a timezone chart so you can see what time that is for your locale.
Prize: The entries will be judged by Treehouse teachers based on both design and code. One winner will receive a free month of Treehouse Pro on us! :) We'll announce the winner on Tuesday, May 27th and reveal the next contest.
cbcbcb
16,560 PointsYou I think Team Learning Tree and their wonderful team of staff should seriously consider adding a delete button these comments. Now I can't delete my irrelevant comment above.
Jacques Vincilione
17,292 PointsHere ya go, hope you like it:
Alex Jonathan
Courses Plus Student 761 PointsLike the theme. Unfortunately I don't know Javascript.
Viktor Bezdek
106 PointsHere's my solution mostly CSS based solution. Took me 18 minutes. Would work only in modern browsers because of CSS3 and querySelector.
26 Answers
Justin Horner
Treehouse Guest TeacherGood luck to all participates! Looking forward to seeing your designs.
John Coffin
10,359 PointsChallenge accepted!!!
Daniel Le Maty
754 PointsDone mine! http://codepen.io/lematy/pen/JmeEb
but i photoshopped some images for the hands and the clock. Is that allowed or does it all have to be in css?
John Coffin
10,359 PointsThis looks awesome. I'm a little ticked. I was hoping to submit first. ;)
FYI, I'm using images for clock face and hands as well (or at least my "first draft" ... and I have yet to get to a second draft in a weeks time). There is nothing in the rules that says you have to animate every pixel using CSS, and the use of images is smart.
John Coffin
10,359 PointsThis looks awesome. I'm a little ticked. I was hoping to submit first. ;)
FYI, I'm using images for clock face and hands as well (or at least my "first draft" ... and I have yet to get to a second draft in a weeks time). There is nothing in the rules that says you have to animate every pixel using CSS, and the use of images is smart.
Becky Castle
15,294 PointsOh man, it's the "school clock"... Hee hee, nice work
Daniel Le Maty
754 PointsThanks :D and i tried without images but that didnt look as good lol
John Coffin
10,359 PointsDaniel Le Maty
754 PointsThats awesome! :D
John Coffin
10,359 PointsThanks!
Becky Castle
15,294 PointsNice. Is that an Armani? ;)
Dino Paškvan
Courses Plus Student 44,108 PointsI don't know if moderators are allowed to compete in these or not, but I wanted to participate. I've probably disqualified myself by using SVG, but I realised I have never experimented with SVG and this seemed like a nice opportunity to do so.
I opted for a simple, minimal design because I didn't want to complicate the SVG too much. I used CSS as little as possible — I'm only centering the container div on the page.
All the colors are defined in the SVG, including the clock shadow gradient. The background color of the page is set in JavaScript as it's dynamic — it changes according to the time of day (it gets lighter towards noon and darker towards midnight).
The shadow that the clock throws also moves during daytime, travelling from left to right as the "Sun" moves across the sky. It also changes intensity (opacity). I picked arbitrary sunrise (5am) and sunset times (7pm) to keep the code as simple as possible.
During "night" the shadow is fixed at an angle of -45deg
, and its opacity is set to 0.2
, due to some imaginary static light source.
All the functions that calculate hand and shadow data were declared as methods on the Date.prototype
property. I chose to extend the built-in object to add analog clock functionality to it. It seemed appropriate in the context of the contest.
Finally, this currently doesn't work in Firefox, as Firefox doesn't have transform-origin
support for SVG.
John Coffin
10,359 PointsThis is deceptively simple. I'm glad you gave the long description; I'm going to check it out later.
IMO you should not disqualify yourself for either. I personally enjoy the fact that I am competing with people who are much better than I am at many different things and who know a wider range of skills. I find that I learn more about things that I might not have tried otherwise.
Nick Pettit
Treehouse TeacherModerators are definitely allowed to participate. :)
Dino Paškvan
Courses Plus Student 44,108 PointsNick Pettit, that's good to know. :)
John Coffin, I figured I'd provide a detailed explanation as the dynamic shadow/background could get missed at a glance.
Finally, I've decided against fixing this for Firefox. Any solution that I could come up with either complicates the SVG too much or the JavaScript code running the whole thing.
This is more of an experiment than anything else, so I hope no one will hold it against me.
John Coffin
10,359 PointsOk. You made me open my mouth in awe. Does it "dong" on the hour?
Christine Dawson
8,136 Points:D Wish I'd thought of making it chime!
John Coffin
10,359 PointsIt would be really cool if you did.
John Coffin
10,359 PointsI think that your clock is trending.
Chezki Indursky
3,500 PointsCool! :)
Eric Flowers
9,472 PointsAwesome!
Becky Castle
15,294 PointsThis is really great!
Charlie Hield
4,767 PointsWent a totally different direction with mine.
Word Clock -- fullscreen & code
John Coffin
10,359 PointsYou did, didn't you.
Good choice in changing the color between minutes. Did you try out having seconds, minutes, and hours as bars? I'm curious if making it easier to tell time at a glance (by doing this) destroys the simple charm of only showing seconds.
John Coffin
10,359 PointsIs there any way to randomize the start-up color? Otherwise, I might not wait until the minute is over to discover the color changing (well ... I would, but someone else might not).
Charlie Hield
4,767 PointsYep, just added random on load.
Sam Nabhan
2,157 PointsThat's brilliant, Charlie. Way to think outside the box :)
Well done.
Peter G.
Courses Plus Student 5,806 PointsDude that is just pure out of the box thinking.
Becky Castle
15,294 PointsSam is right. If this is box: [], here's you, way over here --------------------> 8-) That's an inspiring design.
Alejandro Ñáñez Ortiz
21,184 PointsReally nice one. +1
John Coffin
10,359 PointsHere comes my (wait for it) second iteration:
There are a few "known issues," not the least of which is that the responsive design went out the window. Oh, and I only have webkit imlementation, so you'll need Chrome or Safari. Hopefully I'll have this all cleaned up right quick.
-- much later --
Christine Dawson
8,136 PointsNice! I like the badges idea :)
John Coffin
10,359 PointsThanks! This was something that I've wanted to do, so I'm happy that I finally got a chance.
Dino Paškvan
Courses Plus Student 44,108 PointsOkay, here's my second version: Full / Code
Wait! That looks like my first version! Well, yes... visually, it's identical, but I've made significant under the hood changes.
First of all, only the shadow is an SVG. The clock itself is a collection of divs.
I grabbed the clock functionality from my first version and turned it into a JavaScript clock library called mikulas.js. I named it after the Czech clockmaker who co-created the Prague astronomical clock.
I am no longer extending the Date object, I have a new Mikulas
object that contains a date
property.
It will work both on divs and SVG as all you need to do is pass it the ids of the elements representing clock hands. Optionally, you can pass it a callback function which will get executed every time the clock is updated (I use this for the shadow and background changes):
var c = new Mikulas("h", "m", "s", function() {
console.log("Clock updated!");
});
You can set the time to a particular time or let it run normally:
c.setClockTime(someDateObject); // setting it to particular time
c.start(); // letting the clock work normally based on local time
If you wish, you can also stop the clock at some point:
c.stop();
Basically, as long as you have a bunch of elements resembling clock hands (set at 12 o'clock), it'll work. The transform-origin
property is set programatically on the hand elements.
This version also works in Firefox because I'm not rotating the SVG path, instead, I'm rotating the div containing the SVG.
I'm importing mikulas.js
from my GitHub page inside the CodePen, but you can see what it looks like here or on Github.
The shadow and background dynamics aren't a part of mikulas, instead they are custom functions called in the optional callback
argument.
Josh Sanger
31 PointsI created this using HTML5 Canvas which goes hand in hand with Javascript. There are no images or external libraries :) I must say this was quite fun!
Full screen: http://codepen.io/joshsanger/full/yAFpa/ Code: http://codepen.io/joshsanger/pen/yAFpa
Jacques Vincilione
17,292 PointsLeft my answer as a comment on the post. Oops.
Here ya go, hope you like it:
Jacques Vincilione
17,292 PointsAfter looking at some of the others, I decided to change mine a bit.
Comments/Critiques are appreciated. Entire analog clock built with canvas.
Ashlynn Pai
11,679 PointsNice! I think you may be able to sell that.
Ashlynn Pai
11,679 PointsModifications: replaced the golden hand pointer image replaced outer ring image
Hope it's okay for me to keep tweaking after I post.
http://codepen.io/ashlynnpai/full/Cphar
http://codepen.io/ashlynnpai/pen/Cphar/
My clock is based on the Astronomical Clock in Prague. I wanted to work on something Czech so luckily this project came along because I was going to make something beer related. I did nearly all the work today so there may be some mistakes I can't see from being too tired, so feel free to let me know.
Functions of the clock:
Outer ring -- This is an approximation of old Czech time and show the hours until sunset, with the golden number 24 marking the time of sunset. It doesn't use the proper algorithms because I didn't want to get bogged down here (http://www.mysundial.ca/files/H2SSManual040801.pdf). Instead from Dec 12, the ring rotates clockwise .42 degrees per day. From June 21, it rotates counterclockwise .42 degrees per day. These are the days of earliest and latest sunset in Prague this year. Maybe later I will fix the algorithm, but not today =).
Main ring -- This shows the hour according to astronomical time, with noon at 0 degrees and midnight at 180 degrees. The golden hand points to the current hour. I added the minute and second hand (which is not authentic) so people could see something in motion as everything else doesn't move often.
Inner ring -- This shows the signs of the Zodiac and the position of the sun on the hand pointer is supposed to identify the current Zodiac sign, so it rotates along with the hour hand. Right now it's 30 days behind so I'll have to redo my calculations later. If anyone spots my error that would be great. I'm too tired to see it.
Sorry no figurine show! I was going to make one then decided not to.
Ashlynn Pai
11,679 PointsIt may have been only one day off because of rounding and now it's corrected, as yesterday was only one day past the start of the new zodiac. It seems to be working now.
Charlie Hield
4,767 PointsNice! Totally reminds me of Polarclock from way back when.
Ian Hudson
13,457 PointsJuan,
Very nice and futuristic. :D
Ian
Diego Lucero
10,588 PointsNICE!! I love the concept. Very well-polished look also.
Jacob Miller
12,466 PointsHere's mine: Full page on Codepen. I used Dino Paškvan's library mikulas.js. Thanks Dino!
Chris Mitchell
12,719 Pointsneeded help with javascript so ty to Dino for your explanations, I have never participated in any contest before but here is my attempt:
full page: http://codepen.io/jangofett/full/zutcv
Matthew Hicks
9,641 PointsHere's mine!
http://codepen.io/Talmarei/pen/vmxcb
This is my first contest entry, had lots of fun with this - hope you like it. Looking forward to taking part in more!
Nick Pettit
Treehouse TeacherHi everyone,
Wow! Once again, there are tons of amazing entries. We went through all of them several times today and you certainly didn't make it easy to decide a winner. :) You should all feel proud of the work you've done here, because now you have that much more experience and another item to include in your portfolio.
This week's winner is Christine Dawson! She put together this amazing grandfather clock using HTML, CSS, and JavaScript. Like most of the designs here, this wouldn't quite make semantic sense on a webpage, but it certainly looks very well polished. Congrats, Christine!
Our next forum contest is all about creating a responsive data table.
Christine Dawson
8,136 PointsOh wow, that's made my day! :D Thanks!
John Coffin
10,359 PointsCongrat, Christine!!!
Viktor Bezdek
106 PointsHere's my solution mostly CSS based solution. Took me 18 minutes. Would work only in modern browsers because of CSS3 and querySelector.
cbcbcb
16,560 Pointscbcbcb
16,560 PointsSo does it matter what we program it in? Like can I use swingFX with CSS and core JavaSE or just some swing and JavaSE.......not valid and have to be in Android? Has to be a language that has a course track on the site what's the deal sir? Sorry I'm new I couldn't find anywhere. I was just curious. Sounded fun and I am bored for the day..