Python turtle.forward() Examples
The following are 30
code examples of turtle.forward().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
turtle
, or try the search function
.
Example #1
Source File: fractal_trees.py From advancedpython3 with GNU General Public License v3.0 | 7 votes |
def draw_tree(length, width=9): color = 'brown' if length < 1: return elif length < 3: color = 'green' if width < 1: width = 1 turtle.color(color) turtle.width(width) turtle.forward(length) turtle.left(30) draw_tree(length / FACTOR, width - 1) turtle.right(60) draw_tree(length / FACTOR, width - 1) turtle.left(30) turtle.color(color) turtle.width(width) turtle.backward(length)
Example #2
Source File: gear-1.py From python-examples with MIT License | 7 votes |
def gear(count, width, height): angle = 90-(180/count) for _ in range(count): turtle.forward(width) turtle.left(angle) turtle.forward(height) turtle.right(90) turtle.forward(width) turtle.right(90) turtle.forward(height) turtle.left(angle) # --- main --- # clear everything
Example #3
Source File: main-colors-asymmetrical.py From python-examples with MIT License | 6 votes |
def item(lenght, level, color): if level <= 0: return for _ in range(5): # 5 turtle.color(colors[color]) turtle.forward(lenght) item(lenght/4, level-1, color+1) turtle.penup() # there is no need to draw again the same line (and it can use differnt color) turtle.backward(lenght) turtle.pendown() turtle.right(360/8) # 8 turtle.right(360/8 * 3) # 3 = 8 - 5
Example #4
Source File: main.py From python-examples with MIT License | 6 votes |
def draw_pattern_circle(x, y, r, count, radius, color='red'): rotation = 360 / count turtle.goto(x, y) for _ in range(count): # move from center to circle #turtle.pu() turtle.color('black') turtle.forward(radius) turtle.right(90) draw_circle(r, color) # move from circle to center #turtle.pu() turtle.color('black') turtle.left(90) turtle.backward(radius) # rotate in circle turtle.right(rotation)
Example #5
Source File: main.py From python-examples with MIT License | 6 votes |
def draw_pattern_rectangle(x, y, width, height, count, radius, color='red'): rotation = 360 / count turtle.goto(x, y) for _ in range(count): # move from center to circle turtle.pu() #turtle.color('black') turtle.forward(radius) turtle.right(90+rotation/2) draw_rectangle(width, height, color) # move from circle to center turtle.pu() #turtle.color('black') turtle.left(90+rotation/2) turtle.backward(radius) # rotate in circle turtle.right(rotation)
Example #6
Source File: gear-2.py From python-examples with MIT License | 6 votes |
def gear(count, width, height): angle = 90-(180/count) for _ in range(count): turtle.forward(width) turtle.left(angle) turtle.forward(height) turtle.right(90) turtle.forward(width) turtle.right(90) turtle.forward(height) turtle.left(angle) # --- main --- # clear everything
Example #7
Source File: main.py From python-examples with MIT License | 5 votes |
def backward(): turtle.setheading(270) turtle.forward(100)
Example #8
Source File: example-1.py From python-examples with MIT License | 5 votes |
def move(): if running: t.forward(15) angle = random.randint(-9, 9) * 10 t.left(angle) t.ontimer(move, 25) # 25ms
Example #9
Source File: main.py From python-examples with MIT License | 5 votes |
def left(): turtle.setheading(180) turtle.forward(100)
Example #10
Source File: main.py From python-examples with MIT License | 5 votes |
def right(): turtle.setheading(0) turtle.forward(100)
Example #11
Source File: main.py From python-examples with MIT License | 5 votes |
def draw(): turtle.forward(50) turtle.left(30) turtle.forward(50) turtle.left(30) # access to tkinter - tk & root # instead of standard # import tkinter as tk # root = tk.Tk()
Example #12
Source File: main.py From python-examples with MIT License | 5 votes |
def dragon(level=1, remove_plus_minus=False, width=5): a = 'FX' rule = { 'X': 'X+YF+', 'Y': '-FX-Y', '-': '-', '+': '+', 'F': 'F', } for _ in range(level): a = ''.join(rule[x] for x in a) print('len:', len(a)) a = a.replace('X', '').replace('Y','') print('len without X, Y:', len(a)) if remove_plus_minus: a = a.replace('+-', '').replace('-+', '') print('len without -+, +-:', len(a)) for x in a: if x == 'F': turtle.forward(width) elif x == '+': turtle.right(90) turtle.color('red') elif x == '-': turtle.left(90) turtle.color('green') print('OK') # --- main --- # clear everything
Example #13
Source File: main-1.py From python-examples with MIT License | 5 votes |
def flower(size): for _ in range(36): turtle.forward(size) turtle.left(110) # --- main --- # clear everything
Example #14
Source File: main-2-steps-5.py From python-examples with MIT License | 5 votes |
def flower(size): for _ in range(36): turtle.forward(size) turtle.left(110) # --- main --- # clear everything
Example #15
Source File: main.py From python-examples with MIT License | 5 votes |
def draw_rectangle(width, height, color='red'): turtle.pd() turtle.color(color) for _ in range(2): turtle.forward(width) turtle.left(90) turtle.forward(height) turtle.left(90)
Example #16
Source File: main.py From python-examples with MIT License | 5 votes |
def on_forward(): val = t.textinput('Forward', "How much: ") if val: try: val = int(val) t.forward(val) except ValueError: messagebox.showinfo('Error', 'Wrong value') t.listen()
Example #17
Source File: main-colors.py From python-examples with MIT License | 5 votes |
def item(lenght, level, color): if level <= 0: return for _ in range(8): turtle.color(colors[color]) turtle.forward(lenght) item(lenght/4, level-1, color+1) turtle.penup() # there is no need to draw again the same line (and it can use differnt color) turtle.backward(lenght) turtle.pendown() turtle.right(360/8)
Example #18
Source File: main.py From python-examples with MIT License | 5 votes |
def forward(): turtle.setheading(90) turtle.forward(100)
Example #19
Source File: clock.py From Tools with MIT License | 5 votes |
def move(distance): turtle.penup() turtle.forward(distance) turtle.pendown()
Example #20
Source File: main-6.py From python-examples with MIT License | 5 votes |
def draw_rectangle(size): for _ in range(4): turtle.forward(size) turtle.left(90) # --- main --- # clear everything
Example #21
Source File: main-2.py From python-examples with MIT License | 5 votes |
def draw_rectangle(size): for _ in range(4): turtle.forward(size) turtle.left(90) # --- main --- # clear everything
Example #22
Source File: main-4.py From python-examples with MIT License | 5 votes |
def draw_rectangle(size): for _ in range(4): turtle.forward(size) turtle.left(90) # --- main --- # clear everything
Example #23
Source File: main-1.py From python-examples with MIT License | 5 votes |
def draw_rectangle(size): for _ in range(4): turtle.forward(size) turtle.left(90) # --- main --- # clear everything
Example #24
Source File: main-3.py From python-examples with MIT License | 5 votes |
def draw_rectangle(size): for _ in range(4): turtle.forward(size) turtle.left(90) # --- main --- # clear everything
Example #25
Source File: base.py From Learning-Python-by-building-games with MIT License | 5 votes |
def square(x, y, size, name): """Draw square at `(x, y)` with side length `size` and fill color `name`. The square is oriented so the bottom left corner is at (x, y). """ import turtle turtle.up() turtle.goto(x, y) turtle.down() turtle.color(name) turtle.begin_fill() for count in range(4): turtle.forward(size) turtle.left(90) turtle.end_fill()
Example #26
Source File: draw-hexagons.py From advancedpython3 with GNU General Public License v3.0 | 5 votes |
def hexagon(): for _ in range(6): turtle.forward(50) turtle.left(60)
Example #27
Source File: sample-window3.py From advancedpython3 with GNU General Public License v3.0 | 5 votes |
def draw_square(size): """ Function to draw a square """ turtle.forward(size) turtle.right(90) turtle.forward(size) turtle.right(90) turtle.forward(size) turtle.right(90) turtle.forward(size)
Example #28
Source File: snowflake.py From advancedpython3 with GNU General Public License v3.0 | 5 votes |
def draw_branch(size): """ Draw an individual branch on a snowflake """ side_branch_size = size / 3 for _ in range(3): for i in range(3): turtle.forward(side_branch_size) turtle.backward(side_branch_size) turtle.right(45) turtle.left(90) turtle.backward(side_branch_size) turtle.left(45) turtle.right(90)
Example #29
Source File: snowflake.py From advancedpython3 with GNU General Public License v3.0 | 5 votes |
def draw_snowflake(size): """ Draw a picture of a snowflake """ turtle.penup() turtle.forward(10 * size) turtle.left(45) turtle.pendown() turtle.color(generate_random_colour()) # draw branch 8 times to make a snowflake for _ in range(8): draw_branch(size) turtle.forward(size) turtle.left(45) turtle.penup()
Example #30
Source File: snowflake_koch.py From advancedpython3 with GNU General Public License v3.0 | 5 votes |
def draw_koch(size, depth): if depth > 0: for angle in ANGLES: draw_koch(size / 3, depth - 1) turtle.left(angle) else: turtle.forward(size)