Turing analogclock help
Author |
Message |
WOAH123
|
Posted: Thu Nov 27, 2008 11:25 am Post subject: Turing analogclock help |
|
|
ok for my computer class we are working with turing and i have made a roguh analog clock for my upcoming project but what i am having trouble is with have it display the proper time. I got the hands to move but i am not sure how to make the hands move to the proper time. If you could tell me that would be awesome
Turing: |
View.Set ("graphics:max;max")
View.Set ("offscreenonly")
var x, y : int
var x1, y1 : int
var numberFont := Font.New ("Castellar:48:")
var numberFont2 := Font.New ("Castellar:25:")
var timeOfday : string
var hours : int
var minutes : int
var seconds : int
var SECS: int
var nHours : int
var DATE : string
x := 100
y := 100
x1 := 100
y1 := 100
time (timeOfday )
%hours := timeOfday (1 .. 2)
%minutes := timeOfday (4 .. 5)
%seconds := timeOfday (7 .. 8)
%nHours := strint (hours)
loop
Draw.Oval (x + 400, y + 225, x1 + 200, y1 + 200, red)
Draw.Fill (x + 401, y + 226, red, red)
Draw.Oval (x + 400, y + 225, x1 + 175, y1 + 175, white)
Draw.Fill (x + 401, y + 226, white, white)
Font.Draw ("I", 625, 475, numberFont, black)
Font.Draw ("II", 675, 400, numberFont, black)
Font.Draw ("III", 675, 300, numberFont, black)
Font.Draw ("IV", 650, 200, numberFont, black)
Font.Draw ("V", 600, 100, numberFont, black)
Font.Draw ("VI", 465, 75, numberFont, black)
Font.Draw ("VII", 325, 100, numberFont, black)
Font.Draw ("VIII", 250, 200, numberFont, black)
Font.Draw ("IX", 240, 300, numberFont, black)
Font.Draw ("X", 265, 400, numberFont, black)
Font.Draw ("XI", 325, 475, numberFont, black)
Font.Draw ("XII", 445, 525, numberFont, black)
%put timeOfday
Draw.Oval (x + 400, y + 225, x1 - 85, y1 - 85, black)
Draw.Fill (x + 400, y + 225, black, black)
time (timeOfday )
nHours := strint(timeOfday (7.. 8))
seconds := strint(timeOfday (7.. 8))
seconds := 360-seconds* 6
time(timeOfday )
Draw.FillArc (x + 400, y + 225, 200, 200, seconds, seconds+ 1, 12) %seconds hand
nHours := strint(timeOfday (1.. 2))
hours := strint(timeOfday (1.. 2))
hours := 360-hours* 30
time(timeOfday )
Draw.FillArc (x + 400, y + 225, 170, 100, hours, hours+ 1, black) % hours hand
nHours := strint(timeOfday (4.. 5))
minutes := strint(timeOfday (4.. 5))
minutes := 360-minutes* 6
time(timeOfday )
Draw.FillArc (x + 400, y + 225, 200, 200, minutes, minutes+ 1, green) % minutes hand
time (timeOfday )
Font.Draw (timeOfday, maxx - 1000, maxy - 150, numberFont2, black)
date (DATE )
Font.Draw (DATE, maxx - 1000, maxy - 180, numberFont2, black)
exit when hasch
delay (50)
View.Update
delay (1000)
exit when hasch
Font.Draw (timeOfday, maxx - 1000, maxy - 150, numberFont2, white)
Font.Draw (DATE, maxx - 1000, maxy - 180, numberFont2, white)
end loop
|
Mod Edit: Remember syntax tags. code: | [syntax="Turing"]Code Here[/syntax] |
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
ecookman
![](http://compsci.ca/v3/uploads/user_avatars/5690458955648ca661c338.gif)
|
Posted: Thu Nov 27, 2008 11:26 am Post subject: RE:Turing analogclock help |
|
|
hmmm...i think the dalays are wrong...that might be the problem |
|
|
|
|
![](images/spacer.gif) |
S_Grimm
![](http://compsci.ca/v3/uploads/user_avatars/18926424384e6d86e5cf4d6.jpg)
|
Posted: Thu Nov 27, 2008 12:21 pm Post subject: RE:Turing analogclock help |
|
|
change the amout the second hand moves.
simpler terms.
make the second hand move less pixels each time
even simplerer terms.
the little red hand moves too far each time. |
|
|
|
|
![](images/spacer.gif) |
WOAH123
|
Posted: Fri Nov 28, 2008 9:07 am Post subject: Re: Turing analogclock help |
|
|
ok well im not too good at this and i dont really get how to change it, like if you could possibly type a code that would help it would be much aprecieated |
|
|
|
|
![](images/spacer.gif) |
ecookman
![](http://compsci.ca/v3/uploads/user_avatars/5690458955648ca661c338.gif)
|
Posted: Fri Nov 28, 2008 10:03 am Post subject: RE:Turing analogclock help |
|
|
if AV is right you just need to lower the amount of pixles each time i think this is done by chnaging the interval of which it moves to something smaller...i am not sure how to do it my self because i can't find the code for the second hand...and people aren't usually willing to do it for you...instead hint you in the right direction..ESPECALLY if it is school related |
|
|
|
|
![](images/spacer.gif) |
DanielG
|
Posted: Fri Nov 28, 2008 8:37 pm Post subject: RE:Turing analogclock help |
|
|
First of all, you should use Time.DelaySinceLast (1000) instead of delay (1000), as it gives better results.
Your actual mistake however is that you made a mistake in your drawing, everything is moved up 90 degrees (3 hours, 15 minutes, 15 seconds). I don`t get how you are drawing it (I would have used trig) |
|
|
|
|
![](images/spacer.gif) |
The_Bean
![](http://compsci.ca/v3/uploads/user_avatars/8459755754b4009cee84e9.jpg)
|
Posted: Fri Nov 28, 2008 10:38 pm Post subject: Re: Turing analogclock help |
|
|
Ok for one there is nothing wrong with the delays.
Actually you don't even need delays at all.
The arms of the clock are dependent on the time, and time comes from the time on your computer.
So the hands only move when the time changes, so delays do absolutely nothing other than slow down the refresh rate.
You have the movement of the hands correct with:
seconds moving 6 degree per second
minutes moving 6 degree per minute
hours moving 12 degree per hour
BUT
Your about 90 degrees behind where you should be.
at 0 seconds
360-0*6=360 -- so 0 seconds is at 360 degrees which is at '3' o-clock.
to fix this add 90 to all your formulas for the degrees.
hours := 360 - hours * 30 + 90
minutes := 360 - minutes * 6 + 90
seconds := 360 - seconds * 6 + 90
The y-radius on your hour hand is different from the x-radius
You should take into consideration the minutes and seconds into finding the degree for the hour hand
Aswell include the seconds in the minute hand. This will keep them from skipping, and make them move a bit more smoothly.
The position of the roman numerals are off.
Also you really need to clean up that code.
There are such things as Draw.FillOval instead of using Draw.Oval and Draw.Fill
You have a lot of useless variables, things that are repeated that don't actually do anything, and no cls when you should have one. |
|
|
|
|
![](images/spacer.gif) |
|
|