repl.it
@Charanpreet/

3.06 Starter Code - Drawing shapes

Python (with Turtle)

No description

fork
loading
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import turtle

def draw_square(side_length):
  starting_x = turtle.xcor()
  starting_y = turtle.ycor()
  turtle.setheading(0)
  turtle.pendown()
  turtle.forward(side_length)
  turtle.left(90)
  turtle.forward(side_length)
  turtle.left(90)
  turtle.forward(side_length)
  turtle.left(90)
  turtle.forward(side_length)
  turtle.penup()

def draw_rectangle(width, height):
  starting_x = turtle.xcor()
  starting_y = turtle.ycor()
  turtle.setheading(0)
  turtle.pendown()
  turtle.forward(width)
  turtle.left(90)
  turtle.forward(height)
  turtle.left(90)
  turtle.forward(width)
  turtle.left(90)
  turtle.forward(height)
  turtle.penup()


def draw_equilateral_triangle(side_length):
  starting_x = turtle.xcor()
  starting_y = turtle.ycor()
  turtle.setheading(0)
  turtle.pendown()
  turtle.forward(side_length)
  turtle.left(120)
  turtle.forward(side_length)
  turtle.left(120)
  turtle.forward(side_length)
  turtle.penup()


def draw_regular_hexagon(side_length):
  starting_x = turtle.xcor()
  starting_y = turtle.ycor()
  turtle.setheading(0)
  turtle.pendown()
  turtle.forward(side_length)
  turtle.left(60)
  turtle.forward(side_length)
  turtle.left(60)
  turtle.forward(side_length)
  turtle.left(60)
  turtle.forward(side_length)
  turtle.left(60)
  turtle.forward(side_length)
  turtle.left(60)
  turtle.forward(side_length)
  turtle.penup()


# BONUS
def draw_regular_polygon(num_sides, side_length):
  pass



# Use your functions to draw a picture:
turtle.penup()
turtle.goto(-100, -100)
turtle.color('red')
draw_square(80)
turtle.goto(100, -100)
turtle.color('blue')
draw_rectangle(100,80)
turtle.goto(-100,100)
turtle.color('yellow')
draw_equilateral_triangle(100)
turtle.goto(100, 100)
turtle.color('orange')
draw_regular_hexagon(100)
result
console