@Charanpreet/

Lab 4.04 - Method parameters

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
import turtle
import random

class DancingTurtle(turtle.Turtle):
  def shimmy(self, angle, num_shimmies):
    self.left(angle)
    for _ in range(num_shimmies):
      self.right(2 * angle)
      self.left(2 * angle)
    self.right(angle)

  # Move in a zig-zag.
  def zig_zag(self, angle, size, num_zig_zags):
    self.left(angle)
    for _ in range(num_zig_zags):
      self.forward(size)
      self.right(2 * angle)
      self.forward(size)
      self.left(2 * angle)
    self.right(angle)

  # Move backward and forward 10 times.
  def shake(self, size, num_shakes):
    for _ in range(num_shakes):
      self.backward(size)
      self.forward(size)
  
  # 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, height, num_jumps):
    self.left(90)
    for _ in range(num_jumps):
      self.forward(height)
      self.backward(height)
    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, height, num_rotations):
    self.left(90)
    for _ in range(num_rotations):
      self.forward(height)
      self.left(360)
      self.backward(height)
    self.right(90)

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



# Make Dorothy do all of the dance moves. If the dance moves
# has parameters, then you should use the dance move at least 2 times
# with different parameters.
dorothy = DancingTurtle()
dorothy.shape('turtle')
dorothy.penup()
dorothy.speed(3)
dorothy.goto(-300, 0)
dorothy.change_color()
dorothy.shimmy(90, 3)
dorothy.change_color()
dorothy.zig_zag(80, 100, 4)
dorothy.change_color()
dorothy.shake(30,10)
dorothy.change_color()
dorothy.jump_up_and_down(40,8)
dorothy.change_color()
dorothy.do_backflip(30,5)
dorothy.change_color()
dorothy.do_backwards_shuffle(30,20,10)
result
console