LB Booster
« animation : tower of hanoi »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 04:43am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: animation : tower of hanoi  (Read 238 times)
bluatigro
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 111
xx animation : tower of hanoi
« Thread started on: Jul 8th, 2016, 09:37am »


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


 
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: animation : tower of hanoi
« Reply #1 on: Jul 8th, 2016, 12:42pm »

See my post here for how to improve the performance of this program in LBB.

Richard.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls