00:01
Good day, ladies and gentlemen.
00:06
Today we're looking live at probe number 9 -11 in the great python book.
00:14
It is to display a clock.
00:18
And the basic idea is we're supposed to write a program to display a clock as shown in figure 9 .27a.
00:34
One important thing is that this clock, at least, is not constantly updating.
00:42
That will probably be a problem for another day.
00:46
This one just displays the current time.
00:50
So it's a little different problem.
00:53
It would be constantly updating.
00:55
It's a little different.
00:56
That would be an interesting one to do.
00:58
But that's not what we're doing here.
01:01
Okay.
01:03
So this, let me just, let's start with what we have to do.
01:13
So first off, i'm not really going to go into how to convert, how to get the time.
01:25
Basically, what i did.
01:28
I didn't use the date time module.
01:31
I actually used.
01:33
Used the time dot time explanate or time dot time that he did in done in a previous section.
01:48
So i just used the previous section material to get the time.
01:58
So that gives you, you know, he goes through a whole explanation as how he he does it there, but basically you end up calculating a current hour, a current minute, and a current second, okay? and he explains it all in that section, so i'm not going to go back over it.
02:29
But if we look at, so if we look at what we're trying to do here, you know, we're trying to create this clock like this that has hands.
02:47
So if like right now it's almost five o 'clock.
02:50
So maybe i'll draw it like this, something like this.
02:58
You know, something, i don't know what the seconds are, but maybe something like that.
03:04
And all of this, of course, will be on a, on a canvas object, which is, of course, lying on a tk, or a canvas widget which lies on a tk object.
03:25
So the question that really, you know, of course, the normal stuff, which i've already covered in previous videos about, you know, getting, instantiating the window equals to tk, you know, getting that, and then canvas equals to canvas, you know, all of this stuff we've already talked about before.
03:56
This one, there's a couple challenges here.
04:00
First off, of course, we're going to need the, we're going to need the oval or the, i guess, outside that block, which of course is pleased to my eye.
04:15
It's a circle, but we used to create oval.
04:22
And we use a collection of points, x1, y1, x2, y2.
04:34
And of course, just as a reminder here, the x1, 1 y1 of course come from well it's not quite but the x1 y1 point um maybe i do it like this instead um yeah so if we if i draw this you know which of course i'm not very good at but if i draw something like this basically the box the exact box that contains a circle um which, of course, my circle is not really a good circle either, but the x1, y1 coordinate comes from up here.
05:23
Okay, it's normal.
05:27
The x1 y1 coordinates are up here, whoops, x1, i1 are up there, and the x2 y2 come from down here.
05:38
And i know by now you probably already know this, so it's not too much stupid for me to mention it, but i thought i would.
05:49
Anyhow, there are basically these coordinates, and of course they have to do with the radius of the circle.
05:57
And i want this point here, i'm going to label this point here as a, as a -b, okay? so this point here is going to be a -b.
06:16
And it refers to the center of the circle or the, yeah, the center of the circle, okay? so part of the, you know, the create oval is fine.
06:30
I mean, that's, that's simple.
06:33
The real issue, i think, with this problem is getting the hands, you know, getting the hands correct.
06:40
So it kind of becomes a question as to how do we draw those hands? and let's dig a little bit more into that.
06:49
So if we look at it, we have the point here.
06:54
And then we have just some, god, i wish i could draw a straight line.
07:02
So we have this line.
07:06
And then we have this point here would be, here would be x, y.
07:15
So it would be x, y.
07:16
Y and of course this point here is a b and now of course we're going to fix the radius of this guy at some number so the the radius of course or the length of it if you will the radius um is fixed at some value are now i think once you you might start to see where these numbers come from so now now let's draw the corresponding right triangle here.
07:54
So because we have a hypotenuse, so we can draw a triangle, of course.
08:01
So let's draw the triangle.
08:07
Oops.
08:08
Boy, i just wish i could draw a straight line.
08:12
Okay, so now once we have this, now this length here, of course, the length of it is r times, let me see, it's r, yeah, this angle here, which will denote as maybe as a theta.
08:45
Okay.
08:46
This length is, come on, kids, do you know what it is? can you, do you know? it is r times sign of the theta.
09:06
So i'll just write it out there.
09:08
So it's r times the sign of the theta.
09:11
And this one up here is r times the cosine of the theta.
09:17
R times the cosine.
09:22
Good job.
09:23
Excellent work.
09:25
Obviously you've been studying.
09:27
Congratulations.
09:27
So from this observation, we can get x and y.
09:37
Oh, i'm sorry, look at that.
09:39
I messed up.
09:41
I am sorry.
09:43
Thank you for pointing that out.
09:44
Timothy, you're correct.
09:46
This is sine theta.
09:49
This is cosine.
09:50
Boy, thank you.
09:51
You guys are bright.
09:53
Yes, it is cosine.
09:55
That is the cosine.
09:56
And that is the sign.
10:00
Yes, thank you.
10:02
So we can get using these two equations, we can get that, we can get y and x here.
10:10
We can get that x is equal to a plus r times sine theta, and we can get y equals to b, minus r cosine.
10:36
Yeah, it's important to remember that because the, what's gonna call it? the x coordinates descend as we go in that direction...