Analog clock
The TIMESENSOR of X3D is quite a complicated time mechanism to understand. As I have created some commands for easy animation, I thought that it would be interesting to test the TIMESENSOR with an analog clock.
The construction of an analog clock is very mathematical. I used a 2D disk (DISK) as the clock face and a rectangular torus (RECTORUS) as the clock case. The hour and minute marks are done with scaled boxes (BOX). The second hand is a line drawn by the turtle. The hour and minute hands are faces drawn by the turtle as well using PD (pendown) and PU (penup).
The three hands all have the coordinate (0, 0, 0) as their centre. Therefore, when using the SPIN command with the right amount of seconds as their cycleIntervals, they just spin like a clock. I have also included some objects for you to click on so you can change the thickness of clock case and change colours of the clock. Now, time to play with my newly designed analog clock below.
Below are my LOGO program for this analog clock. Because it is quite long so I only included the clock part below.
; Virtual analog clock ; By Andy Yeh (2014) CS RESET SETBG 34 FD 0.05 SETMAT 0 24 DISK MAKE "facemat WORD OBJECT "_mat BK 0.05 RU 90 SETSCALE 1 0.1 1 SETMAT 0 16 RECTORUS MAKE "case WORD OBJECT "_rectorus MAKE "casemat WORD OBJECT "_mat SET :case "outerradius 1.05 SET :case "innerradius 1 HOME RU 90 SETSCALE .05 .1 .05 SETMAT 0 30 CYLINDER ; draw hour hand LT 60 BK 0.1 WEST 0.01 FACE PD REPEAT 2 [ FD 0.7 RT 90 FD 0.02 RT 90 ] PU MAKE "hour_hand OBJECT ; draw minute hand HOME BK 0.02 RU 90 BK 0.1 WEST 0.01 FACE PD REPEAT 2 [ FD 0.8 RT 90 FD 0.02 RT 90 ] PU MAKE "minute_hand OBJECT ; draw second hand HOME BK 0.04 RU 90 BK 0.1 LINE PD FD 0.9 PU MAKE "second_hand OBJECT ; apply animation SPIN :hour_hand "tr 43200 SPIN :minute_hand "tr 3600 SPIN :second_hand "tr 60 ; draw hour marks HOME FD 0.03 SETSCALE 0.03 0.15 0.03 REPEAT 12 [ RU 90 FD 0.88 RD 90 BOX RU 90 BK 0.88 RD 90 TR 30 IF REPCOUNT = 1 [ MAKE "xii OBJECT ] ] ; draw minute marks HOME FD 0.03 SETSCALE 0.01 0.05 0.01 REPEAT 60 [ RU 90 FD 0.93 RD 90 MAKE "count repcount-1 MAKE "mod :count % 5 IFELSE :mod = 0 [] [BOX] RU 90 BK 0.93 RD 90 TR 6 ] SELECT :xii SETMAT 1 0 DESELECT
Can you figure out how I did it in the above LOGO program?
If you are interest in the full program, you can try directly in VRMath2 Editor and open the analog_clock.logo in the Example drive (look in animation folder) in Logo Editor. I have also attached the files here if you wish to download.
PS: To get the Logo Editor window in VRMath2 Editor, you can click on the Window menu to find it, or from the File menu to Open Logo file, or simply click on the small pencil icon in Console window to get to Logo Editor. Then you can open some Logo examples from its Open icon.
Files: analog_clock.logo analog_clock.x3d
Please leave me a comment, suggestions or questions below, or discuss in the forum your ideas.
- Andy's blog
- Login or register to post comments
- 14220 reads