Very nice and fun exercise, loved it! I'm learning Python (JS dude here) and this is a great help, thank you Christian. The only point which could be mentioned is the code for drawing the hands could be DRYer. Here's what I refactored: ``` # Draw the hands # Each tuple in list hands describes the color, the length # and the divisor for the angle hands = [("white", 80, 12), ("blue", 150, 60), ("red", 110, 60)] time_set = (hr, mn, sec) for hand in hands: time_part = time_set[hands.index(hand)] angle = (time_part/hand[2])*360 pen.penup() pen.goto(0, 0) pen.color(hand[0]) pen.setheading(90) pen.rt(angle) pen.pendown() pen.fd(hand[1]) ```
@@TokyoEdTech Understood. Although one could say that it's never too early to learn good coding practice, as refactoring and DRY code are essential skills in real world. Plus it's another place to apply loops, another pillar of any coding language.
Hello! Im really enjoying all ur tutorials, and im enjoy making simple python games. I was wondering if u could make a tutorial on how to make the classic «snake» game :-)
Christian Thompson thanks. I never had a RUclipsd actually reply to my comments. This comment is really important because I want to end up using python for robotics and I was struggling on the right path to go towards it. So thanks
Christian Thompson good thing math is my best subject and favorite. But I’m just a freshman in highschool that likes to code so I’m not quite ready for that yet.
I’m happy to help, but I need to see the actual code. Please share your code via pastebin.com link so I can download and test it. To learn how, please watch this video and then get back to me: ruclips.net/video/L6AwVuu6O3Y/видео.html Keep on codin’!
I'm terrible at math, I couldn't understand the equation angle = (h / 12) * 360.. and how it splits the clock in 12 parts but I understand when it's written backwards like angle = (360 / 12) * h. for some reason I was stumped for a good 15 minutes trying to understand the method I almost wanted to just memorize it instead edit: just realized I didn't thank you for the instructional, the video was very helpful
Very nice and fun exercise, loved it! I'm learning Python (JS dude here) and this is a great help, thank you Christian.
The only point which could be mentioned is the code for drawing the hands could be DRYer. Here's what I refactored:
```
# Draw the hands
# Each tuple in list hands describes the color, the length
# and the divisor for the angle
hands = [("white", 80, 12), ("blue", 150, 60), ("red", 110, 60)]
time_set = (hr, mn, sec)
for hand in hands:
time_part = time_set[hands.index(hand)]
angle = (time_part/hand[2])*360
pen.penup()
pen.goto(0, 0)
pen.color(hand[0])
pen.setheading(90)
pen.rt(angle)
pen.pendown()
pen.fd(hand[1])
```
@@TokyoEdTech Understood. Although one could say that it's never too early to learn good coding practice, as refactoring and DRY code are essential skills in real world. Plus it's another place to apply loops, another pillar of any coding language.
very good channel! thank you make these great tutorial!
Excellent lesson. Thank you so much.
Glad you liked it!
Hey, just asking is this code still up to date?
I think it will still work - there haven't been that many changes to the turtle module. If you run into any problems let me know.
Bring him to 100k subs
Hello!
Im really enjoying all ur tutorials, and im enjoy making simple python games. I was wondering if u could make a tutorial on how to make the classic «snake» game :-)
When it is 2.45PM the hour hand should not be on 2 o’clock but somewhere between 2 and 3 o’clock. How to make this to happen, can u help me?
Ok i will try. thank you..
you can also use this:
angle = (30 * h) + (m / 2)
What does pen.rt (angle) do
hi
tanx for the tutorial but in the lines *angle = (h / 12)*360* it shows* "h" is not defined*
It really depends on your code - you'd have to share it for me to take a look and help you.
That's right man get those bugs out
Hey do u know the best way to start learning python for eventually using it in robotics and not games?
Or just learning python for robotics
Christian Thompson thanks. I never had a RUclipsd actually reply to my comments. This comment is really important because I want to end up using python for robotics and I was struggling on the right path to go towards it. So thanks
Christian Thompson good thing math is my best subject and favorite. But I’m just a freshman in highschool that likes to code so I’m not quite ready for that yet.
It is shwoing the h,m,s has an undefined variable plzz helppp
I’m happy to help, but I need to see the actual code. Please share your code via pastebin.com link so I can download and test it. To learn how, please watch this video and then get back to me: ruclips.net/video/L6AwVuu6O3Y/видео.html Keep on codin’!
Can you make custom hands?
@@TokyoEdTech how?
I'm terrible at math, I couldn't understand the equation angle = (h / 12) * 360.. and how it splits the clock in 12 parts but I understand when it's written backwards like angle = (360 / 12) * h. for some reason I was stumped for a good 15 minutes trying to understand the method I almost wanted to just memorize it instead
edit: just realized I didn't thank you for the instructional, the video was very helpful
Please give source
How to use numbers in clock? can anybody help
please anyone help me.
Ok. Thank you..
it keeps telling me that h is not defined
@@TokyoEdTech #Analog clock
import turtle
import time
#Window
wn = turtle.Screen()
wn.setup(width=750, height=750)
wn.bgcolor("light blue")
wn.title("Analog Clock")
wn.tracer(0)
#Clock Face
myTurtle = turtle.Turtle()
myTurtle.speed(0)
myTurtle.hideturtle()
def draw_clock(h, m, s, myTurtle):
myTurtle.penup()
myTurtle.goto(0,360)
myTurtle.setheading(180)
myTurtle.color("black")
myTurtle.pensize(3)
myTurtle.pendown()
myTurtle.circle(360)
#Lines on clock for hours
myTurtle.penup()
myTurtle.goto(0,0)
myTurtle.setheading(90)
for _ in range(12): #This is just the centre of the clockface
myTurtle.fd(2)
myTurtle.pendown()
myTurtle.fd(20)
myTurtle.penup()
myTurtle.goto(0,0)
myTurtle.rt(30)
for _ in range(12): #This adds the no. lines to the clockface
myTurtle.fd(340)
myTurtle.pendown()
myTurtle.fd(20)
myTurtle.penup()
myTurtle.goto(0,0)
myTurtle.rt(30)
#Clock hands Hours
myTurtle.color("pink")
myTurtle.pensize(3)
def Draw_HourHand(myTurtle):
myTurtle.penup()
myTurtle.goto(0,0)
myTurtle.setheading(90)
myTurtle.pendown()
myTurtle.fd(200)
angle = (h / 12) * 360
myTurtle.rt(angle)
myTurtle.penup()
myTurtle.goto(0,0)
myTurtle.clear()
wn.update()
myTurtle.pendown()
myTurtle.fd(200)
Draw_HourHand(myTurtle)
#Clock hands Minutes
myTurtle.color("purple")
def Draw_MinuteHand(myTurtle):
myTurtle.penup()
myTurtle.goto(0,0)
myTurtle.setheading(180)
myTurtle.pendown()
myTurtle.fd(250)
Draw_MinuteHand(myTurtle)
#Clock Hands Seconds
myTurtle.color("dark blue")
def Draw_SecondsHand(myTurtle):
myTurtle.penup()
myTurtle.goto(0,0)
myTurtle.setheading(210)
myTurtle.pendown()
myTurtle.fd(150)
Draw_SecondsHand(myTurtle)
while True:
h = int(time.strftime("%I"))
m = int(time.strftime("%M"))
s = int(time.strftime("%S"))
draw_clock(h, m, s, myTurtle)
wn.update()
time.sleep(1)
wn.mainloop()
error: name h is not defined
@@TokyoEdTech Don't worry I changed my code completely so this is no longer an issue.
Please help him to reach 100k
Yes, please! :)