示例#1
0
def initTurtle():
    global InitTurtle
    # Initialisation de Turtle si pas déjà fait
    if not InitTurtle:
        # Tracé avec Tk : on trace dans le canvas
        if TK:
            from turtle import RawPen
            global turtle
            turtle = RawPen(Wcanvas)
            if Debug: print(turtle.getscreen().screensize())
        else:
            # Tracé sans Tk : création de la fenêtre et titre
            turtle.title(TITRE + VERSION)
        # Cache le pointeur de Turtle
        turtle.hideturtle()
        # Vitesse maximale du tracé
        turtle.speed(10)
        # Orientation initiale : Nord-Est
        orientation()
        # Turtle est maintenant initialisé
        InitTurtle = True
    # Turtle est déjà initialisé : on nettoie la fenêtre
    else:
        turtle.clear()
    return
示例#2
0
def initTurtle():
    global InitTurtle
    # Initialisation de Turtle si pas déjà fait
    if not InitTurtle:
        if TK:
            from turtle import RawPen
            global turtle
            turtle = RawPen(Wcanvas)
        else:
            # Titre de la fenêtre
            turtle.title(TITRE + VERSION)
            # Fonction utilisateur définie sur clic
            turtle.onscreenclick(screenClick)
        # Vitesse maximale du tracé
        turtle.speed(0)
        # Cache le pointeur de Turtle
        turtle.hideturtle()
        # Turtle est maintenant initialisé
        InitTurtle = True
    # Turtle est déjà initialisé : on vide la fenêtre
    else:
        turtle.clear()
    return
示例#3
0
 def draw(self):
     pen = RawPen(self.canvas)
     pen.pencolor('black')
     pen.goto(self.x - sizeCase / 2, self.y + sizeCase / 2)
     pen.seth(0)
示例#4
0
variables = data['variables'].keys()
constants = data['constants'].keys()
axiom = data['axiom']
rules = data['rules']
system = L_system(variables, constants, axiom, rules)

# Load the actions
actions = dict(data['variables'], **data['constants'])

# Create the screen
screen = Screen()
screen.mode('logo')
screen.tracer(0, 0)

# Create the pens
pen = RawPen(screen)
# Hide the pen
pen.speed(0)

# Run the L_system
positions = []
angles = []
for i in range(n_generation):
    # Reset the screen
    screen.reset()
    pen.hideturtle()
    # Move the turtle
    for movement in system.axiom:
        exec(actions[movement])
    # Compute the next generation
    system.next_generation()
示例#5
0
 def _draw_board(self):
     """Draws board."""
     tri = ((-1.5, -0.5), (4, 9.5), (9.5, -0.5))
     artist = RawPen(self.window)
     # Draws grooves in wood:
     artist.pen(pendown=False, pensize=2, speed=0)
     x1, y1, x2, y2 = __class__._WORLD_COORDS
     for y in range(y1, y2 + 1, 2):
         artist.goto(x1, y)
         artist.pendown()
         artist.goto(x2, y)
         artist.penup()
     # Draws board:
     artist.pen(pencolor=(34, 16, 0),
                fillcolor=(51, 25, 0),
                pensize=6,
                speed=0)
     artist.goto(tri[-1])
     artist.pendown()
     artist.begin_fill()
     for coord in tri:
         artist.goto(coord)
     artist.end_fill()
     # Draws peg holes:
     artist.pen(pencolor="gray", fillcolor="black", pensize=1)
     for peg_hole in self.game.board:
         artist.penup()
         artist.goto(peg_hole)
         artist.pendown()
         artist.begin_fill()
         artist.circle(0.4)
         artist.end_fill()
     artist.penup()
     artist.goto(__class__.HADES)