Jump to content
Tuts 4 You

How to build a analog clock?


LCF-AT

Recommended Posts

Hi guys,

could anybody explain how to build any kind of dynamic graphic illustrations?So how to do this and what do I need to do this?

Example: Windows 7 has a little nice analog clock graphic you get to see if you press on the time in the taskbar and now I wanna have / build any similar clock like this but I dont know how I should do this.The first mind I had was to paint a clock picture in any paint app to have the analog clock background (not sure whether this is right) and to show this later in any dialog.As next step I need to build some diffrent clock pointers to show them on this clock anyhow  etc.All in all I have no idea how the right way is and thats the reason why I do ask now so maybe you could tell me something about this and how to handle such graphical representations starting just with a clock. :)

Thank you

Link to comment

You could make use of Gdi/Gdiplus to generate the graphics on the fly and render them onto the screen / into a window.

There are a lot of open source examples of making an analog clock already on the internet. Just Google for your language of choice with analog clock in the search such as: analog clock C++

Link to comment

Hi,

thanks for the links but this isnt that what I am looking for.Dont wanna make any Dos style clock etc.I would like to create almost same clock like this of Win 7 (see picture).So the clock background should be any good looking picture but I dont know how to make the time pointers and showing them.

Clock.png

greetz

Link to comment

Personally I would do it either with GDI or OpenGL, depending on the use case. Create a back ground then render the hands and lines on top - algorithm should be fairly simple (6 degrees movement per minute for the big hand and 30 degrees per hour for the hour hand)

  • Like 1
Link to comment
  • 7 months later...
Teddy Rogers

If you aren't too worried about scaling you could create a background clock image then three separate images for the second, minute and hour hands. You then only need to plot the angles for the time and paint them on to the background image in memory before displaying to screen. Possibly even add a little dithering to smooth out jagged edges.

21 hours ago, LCF-AT said:

no progress yet to build any GDI lines.So somehow I should use this..

Maybe using the Polyline function?

Procedure.i DrawClockHands(second_x, second_y, minute_x, minute_y, hour_x, hour_y, hdc)
  
  Structure POSITION
    second.POINT
    minute.POINT
    hour.POINT
  EndStructure 
  
  Protected pointer.POSITION
  pointer\second\x = second_x
  pointer\second\y = second_y
  pointer\minute\x = minute_x
  pointer\minute\y = minute_y
  pointer\hour\x = hour_x
  pointer\hour\y = hour_y
  
  Polyline_(hdc, @pointer, 3)
  
EndProcedure 

Ted.

  • Like 1
Link to comment

Hi Ted,

so do you mean I have to create images for the clock hands too and then turning them to show them correctly?

So my main goal was it just to reproduce the Win 7 clock anyhow also with same hands.So the clock picture I can copy / use and just need to draw / show the hands on it etc.Also then I think I need to calc anyhow a lot to show all hands correctly for time x.No idea,so as I said I think I still do think wrong anyhow. :(

PS: Yes maybe other languages are much better and more simple to use but I cant switch now so there I would start almost from zero again.

greetz

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...