WARNING :
make number not to great
Code:
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy , number , pi , speed
number = 4
pi = atn(1)*4
speed = 10
dim x(number),y(number),size(number),kl$(number),p(3)
winx = WindowWidth
winy = WindowHeight
for i = 0 to 3
p(i)=i*winx/4
next i
for i = 0 to number
x(i)=p(1)
y(i)=winy-number*40+i*40-150
size(i)=i*100/number+20
kl$(i)=rainbow$(i*360/(number+1))
next i
nomainwin
open "HANOI" for graphics as #m
#m "trapclose [quit]"
call hanoi number+1 , 1 , 2 , 3
notice "ready"
wait
[quit]
close #m
end
sub move s , t
for i = number to 0 step -1
if x(i)=p(s) then h=i
next i
q = y(h)
for i = q to 100 step 0-speed
y(h)=i
call show
next i
if s < t then
for i = p(s) to p(t) step speed
x(h)=i
call show
next i
else
for i = p(s) to p(t) step 0-speed
x(h)=i
call show
next i
end if
q = 0
for i = 0 to number
if x(i)=p(t) then q=q+1
next i
for i = 100 to winy - q * 40 - 110 step speed
y(h)=i
call show
next i
end sub
sub show
scan
#m "fill black"
for i = 0 to number
#m "color ";kl$(i)
#m "backcolor ";kl$(i)
#m "goto ";x(i)-size(i);" ";y(i)-20
#m "down"
#m "boxfilled ";x(i)+size(i);" ";y(i)+20
#m "up"
next i
CallDLL #kernel32, "Sleep" _
, 20 As long _
, ret As void
end sub
sub hanoi n , s , t , b
if n = 1 then
call move s , t
print "moving ";s;" to ";t
else
call hanoi n-1 , s , b , t
call hanoi 1 , s , t , b
call hanoi n-1 , b , t , s
end if
end sub
function rad( deg )
rad = deg * pi / 180
end function
function rainbow$( deg )
r = int(sin( rad( deg ) ) * 127 + 128)
g = int(sin( rad( deg-120 ) ) * 127 + 128)
b = int(sin( rad( deg+120 ) ) * 127 + 128)
rainbow$=str$(r)+" ";g;" ";b
end function