Digital or analog?
Offline
You'd need a way to print the numbers and a way to get the starting time. Many simply ask their users to put in the current time. I'd then reset the timer and do this:
set [hours] to ((original hour) + (round( (timer/3600)-.5) ) mod [12]
set [minute] to ( ( (original minute) + (round((timer/60)-.5) ) ) mod [60]
I think that's the script
I'd put it in scratchblocks, but I guess it doesn't work for that many operators.
Last edited by MoreGamesNow (2012-03-04 22:24:07)
Offline
Or, if you use timer for something else, use
when flag clicked forever change [seconds v] by (1) if <(seconds) > (59)> set [seconds v] to (0) change [minutes v] by (1) end if <(minutes) > (59)> set [minutes v] to (0) change [hours v] by (1) end if <(hours) > (23)> set [hours v] to (0) end wait (0.99) secs endAlthough this clock can be a little off.
Last edited by aryabtsev (2012-04-03 18:01:56)
Offline
If you are going to do a regular (old-style, non-digital) clock, create a minute hand sprite and a second hand sprite, along with a sensor sprite positioned at the twelve.
Second hand:
when gf clicked forever repeat until < (touching [sensorsprite v]) > if <(timer)> > (1) reset timer turn (6) degrees end if < (touching [sensorsprite v]) > broadcast [minute]And then for the minute hand:
forever when i receive [minute] turn (6) degreesIf you wanted to do hours, you'd do, in the "minute hand" sprite, a "broadcast hour" block
broadcast [hour]And then you'd do for the hour scripts exactly what you did for the minute hand, except for the hour hand you'd turn 30 (360/12) degrees instead of 6 degrees.
Offline
mythbusteranimator wrote:
If you are going to do a regular (old-style, non-digital) clock, create a minute hand sprite and a second hand sprite, along with a sensor sprite positioned at the twelve.
Second hand:when gf clicked forever repeat until < touching [sensorsprite v]? > if <(timer) > (1)> reset timer turn cw (6) degrees end if < touching [sensorsprite v]? > broadcast [minute v]And then for the minute hand:
forever when i receive [minute v] turn cw (6) degreesIf you wanted to do hours, you'd do, in the "minute hand" sprite, a "broadcast hour" block
broadcast [hour v]And then you'd do for the hour scripts exactly what you did for the minute hand, except for the hour hand you'd turn 30 (360/12) degrees instead of 6 degrees.
I hope you found my information helpful. Unless, of course, you are not doing a normal clock and are in fact doing a digital clock. In that case, I just wasted about twenty minutes. JK
Scratchblocks fixed.
Offline
MoreGamesNow wrote:
You'd need a way to print the numbers and a way to get the starting time. Many simply ask their users to put in the current time. I'd then reset the timer and do this:
set [hours] to ((original hour) + (round( (timer/3600)-.5) ) mod [12]
set [minute] to ( ( (original minute) + (round((timer/60)-.5) ) ) mod [60]
I think that's the script
I'd put it in scratchblocks, but I guess it doesn't work for that many operators.
You don't need a way to print.
You could always just have 4 each number place in the clock. First and third sprite would have costumes that have the numbers 1 through 5.
And the second and fourth would have costumes that have the numbers 1 through 9.
Seems like a lot, but it works.
Offline
ProgrammingFreak wrote:
MoreGamesNow wrote:
You'd need a way to print the numbers and a way to get the starting time. Many simply ask their users to put in the current time. I'd then reset the timer and do this:
set [hours] to ((original hour) + (round( (timer/3600)-.5) ) mod [12]
set [minute] to ( ( (original minute) + (round((timer/60)-.5) ) ) mod [60]
I think that's the script
I'd put it in scratchblocks, but I guess it doesn't work for that many operators.You don't need a way to print.
You could always just have 4 each number place in the clock. First and third sprite would have costumes that have the numbers 1 through 5.
And the second and fourth would have costumes that have the numbers 1 through 9.
Seems like a lot, but it works.
The first only needs a one. xD
Offline
ProgrammingFreak wrote:
MoreGamesNow wrote:
You'd need a way to print the numbers and a way to get the starting time. Many simply ask their users to put in the current time. I'd then reset the timer and do this:
set [hours v] to <<(original hour) + <round <<<timer>/[3600]>-[0.5]>> > mod [12]> set [minute v] to << (original minute) + <round<<<timer>/[60]>-[.5]> > > mod [60]>I think that's the script
I'd put it in scratchblocks, but I guess it doesn't work for that many operators.You don't need a way to print.
You could always just have 4 each number place in the clock. First and third sprite would have costumes that have the numbers 1 through 5.
And the second and fourth would have costumes that have the numbers 1 through 9.
Seems like a lot, but it works.
It does work with that many operators. Never underestimate the power of scratchblocks!
Offline
well, you could do this for the counting:
when gf clicked set [secs v] to (0) set [mins v] to (0) set [hrs v] to (0) // you can set them to something else or let the user enter values forever wait (1) secs change [secs v] by (1) if <(secs) = (60)> set [secs v] to (0) change [mins v] by (1) if <(mins) = (60)> set [mins v] to (0) change [hrs v] by (1) if <(hrs) = (24)> set [hrs v] to (0) end end end broadcast [display v]If you want it more accurate, or if you wanted it to be a stopwatch, you can use the timer:
when gf clicked set [set secs v] to (0) //these are the variables you need to set [set mins v] to (0) //change if you want to set the time yourself set [set hrs v] to (0) reset timer forever set [secs v] to ((round ((timer) - (5))) + (set secs)) // round down to nearest integer set [millisecs v] to (((timer) - (secs)) * (1000)) set [mins v] to (round ((((secs)/(60)) - (5)) + (set mins)) set [secs v] to ((secs) mod (60)) set [hrs v] to (round ((((mins)/(60)) - (5)) + (set hrs)) set [mins v] to ((mins) mod (60)) set [hrs v] to ((hrs) mod (24)) broadcast [display v] and waitIf you wanted it to be a stopwatch counting down,
when gf clicked all of the old code, replacing every (timer) with ((((set hrs) * (3600)) + (((set mins) * (60)) + (set secs))) - (timer))Note that changing the time is more complicated than before, so do
when i receive [change time v] ask [new hours? (-1 to keep it the same)] and wait if <(answer) > [0]> set [set hrs v] to (answer) else set [set hrs v] to (hrs) end ask [new minuites? (-1 to keep it the same)] and wait if <(answer) > [0]> set [set mins v] to (answer) else set [set mins v] to (mins) end ask [new seconds? (-1 to keep it the same)] and wait if <(answer) > [0]> set [set secs v] to (answer) else set [set secs v] to (secs) end reset timerNow for the display if you want analogue, you need 3 sprites, for the hour hand, minute hand, and second hand. They should all be straight lines pointing up with the hour hand shorter than the rest and the second hand a different colour to the rest. Set the costume centre of each one to the end of the line, and put them all at the same position. Give each one a LOCAL (for this sprite only) variable called point at.
when i receive [display v] set [point at v] to ((hrs) * (30)) set [point at v] to ((point at) + (((mins) / (60)) * (30))) point in direction (point at)In the minute hand:
when i receive [display v] set [point at v] to ((mins) * (6)) set [point at v] to ((point at) + (((secs) / (60)) * (6))) point in direction (point at)In the second hand:
when i receive [display v] set [point at v] to ((secs) * (6)) point in direction (point at)Now, if you want digital, it is slightly easier.
when gf clicked // This script is so the colons in the display flash each second set [colons? v] to (0) //if you don't want that, forever set [colons? v] to ((1) - (colons?) wait (1) secs when i receive [display v] if <(display) = [24hour]> if <(colons?) = (1)> set [time v] to (join (hrs) (join [:] (join (mins) (join [:] (secs)) else set [time v] to(join (hrs) (join [ ] (join (mins) (join [ ] (secs)) end stop script end if <(display) = [stopwatch]> if <(colons?) = (1)> set [time v] to (join (hrs) (join [:] (join (mins) (join [:] (join (secs) (join [:] (milisecs))))))) else set [time v] to (join (hrs) (join [ ] (join (mins) (join [ ] (join (secs) (join [ ] (milisecs))))))) end stop script end if <(display) = [12hour]> if <(colons?) = (1)> if <<(hrs) = (0)> or <(hrs) = (12)>> set [time v] to [12] else set [time v] to (hrs) end set [time v] to (join (time) (join [:] (join (mins) (join [:] (secs)) if <(hrs) < (12)> set [time v] to (join (time) [ AM]) else set [time v] to (join (time) [ PM]) end else if <<(hrs) = (0)> or <(hrs) = (12)>> set [time v] to [12] else set [time v] to (hrs) end set [time v] to (join (time) (join [ ] (join (mins) (join [ ] (secs)) if <(hrs) < (12)> set [time v] to (join (time) [ AM]) else set [time v] to (join (time) [ PM]) end end endThen you can just show the variable time. If you want it bigger, get a sprite with a costume for each digit plus a colon, and add this script to the end of the above script:
set [index v] to (0) go to x:(xpositionoftime) y:(ypositionoftime) repeat until <(index) = (length of (time))> change [index v] by (1) if <(letter (index) of (time)) = [ ]> move (20) steps stop script end if <(letter (index) of (time)) = [0]>// costumes with numerical names automaticly // change to "01", "11", "21", ect... so there is no costume 0. switch to costume [01 v] else switch to costume (letter (index) of (time)) end stamp move (20) steps endHope that helps!
Last edited by joefarebrother (2012-04-11 06:06:36)
Offline