diff --git a/en/code/rocket-launch-solution/main.py b/en/code/rocket-launch-solution/main.py index c869ddbb9..ac1f6dabd 100644 --- a/en/code/rocket-launch-solution/main.py +++ b/en/code/rocket-launch-solution/main.py @@ -1,66 +1,42 @@ -#!/bin/python3 - # Import library code from p5 import * from random import randint -# Setup global variables +# Set up global variables screen_size = 400 -rocket_y = 400 -burn = 100 -orbit_radius = 250 -orbit_y = screen_size - orbit_radius +rocket_position = screen_size # The draw_rocket function goes here def draw_rocket(): - global rocket_y, fuel, burn - - if fuel >= burn and rocket_y > orbit_y: - rocket_y -= 1 - fuel -= burn - print('Fuel left: ', fuel) - - no_stroke() - - for i in range(25): - fill(255, 255 - i * 10, 0) - ellipse(width/2, rocket_y + i, 8, 3) - - fill(200, 200, 200, 100) # Transparent grey - for i in range(20): # Draw 20 random smoke ellipses - ellipse(width/2 + randint(-5, 5), rocket_y + - randint(20, 50), randint(5, 10), randint(5, 10)) - - if fuel < burn and rocket_y > orbit_y: - tint(255, 0, 0) - elif fuel < 1000 and rocket_y <= orbit_y: - tint(0, 255, 0) - elif fuel >= 1000 and rocket_y <= orbit_y: - tint(255, 200, 0) - - image(rocket, width/2, rocket_y, 64, 64) - no_tint() + global rocket_position + rocket_position = rocket_position - 1 + image(rocket, width / 2, rocket_position, 64, 64) + fill(200, 200, 200, 100) + no_stroke() + for i in range(20): + circle_size = randint(5, 10) + ellipse( + screen_size / 2 + randint(-5, 5), + rocket_position + randint(20, 50), + circle_size, + circle_size, + ) # The draw_background function goes here def draw_background(): - background(0) - image(planet, width/2, height, 300, 300) - - no_fill() - stroke(255) - stroke_weight(2) - ellipse(width/2, height, orbit_radius * 2, orbit_radius * 2) + background(0, 0, 0) + image(planet, screen_size / 2, screen_size, 300, 300) def setup(): - # Setup your animation here + # Set up your animation here size(screen_size, screen_size) image_mode(CENTER) global planet, rocket - planet = load_image('planet.png') - rocket = load_image('rocket.png') + planet = load_image("purple_planet.png") + rocket = load_image("rocket.png") def draw(): @@ -69,5 +45,4 @@ def draw(): draw_rocket() -fuel = int(input('How many kilograms of fuel do you want to use?')) run() diff --git a/en/quiz1/question_1.md b/en/quiz1/question_1.md index 722b37e8b..144c726f6 100644 --- a/en/quiz1/question_1.md +++ b/en/quiz1/question_1.md @@ -15,20 +15,20 @@ Which output would you expect if you ran the program below? ```python for i in range(5): - print("Looping", i) + print(i) ``` --- choices --- -- ( ) Looping 1
Looping 2
Looping 3
Looping 4
Looping 5 +- ( ) 1
2
3
4
5 --- feedback --- -Not quite, a `for` loop in Python repeats its code once for each item in a sequence it's given, and here `range` creates a sequence starting from `0`. +Not quite, a `for` loop in Python starts from 0, unless otherwise specified. --- /feedback --- -- ( ) Looping i +- ( ) i
i
i
i
i --- feedback --- @@ -36,7 +36,7 @@ Not quite, the **loop variable** from a `for` loop — in this case `i` — hold --- /feedback --- -- (x) Looping 0
Looping 1
Looping 2
Looping 3
Looping 4 +- (x) 0
1
2
3
4 --- feedback --- @@ -44,11 +44,11 @@ Correct. The loop runs once, in order, for each item `i` in the range [0, 1, 2, --- /feedback --- -- ( ) Looping 4
Looping 3
Looping 2
Looping 1
Looping 0 +- ( ) 4
3
2
1
0 --- feedback --- -Not quite, a `for` loop runs through the sequence of items it is given in order. Because `range()` gives an ordered sequence from 0 to the number it is passed, that is the order you would expect to see printed out by this `for` loop. +Not quite. Unless you have specified otherwise, a `for` loop will start at 0 and count up the number of times specified in the range. --- /feedback --- diff --git a/en/step_4.md b/en/step_4.md index ecbb3b0a8..1ae96b138 100644 --- a/en/step_4.md +++ b/en/step_4.md @@ -37,18 +37,39 @@ def draw_rocket(): --- task --- +The outline around the circles is called the **stroke**. Add some code to turn it off. -Generate a random number between 5 and 10 for the size of the circle, then draw it at the bottom of the rocket. --- code --- --- language: python line_numbers: true line_number_start: 14 -line_highlights: 15-16 +line_highlights: 15 +--- + + fill(200, 200, 200, 100) + no_stroke() + + +--- /code --- + +--- /task --- + + +--- task --- + +Generate a random number between 5 and 10 for the size of the circle, then draw it at the bottom of the rocket. + +--- code --- +--- +language: python +line_numbers: true +line_number_start: 15 +line_highlights: 16-22 --- -fill(200, 200, 200, 100) +no_stroke() circle_size = randint(5,10) ellipse( screen_size/2, @@ -76,7 +97,7 @@ Indent the code you used to draw the circle, and add a loop which will run the c language: python line_numbers: true line_number_start: 10 -line_highlights: 15-22 +line_highlights: 16-23 --- def draw_rocket(): @@ -84,6 +105,7 @@ def draw_rocket(): rocket_position = rocket_position - 1 image(rocket, width/2, rocket_position, 64, 64) fill(200, 200, 200, 100) + no_stroke() for i in range(20): circle_size = randint(5,10) ellipse( @@ -112,8 +134,8 @@ Generate a random number and add it to the x and y position of each circle so th --- language: python line_numbers: true -line_number_start: 16 -line_highlights: 17-18 +line_number_start: 24 +line_highlights: 25-26 --- ellipse( @@ -128,25 +150,6 @@ ellipse( --- /task --- ---- task --- -The outline around the circles is called the **stroke**. Add some code to turn it off. - - ---- code --- ---- -language: python -line_numbers: true -line_number_start: 13 -line_highlights: 14 ---- - - fill(200, 200, 200, 100) - no_stroke() - - ---- /code --- - ---- /task --- --- task --- diff --git a/en/step_6.md b/en/step_6.md index 133daa39d..b7840bade 100644 --- a/en/step_6.md +++ b/en/step_6.md @@ -2,18 +2,19 @@ ## Challenge -Your project is complete, but you can still make it better if you want. Here are a few upgrades to consider: +You could: - + Let the user set the rate at which the rocket burns fuel or how far the rocket flies in each frame. - + Add a second, higher, orbit for the rocket to reach and drop off another satellite. Have it change colour again when it gets there. - -Here's a version of the project with all those upgrades, so you can see how they could work. Click Run to launch the rocket: - - -You can view the [completed upgrade project here](https://editor.raspberrypi.org/en/projects/rocket-launch-upgrade){:target="_blank"}. +--- task --- +Give your smoke circles a range of different colours. +--- /task --- +--- task --- +Make your rocket move faster or slower. +--- /task --- +--- task --- +Add to your animation so that the rocket appears to reappear and land on a different planet. +--- /task --- --- /challenge --- \ No newline at end of file