Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("Height: ")
- local w,h = term.getSize()
- local height = read()
- local blockh = h/height
- local scale = w/height/3
- local timescale = 0.5/(height/5+1)
- local blockcols = {colors.red,colors.orange,colors.yellow,colors.green,colors.cyan,colors.blue,colors.purple}
- local blocks = {{},{},{}}
- for i=1,height do blocks[1][i] = height-i+1 end
- local function draw_block(blockw,blocky,blockx)
- local drawx = w/3*(blockx-0.5)
- paintutils.drawBox(drawx-blockw/2*scale,
- h-(blockh*(blocky-1)),
- drawx+blockw/2*scale,
- h-blockh*blocky+1,
- blockcols[(blockw-1)%#blockcols+1])
- end
- local function move(a,b)
- print(a,b)
- table.insert(blocks[b],table.remove(blocks[a]))
- term.setBackgroundColor(colors.black)
- term.clear()
- for i=1,3 do
- for j=1,#blocks[i] do
- draw_block(blocks[i][j],j,i)
- end
- end
- sleep(timescale)
- end
- local function hanoi(h,a,b)
- a = a or 1
- b = b or 3
- if h==1 then
- move(a,b)
- return
- end
- local c=6-a-b
- hanoi(h-1,a,c)
- move(a,b)
- hanoi(h-1,c,b)
- end
- term.setBackgroundColor(colors.black)
- hanoi(height)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement