repl.it
@Charanpreet/

Lab 4.03 Example - Dancing turtle-1

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
import turtle
import random
class DancingTurtle(turtle.Turtle):
  def shimmy(self):
    for _ in range(6):
      self.left(30)
      self.right(30)

  # Move in a zig-zag.
  def zig_zag(self):
    self.left(30)
    for _ in range(4):
      self.right(60)
      self.forward(20)
      self.left(60)
      self.forward(20)
    self.right(30)

  # Move forward and backward 10 times.
  def shake(self):
    for _ in range(10):
      self.backward(20)
      self.forward(20)
  
  
  # Change color to a random color.
  def change_color(self):
    red_color = random.randint(0, 250)
    green_color = random.randint(0, 250)
    blue_color = random.randint(0, 250)
    self.color(red_color, green_color, blue_color)

  # Point in the up direction. Then go up and down 3 times.
  # Then point back to the right.
  def jump_up_and_down(self):
    self.left(90)
    for _ in range(3):
      self.forward(40)
      self.backward(40)
    self.right(90)

  # Point in the up direction. Go up. Then do a 360 degree turn.
  # Come back down and then point to the right again.
  def do_backflip(self):
    self.left(90)
    self.forward(40)
    self.left(360)
    self.backward(40)
    self.right(90)

  # Move backwards 60 steps and forward 30 steps.
  # Repeat 6 times.
  def do_backwards_shuffle(self):
    for _ in range(6):
      self.backward(60)
      self.forward(30)


# Create a DancingTurtle and have it do some dance moves.
# Make sure to incorporate all of the dance moves.

dorothy = DancingTurtle()
dorothy.shape('turtle')
dorothy.penup()
dorothy.speed(3)
dorothy.goto(0, 0)
dorothy.change_color()
dorothy.shimmy()
dorothy.change_color()
dorothy.do_backflip()
dorothy.change_color()
dorothy.do_backwards_shuffle()
dorothy.change_color()
dorothy.zig_zag()
dorothy.change_color()
dorothy.shake()
dorothy.change_color()
dorothy.jump_up_and_down()
result
console