It's a working clock. I tested this for an hour and it keeps good time,
This moves the gears once a minute. Maybe you could add seconds.
You can set the time by pressing s and Esc to quit.
Code: Select all
#cmdline "-s gui"
#define pi (4*atn(1))
screenres 850, 525, 32, 2
screenset 0, 1
dim as double R, X1, Y1, X2, Y2, X3, Y3, X4, Y4, ao
Dim as String t,hrs,min,sec,minchange
dim as string key
do
t = Time
hrs = Left(t, 2)
min = Mid(t, 4, 2)
sec = Right(t, 2)
cls
draw string (5, 5), "Press S to set Clock, Esc to quit."
draw string (500, 210), "Minute, 5 teeth, driven", rgb(128, 255, 0)
draw string (500, 230), "Hour, 16 teeth, fixed on a tube", rgb(255, 128, 0)
draw string (500, 350), "Change gear, coupled wheels", rgb(255, 255, 0)
draw string (500, 370), "Large: 15 teeth, small: 4 teeth", rgb(255, 255, 0)
for A as single = 0 to 2*pi step 0.001
R = 100 + cos(16 * A) * 15 ' Hour, 16 teeth
X1 = sin(A - ao) * R + 240
Y1 = cos(A - ao) * R + 220
R = 30 + sin(-4 * A + 11) * 10 ' Change gear (small), 4 teeth
X2 = sin(A + 4 * ao) * R + 240
Y2 = cos(A + 4 * ao) * R + 360
R = 100 + cos(15 * A) * 15 ' Change gear (large), 15 teeth
X3 = sin(A + 4 * ao) * R + 240
Y3 = cos(A + 4 * ao) * R + 360
R = 30 + sin(-5 * A - 11) * 15 ' Minute, 5 teeth, driven
X4 = sin(A - 12 * ao) * R + 240
Y4 = cos(A - 12 * ao) * R + 220
if A = 0 then
line(240, 220) - (0.8 * (240 - X1) + 240, 0.8 * (220 - Y1) + 220)
line(240, 360) - (X3, Y3),,, &b1010101010101010
line(240, 220) - (4 * (240 - X4) + 240, 4 * (220 - Y4) + 220)
end if
pset (X1, Y1), rgb(255, 128, 0)
pset (X2, Y2), rgb(255, 255, 0)
pset (X3, Y3), rgb(255, 255, 0)
pset (X4, Y4), rgb(128, 255, 0)
pset (X1+1, Y1+1), rgb(255, 128, 0)
pset (X2-1, Y2-1), rgb(255, 255, 0)
pset (X3+1, Y3), rgb(255, 255, 0)
pset (X4-1, Y4), rgb(128, 255, 0)
pset (X4-2, Y4), rgb(128, 255, 0)
next A
ao = ao + pi/360
flip
screensync
Do
t = Time
minchange = Mid(t, 4, 2)
If minchange <> min Then Exit do '' minute changed
If Multikey(&H1F) Then Exit do ''set time press s
If Multikey(&H01) Then End '' exit program Esc key
sleep 100,1 ''lowers cpu usage
Loop
Loop