Skip to content

Commit

Permalink
Loads of upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
lawsie committed Oct 22, 2024
1 parent 00b61a9 commit 62ea1de
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 86 deletions.
65 changes: 20 additions & 45 deletions en/code/rocket-launch-solution/main.py
Original file line number Diff line number Diff line change
@@ -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():
Expand All @@ -69,5 +45,4 @@ def draw():
draw_rocket()


fuel = int(input('How many kilograms of fuel do you want to use?'))
run()
14 changes: 7 additions & 7 deletions en/quiz1/question_1.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,40 @@ 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 <br> Looping 2 <br> Looping 3 <br> Looping 4 <br> Looping 5
- ( ) 1 <br> 2 <br> 3 <br> 4 <br> 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 <br> i <br> i <br> i <br> i

--- feedback ---

Not quite, the **loop variable** from a `for` loop — in this case `i` — holds the current value from the sequence the loop is working through.

--- /feedback ---

- (x) Looping 0 <br> Looping 1 <br> Looping 2 <br> Looping 3 <br> Looping 4
- (x) 0 <br> 1 <br> 2 <br> 3 <br> 4

--- feedback ---

Correct. The loop runs once, in order, for each item `i` in the range [0, 1, 2, 3, 4].

--- /feedback ---

- ( ) Looping 4 <br> Looping 3 <br> Looping 2 <br> Looping 1 <br> Looping 0
- ( ) 4 <br> 3 <br> 2 <br> 1 <br> 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 ---

Expand Down
53 changes: 28 additions & 25 deletions en/step_4.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -76,14 +97,15 @@ 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():
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(
Expand Down Expand Up @@ -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(
Expand All @@ -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 ---
Expand Down
19 changes: 10 additions & 9 deletions en/step_6.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

<iframe src="https://editor.raspberrypi.org/en/embed/viewer/rocket-launch-upgrade" width="600" height="600" frameborder="0" marginwidth="0" marginheight="0" allowfullscreen>
</iframe>
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 ---

0 comments on commit 62ea1de

Please sign in to comment.