Scratch Advanced – Challenge 17 – Time

Time

Questions.

How do we measure it?

Why are there 60 minutes in an Hour?   Why are there 24 Hours in a Day?

Why are there 365 Days in a Year?

Answers.

We have to go back in History to find out why we 60 in time quite a lot. It is thanks to the Babylonians that we have the modern day usage of 60 seconds in a minute and 60 minutes in an hour and even 360 degrees in a circle (60 x 6)

The reason that they used 60 is because it can be divided by a lot of different numbers, for example:

60 /  1 = 60

60 /  2 = 30

60 /  3 = 20

60 /  4 = 15

60 /  5 = 12

60 /  6 = 10

60 / 10 =  6

60 / 12 =  5

60 / 15 =  4

60 / 20 =  3

60 / 30 =  2

60 / 60 =  1

And for the 24 Hours in a Day, we have to thank the Egyptians who came up with that idea. They actually used 12 for Day time and 12 for Night time. But it wasn’t till a lot later that each of these 12 parts became the same length of time.

So what is a day? Well as most of you know it is the time it takes for the earth to turn round once on it’s axis.

This isn’t strictly true though  as it only takes the earth 23hr and 56 minutes to spin once, the extra four minutes are taken up by turning to face the sun properly again.

So you should strictly say that 24 hours is the time it takes the Earth to face the Sun again, when you measure from Noon on one day to Noon on the next day.

And finally 365 days in the year, again this is something that we all know, it’s the number of days that it takes for the Earth to travel once around the Sun.

We have an Experiment we can do here as well.

If the Sun is the size of a Football, how big is the Earth and how far away will it be to be in scale?

And just out of interest here are some other planets years:

Mercury 88 days

Venus 224 days

Mars 687 days

Jupiter 4331 days

Saturn 10832 days

Uranus 307999 days

Neptune 60190 days

and finally poor old Pluto 90520 days, which is roughly 248 Earth Years.

So what does all this have to do with Computers, well all Computers have a clock and calendar in them to tell the time, so we are going to build one in Scratch, this will hopefully demonstrate how something that we take for granted and don’t even think about very much can become quite complex when you try and convert it into a Computer program.

Some of the things that you will have to think about:

1. The days in each month are not the same.

2. The hour hand does two circuits of the clock, the minute and second only one before the next thing changes.

3. Leap years. This is a fun one.

4. Daylight Savings Time (DST) When does it happen and which way do the clocks go?

We will need a few Sprites:

1. Second Hand

2. Minute Hand

3. Hour Hand

4. Clock Face

5. Day of Month

6. Month

7. Year

Now for the coding. Although we think of time in 60 minutes and 12 hours, all the hands on the clock actually need to turn through 360 degrees, so it is easier to code with that in mind rather than 60 seconds for example.

So, if you have your sprites setup, you will need some variables to store the position of each hand. Once you have those, you can put the code together, something  like this to initialise all your variables:

GreenFlag

 

 

 

 

 

 

 

And then as you can see I am broadcasting Start which contains the main code like this:

Start

 

 

 

 

 

 

 

 

 

 

 

 

 

And for each of the hands,  something like this should be enough:

 

The +90 is because Scratch has 0 degrees pointing LEFT, not UP!

SecondHand

 

 

The full Scratch project has been uploaded to the Scratch WebSite as well, for those of you who want to cheat :).

One thought on “Scratch Advanced – Challenge 17 – Time

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s