Skip to content

Commit 4a0e0be

Browse files
m-bowleypjbRPF
andauthored
Updating rocket launch example code (#184)
Co-authored-by: Pete Bell <104009652+pjbRPF@users.noreply.github.com>
1 parent 9fe2c2d commit 4a0e0be

File tree

3 files changed

+53
-52
lines changed
  • lib/tasks/project_components

3 files changed

+53
-52
lines changed

lib/tasks/project_components/make_a_face_starter/main.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
from grid import *
55

66
def setup():
7-
# Put code to run once here
8-
size(400, 400) # width and height
7+
# Put code to run once here
8+
size(400, 400) # width and height
99

1010
def draw():
11-
# Put code to run every frame here
12-
background(255, 255, 255) # move under draw() to reset the drawing every frame
13-
grid() # add a # to the beginning of this line to hide the grid
11+
# Put code to run every frame here
12+
background(255, 255, 255)
13+
# Add code to draw your face here
14+
15+
grid() # add a # to the beginning of this line to hide the grid
16+
1417

1518
# Keep this to run your code
1619
run()

lib/tasks/project_components/powerful_patterns_starter/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ def draw():
1616

1717

1818
# Keep this to run your code
19-
run()
19+
run(frame_rate = 5)

lib/tasks/project_components/rocket_launch_example/main.py

Lines changed: 44 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,67 +6,65 @@
66

77
# Setup global variables
88
screen_size = 400
9-
rocket_y = screen_size # start at the bottom
10-
burn = 100 # how much fuel is burned in each frame
9+
rocket_y = 400
10+
burn = 100
1111
orbit_radius = 250
1212
orbit_y = screen_size - orbit_radius
1313

14+
1415
# The draw_rocket function goes here
1516
def draw_rocket():
17+
global rocket_y, fuel, burn
1618

17-
global rocket_y, fuel, burn
18-
19-
if fuel >= burn and rocket_y > orbit_y: # still flying
20-
rocket_y -= 1 # move the rocket
21-
fuel -= burn # burn fuel
22-
print('Fuel left: ', fuel)
23-
24-
no_stroke() # Turn off the stroke
25-
26-
for i in range(25): # draw 25 burning exhaust ellipses
27-
fill(255, 255 - i*10, 0) # yellow
28-
ellipse(width/2, rocket_y + i, 8, 3) # i increases each time the loop repeats
19+
if fuel >= burn and rocket_y > orbit_y:
20+
rocket_y -= 1
21+
fuel -= burn
22+
print('Fuel left: ', fuel)
23+
24+
no_stroke()
25+
26+
for i in range(25):
27+
fill(255, 255 - i * 10, 0)
28+
ellipse(width/2, rocket_y + i, 8, 3)
2929

30-
fill(200, 200, 200, 100) # transparent grey
31-
for i in range(20): # draw 20 random smoke ellipses
32-
ellipse(width/2 + randint(-5, 5), rocket_y + randint(20, 50), randint(5, 10), randint(5, 10))
33-
34-
if fuel < burn and rocket_y > orbit_y: # No more fuel and not in orbit
35-
tint(255, 0, 0) # Failure
36-
elif fuel < 1000 and rocket_y <= orbit_y:
37-
tint(0, 255, 0) # Success
38-
elif fuel >= 1000 and rocket_y <= orbit_y:
39-
tint(255, 200, 0) # Too much fuel
40-
41-
image(rocket, width/2, rocket_y, 64, 64)
42-
no_tint()
43-
30+
fill(200, 200, 200, 100) #Transparent grey
31+
for i in range(20): #Draw 20 random smoke ellipses
32+
ellipse(width/2 + randint(-5, 5), rocket_y + randint(20, 50), randint(5, 10), randint(5, 10))
33+
34+
if fuel < burn and rocket_y > orbit_y:
35+
tint(255, 0, 0)
36+
elif fuel < 1000 and rocket_y <= orbit_y:
37+
tint(0, 255, 0)
38+
elif fuel >= 1000 and rocket_y <= orbit_y:
39+
tint(255, 200, 0)
40+
41+
image(rocket, width/2, rocket_y, 64, 64)
42+
no_tint()
43+
4444

4545
# The draw_background function goes here
4646
def draw_background():
47-
background(0) # short for background(0, 0, 0) - black
48-
image(planet, width/2, height, 300, 300) # draw the image
49-
50-
no_fill() # Turn off any fill
51-
stroke(255) # Set a white stroke
52-
stroke_weight(2)
53-
ellipse(width/2, height, orbit_radius*2, orbit_radius*2)
54-
47+
background(0)
48+
image(planet, width/2, height, 300, 300)
49+
50+
no_fill()
51+
stroke(255)
52+
stroke_weight(2)
53+
ellipse(width/2, height, orbit_radius * 2, orbit_radius * 2)
5554

5655
def setup():
57-
# Setup your animation here
58-
size(screen_size, screen_size)
59-
image_mode(CENTER)
60-
global planet, rocket
61-
planet = load_image('planet.png') # your chosen planet
62-
rocket = load_image('rocket.png')
56+
# Setup your animation here
57+
size(screen_size, screen_size)
58+
image_mode(CENTER)
59+
global planet, rocket
60+
planet = load_image('planet.png')
61+
rocket = load_image('rocket.png')
6362

6463

6564
def draw():
66-
# Things to do in every frame
67-
draw_background()
68-
draw_rocket()
69-
65+
# Things to do in every frame
66+
draw_background()
67+
draw_rocket()
7068

7169
fuel = int(input('How many kilograms of fuel do you want to use?'))
7270
run()

0 commit comments

Comments
 (0)