Python 3D Graphics Tutorial 17: Creating Accurate 3D Clock in Vpython

preview_player
Показать описание
You guys can help me out over at Patreon, and that will help me keep my gear updated, and help me keep this quality content coming:

In this video we show step-by-step instructions on how to build a 3D clock face model in Vpython. We will animate the clock in this lesson, with second, minute and hour hands. We then how to show how to make it keep accurate time by synchronizing with your system clock time.

#Python
#Lessons
#Vpython
Рекомендации по теме
Комментарии
Автор

I AM LEGEND! Not sure how I was able to accomplish this. I took a little break and I kept telling myself there was no way I would ever be able to do this. Busted out the trusty composition notebook and I got work... After a bit of doodling I decided it may just be possible so I started coding. As I programed each segment of the clock and each one came to life one by one a small tear formed in the corner of my eye. Watching my clock that I programed come to life was almost as good of a feeling as watching my sons birth. Thanks for another great lesson Paul!

Mr.Java
Автор

This lesson was very fascinating! I thought I had it right, I thought about the position and the starting point and but didn't got to this idea of solution with the pi's. This lesson taught me alot, thx Paul.

yuval
Автор

Hi Paul, I am Legend still! I've got the clock to work seamlessly between the minutes and hours: Thanks again for everything.

alfredcalleja
Автор

Thank you Paul for all this so nice tutorial. I had a very pleasant (and informative) good time with your lessons. Finally, I managed to make my clock and I am very happy with it. The formulas I used to sync it to real time are a bit different from yours, but I think they work :

from vpython import *
import time
import numpy as np

rad = 1
clockFace = cylinder(axis=vector(0, 0, -.1*rad), radius=rad)

mHand = arrow(color=color.red, length=rad*.8, shaftwidth=.02*rad)
hHand = arrow(color=color.red, length=rad*.6, shaftwidth=.03*rad)
sHand = arrow(color=color.red, length=rad*.9, shaftwidth=.01*rad)
cylinder(axis=vector(0, 0, 1),
radius=.03*rad,
length=.04*rad,
color=color.red)
sHl, mHl, hHl = sHand.length, mHand.length, hHand.length

for nbTicks, size in ((13, .1), (61, .04)):
for theta in np.linspace(0, 2*pi, nbTicks):
ax=vector(rad*cos(theta), rad*sin(theta), 0)
box(axis=ax,
pos=ax*.9,
size=vector(rad*size, rad*.015, .01),
color=color.black)

while True:
rate(1)
hour, minute, second =

sAng = second * pi / 30
mAng = (sAng + minute * 2 * pi) / 60
hAng = (mAng + hour * 2 * pi) / 12

sHand.axis = vector(sHl*sin(sAng), sHl*cos(sAng), 0)
mHand.axis = vector(mHl*sin(mAng), mHl*cos(mAng), 0)
hHand.axis = vector(hHl*sin(hAng), hHl*cos(hAng), 0)

jeas
Автор

Thanks for your time and trouble in putting these lessons together for us. Since I'm not (nor was) a professional programmer I am learning a lot from you. All the best to you and your family!

leeg.
Автор

Thanks a lot for a clear lesson. I am legend with hour and minute hands moving in sync with the second hand.

daviddirac
Автор

Loving the V-Python Lessons Paul! I automatically synced the hands together on first build, I love the maths problems!

berryblades
Автор

Thank you for another interesting home work assignment. I am legend - sort of, I got it to tell accurate time to the second based on the system clock but I am sure the solution you are about to show in this lesson will be much more elegant. Thank you again!

pokerface
Автор

Apparently I got ahead. I AM LEGEND. I used datetime instead of time so that I could have the fraction of a second and have all hands working smoothly around the clock.

chris
Автор

I am legend! *thump* *thump* - thanks, Paul!

thomasszymanski
Автор

I am Legend..Thanks Paul for coming up with these amazing lessons <3

riyanshugupta
Автор

I am legend! I tried doing it for 3 hours and made it!! very proud of myself

alonb
Автор

Ok, question. This started a few lessons back. You had to change your angle position to the top by adding pi/2. I did not! Top is position 0 for me!? 🤷‍♂️. And then following along in this lesson, I did not have to flip the formula by adding a negative "-(minute/60)*2pi.... ". By doing so it it made the hand move backwards. Then I got to looking over my program and discovered a big difference. When I initially built this program, I reversed the cos and sin positions when I set up the hand.axis in attempt to get the hands to turn clockwise instead of counterclockwise. It worked, so I left it and forgot about it. So my question is, why not? It eliminated a lot of the extra coding that you had to do. It put the 0 position at the top, and it made the hands move clockwise.

wayneswan
Автор

I am following eagerly Sir Paul, interesting as math minded

edgarpanunciolobitana
Автор

Minute and hour hand now sweeping smoothly and the time is spot on to the second according to the windows clock on the taskbar. Resource wise this is an expensive little clock for a Dell notebook with an i5-6300U processor. Task manager reckons that python is using 30% of cpu time. P.S. I really liked my ticking minute hand 😄

martinjones
Автор

Really a fun and exciting lesson.. Learn a lot and eagerly waiting for the hardware project. Thank u sir.

pralaymajumdar
Автор

Those lawn chairs are starting to accumulate! My second hand only seems to align with my tick marks at 12, 3, 6, & 9. It seems to align just a bit off on the remaining tick marks.

codecage
Автор

Hi Paul. Can I ask, for this homework do the minute and hour hands need to sweep smoothly or can they move in discrete steps ie minute hand move every second and hour hand every minute?
I've managed to do the latter but any smooth movement has me stumped.
And thank you so much for your excellent content.

airwavested
Автор

Hello Paul,

Love your teaching lessons !!!! I understand your thoughts on not posting the code with one exception. I am 73 years old and have worked with hardware my whole career. I have no interest in becoming a software engineer as I am retired. I suffered a TBI (traumatic brain injury) in a bad accident in 2014 and have short term memory issues. With the complete listing I can study the code at my own speed and go over it multiple times and work with it. I am sure others may have similar issues. Programming is a hobby for me and again no intension to make it a career. I like programming as it challenges and helps me with my cognitive issues. You may find if you posted you code you might possibly get more subscribers. Thanks again for all your hard work

rbonari
Автор

Already had th eminute and hour hand smoothly moving fractionally

stefanonicolini