Docsity

Python Turtle Graphics: A Beginner's Guide to Drawing Shapes, Cheat Sheet of Computer science

Partial preview of the text

Download Python Turtle Graphics: A Beginner's Guide to Drawing Shapes and more Cheat Sheet Computer science in PDF only on Docsity!

STRECHED SLINKY

circle(35) forward(40) circle(35) forward(40) circle(35) forward(40) circle(35) forward(40) circle(35) forward(40) BUBBLE WRAP speed(0)

This function will draw one row of 10 circles

def draw_circle_row(): for i in range(10): pendown() begin_fill() color("light blue") circle(20) end_fill() penup() forward(40)

This function will move Tracy from end of row up to beginning of the row on top

def move_up_a_row(): left(90) forward(40) right(90) backward(400) def make_highlight(): for i in range(10): pendown() pensize(2) color("white") circle(10, 90) pensize(1) penup() backward(50) right(90) backward(10)

Send Tracy to starting position in bottom left corner

penup() setposition(-180,-200)

Call circle drawing function 10 times to fill ten rows

for i in range(10): draw_circle_row() move_up_a_row() left(90) setposition(-170, 180) for i in range(10): make_highlight() right(90) move_up_a_row() left(90)

draw_square() left(90) for i in range(8): draw_square() left(90) for I in range(7): draw_square() DART BOARD speed(0) circle_radius= def center_circle(): right(90) forward(25) left(90) for i in range(4): pendown() circle(circle_radius) penup() center_circle() circle_radius = circle_radius + 25

LINE OF INCREASING BLOCK speed(0) square_length= distance= def draw_square(): pendown() for i in range(4): forward(square_length) left(90) penup() setposition(-150,0) for i in range(5): draw_square() penup() forward(distance) square_length=square_length + 10 distance=distance+

FOUR CORNERS speed(0) square_length = int(input("How large should the squares be? (in pixels): ")) def draw_square(): for i in range(4): pendown() forward(square_length) right(90) penup() penup() setposition(100,100) draw_square() setposition(100,-100) draw_square() setposition(-150, 100) draw_square() setposition(-150, -100) draw_square()

COLORFUL CATTERPILLER speed(0) color_choice1 = input("What is the color of the first circle? ") color_choice2 = input("What is the color of the second circle? ") color_choice3 = input("What is the color of the third circle? ") color_choice4 = input("What is the color of the fourth circle? ") def draw_circle(): pendown() circle(20) penup() forward(40) penup() setposition(-150,0) for i in range(2): begin_fill() color(color_choice1) draw_circle() end_fill() begin_fill() color(color_choice2) draw_circle() end_fill() begin_fill() color(color_choice3)

color(circle_color_choice) circle(radius) end_fill() penup() setposition(-radius, radius) draw_square() penup() setposition(0, - radius) draw_circle() SNOWMAN speed(0) first_radius = int(input("How big should the first circle be? " )) def draw_circle(): pendown() begin_fill() color("gray") circle(first_radius) end_fill()

penup() setposition(0,-200) for i in range(3): draw_circle() left(90) forward(first_radius*2) right(90) first_radius = first_radius/ GEOMETRY circle_radius = 20 penup() setposition (0,-100) for i in range(7): pendown() circle(circle_radius,360,i) circle_radius = circle_radius + 20 penup()

PHONE SIGNAL for i in range(10,60,10): pendown() forward(10) left(90) forward(i) left(90) forward(10) left(90) forward(i) penup() left(90) forward(25) BLACK AND WHITE SQUARES penup() setposition (-50,0) count = 1 def draw_square(): for i in range(4):

pendown() forward(25) left(90) penup() forward(35) for i in range(6): if count % 2 == 0: draw_square() count = count - 1 else: begin_fill() color("black") draw_square() end_fill() count = count + 1 INCREASING SQUARES length = 25 speed(0) penup()

def move_to_row(num_blocks): x_value = -((num_blocks50)/2) + radius y_value = -200+(50row_value) setposition(x_value,y_value) def draw_block_row(num_blocks): for i in range(num_blocks): pendown() circle(radius) penup() forward(50) num_blocks=int(input("How many blocks on the bottom row? (8 or less): ")) for i in range(num_blocks): move_to_row(num_blocks) row_value=row_value+ draw_block_row(num_blocks) num_blocks=num_blocks- .

CHECKERBOARD RED BALCK speed(0) penup() setposition (-200,-200) count = 1 def draw_square(): for i in range(4): pendown() forward(40) left(90) penup() forward(40) for i in range(10): for i in range(10): if count % 2 == 0: begin_fill() color("black") draw_square() end_fill() count = count - 1 else: begin_fill() color("red") draw_square() end_fill() count = count + 1 penup() left(90) forward(40) left(90) forward(400) right(180) count = count + 1

penup() forward(50) CATTERPILLER circle(20) penup() forward(40) pendown() circle(20) penup() forward(40) pendown() circle(20) penup() forward(40) pendown() circle(20) penup() forward(40) pendown() circle(20)

COLUMNS

pendown() left(90) backward(200) forward(400) left(90) penup() forward(100) left(90) pendown() forward(400) left(90) penup() forward(200) left(90) pendown() forward(400) backward(400) left(180) penup()