GRAYBYTE WORDPRESS FILE MANAGER5020

Server IP : 198.54.121.189 / Your IP : 216.73.216.140
System : Linux premium69.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
PHP Version : 7.4.33
Disable Function : NONE
cURL : ON | WGET : ON | Sudo : OFF | Pkexec : OFF
Directory : /usr/lib64/python3.8/turtledemo/
Upload Files :
Current_dir [ Not Writeable ] Document_root [ Writeable ]

Command :


Current File : /usr/lib64/python3.8/turtledemo//minimal_hanoi.py
#! /usr/bin/python3.8
"""       turtle-example-suite:

         tdemo_minimal_hanoi.py

A minimal 'Towers of Hanoi' animation:
A tower of 6 discs is transferred from the
left to the right peg.

An imho quite elegant and concise
implementation using a tower class, which
is derived from the built-in type list.

Discs are turtles with shape "square", but
stretched to rectangles by shapesize()
 ---------------------------------------
       To exit press STOP button
 ---------------------------------------
"""
from turtle import *

class Disc(Turtle):
    def __init__(self, n):
        Turtle.__init__(self, shape="square", visible=False)
        self.pu()
        self.shapesize(1.5, n*1.5, 2) # square-->rectangle
        self.fillcolor(n/6., 0, 1-n/6.)
        self.st()

class Tower(list):
    "Hanoi tower, a subclass of built-in type list"
    def __init__(self, x):
        "create an empty tower. x is x-position of peg"
        self.x = x
    def push(self, d):
        d.setx(self.x)
        d.sety(-150+34*len(self))
        self.append(d)
    def pop(self):
        d = list.pop(self)
        d.sety(150)
        return d

def hanoi(n, from_, with_, to_):
    if n > 0:
        hanoi(n-1, from_, to_, with_)
        to_.push(from_.pop())
        hanoi(n-1, with_, from_, to_)

def play():
    onkey(None,"space")
    clear()
    try:
        hanoi(6, t1, t2, t3)
        write("press STOP button to exit",
              align="center", font=("Courier", 16, "bold"))
    except Terminator:
        pass  # turtledemo user pressed STOP

def main():
    global t1, t2, t3
    ht(); penup(); goto(0, -225)   # writer turtle
    t1 = Tower(-250)
    t2 = Tower(0)
    t3 = Tower(250)
    # make tower of 6 discs
    for i in range(6,0,-1):
        t1.push(Disc(i))
    # prepare spartanic user interface ;-)
    write("press spacebar to start game",
          align="center", font=("Courier", 16, "bold"))
    onkey(play, "space")
    listen()
    return "EVENTLOOP"

if __name__=="__main__":
    msg = main()
    print(msg)
    mainloop()

[ Back ]
Name
Size
Last Modified
Owner / Group
Permissions
Options
..
--
March 05 2024 23:45:16
root / root
0755
__pycache__
--
March 05 2024 23:45:13
root / root
0755
__init__.py
0.307 KB
June 06 2023 13:32:21
root / root
0644
__main__.py
13.907 KB
October 17 2023 18:12:57
root / root
0644
bytedesign.py
4.147 KB
June 06 2023 13:32:21
root / root
0755
chaos.py
0.929 KB
June 06 2023 13:32:21
root / root
0644
clock.py
3.125 KB
June 06 2023 13:32:21
root / root
0755
colormixer.py
1.308 KB
June 06 2023 13:32:21
root / root
0644
forest.py
2.896 KB
June 06 2023 13:32:21
root / root
0755
fractalcurves.py
3.391 KB
June 06 2023 13:32:21
root / root
0755
lindenmayer.py
2.376 KB
June 06 2023 13:32:21
root / root
0755
minimal_hanoi.py
2.002 KB
June 06 2023 13:32:21
root / root
0755
nim.py
6.36 KB
June 06 2023 13:32:21
root / root
0644
paint.py
1.26 KB
June 06 2023 13:32:21
root / root
0755
peace.py
1.04 KB
June 06 2023 13:32:21
root / root
0755
penrose.py
3.3 KB
June 06 2023 13:32:21
root / root
0755
planet_and_moon.py
2.758 KB
June 06 2023 13:32:21
root / root
0755
rosette.py
1.329 KB
June 06 2023 13:32:21
root / root
0644
round_dance.py
1.762 KB
June 06 2023 13:32:21
root / root
0644
sorting_animate.py
4.911 KB
October 17 2023 18:12:57
root / root
0644
tree.py
1.367 KB
June 06 2023 13:32:21
root / root
0755
turtle.cfg
0.156 KB
June 06 2023 13:32:21
root / root
0644
two_canvases.py
1.093 KB
June 06 2023 13:32:21
root / root
0644
yinyang.py
0.801 KB
June 06 2023 13:32:21
root / root
0755

GRAYBYTE WORDPRESS FILE MANAGER @ 2025
CONTACT ME
Static GIF