-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
199 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/bin/python3 | ||
|
||
# Import library code | ||
from p5 import * | ||
from random import randint | ||
|
||
# Setup global variables | ||
screen_size = 400 | ||
rocket_y = 400 | ||
burn = 100 | ||
orbit_radius = 250 | ||
orbit_y = screen_size - orbit_radius | ||
|
||
|
||
# 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() | ||
|
||
|
||
# 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) | ||
|
||
|
||
def setup(): | ||
# Setup your animation here | ||
size(screen_size, screen_size) | ||
image_mode(CENTER) | ||
global planet, rocket | ||
planet = load_image('planet.png') | ||
rocket = load_image('rocket.png') | ||
|
||
|
||
def draw(): | ||
# Things to do in every frame | ||
draw_background() | ||
draw_rocket() | ||
|
||
|
||
fuel = int(input('How many kilograms of fuel do you want to use?')) | ||
run() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name: 'Rocket Launch Example' | ||
identifier: 'rocket-launch-example' | ||
type: 'python' |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/python3 | ||
|
||
# Import library code | ||
from p5 import * | ||
from random import randint | ||
|
||
# Setup global variables | ||
|
||
|
||
# The draw_rocket function goes here | ||
|
||
|
||
|
||
# The draw_background function goes here | ||
|
||
|
||
|
||
def setup(): | ||
# Setup your animation here | ||
|
||
|
||
|
||
def draw(): | ||
# Things to do in every frame | ||
|
||
|
||
|
||
run() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name: "Rocket Launch" | ||
identifier: 'rocket-launch-starter' | ||
type: 'python' |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#!/bin/python3 | ||
|
||
# Import library code | ||
from p5 import * | ||
from random import randint | ||
|
||
# Setup global variables | ||
screen_size = 400 | ||
rocket_y = screen_size # Start at the bottom | ||
burn = 100 # How much fuel is burned in each frame | ||
orbit_radius = 250 | ||
orbit_y = screen_size - orbit_radius | ||
high_orbit_radius = 350 | ||
high_orbit_y = screen_size - high_orbit_radius | ||
speed = 1 # How far the rocket flies each frame | ||
|
||
# The draw_rocket function goes here | ||
|
||
|
||
def draw_rocket(): | ||
global rocket_y, fuel, burn | ||
|
||
if fuel >= burn and rocket_y > high_orbit_y: # Still flying | ||
rocket_y -= speed # Move the rocket | ||
fuel -= burn # Burn fuel | ||
print('Fuel left: ', fuel) | ||
|
||
no_stroke() # Turn off the stroke | ||
|
||
for i in range(25): # Draw 25 burning exhaust ellipses | ||
fill(255, 255 - i*10, 0) # yellow | ||
# i increases each time the loop repeats | ||
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 > high_orbit_y: # No more fuel and not in orbit | ||
tint(255, 0, 0) # Failure | ||
elif rocket_y <= orbit_y and rocket_y > high_orbit_y: | ||
tint(0, 255, 0) # Success | ||
elif fuel < 1000 and rocket_y <= high_orbit_y: | ||
tint(0, 100, 200) # High orbit success | ||
elif fuel >= 1000 and rocket_y <= high_orbit_y: | ||
tint(255, 200, 0) # Too much fuel | ||
|
||
image(rocket, width/2, rocket_y, 64, 64) | ||
no_tint() | ||
|
||
|
||
# The draw_background function goes here | ||
def draw_background(): | ||
background(0) # Short for background(0, 0, 0) - black | ||
image(planet, width/2, height, 300, 300) # draw the image | ||
|
||
# Draw the lower orbit | ||
no_fill() # Turn off any fill | ||
stroke(255) # Set a white stroke | ||
stroke_weight(2) | ||
ellipse(width/2, height, orbit_radius*2, orbit_radius*2) | ||
|
||
# Draw the higher orbit | ||
stroke(0, 100, 200) # Set a bluish stroke | ||
stroke_weight(2) | ||
ellipse(width/2, height, high_orbit_radius*2, high_orbit_radius*2) | ||
|
||
|
||
def setup(): | ||
# Setup your animation here | ||
size(screen_size, screen_size) | ||
image_mode(CENTER) | ||
global planet, rocket | ||
planet = load_image('orange_planet.png') # Your chosen planet | ||
rocket = load_image('rocket.png') | ||
|
||
|
||
def draw(): | ||
# Things to do in every frame | ||
draw_background() | ||
draw_rocket() | ||
|
||
|
||
fuel = int(input('How many kilograms of fuel do you want to use?')) | ||
burn = int(input('How much fuel should the rocket burn each frame?')) | ||
speed = int(input('How far should the rocket travel each frame?')) | ||
run() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name: 'Rocket Launch Upgrade' | ||
identifier: 'rocket-launch-upgrade' | ||
type: 'python' |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.