Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions lib/tasks/project_components/make_a_face_starter/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
from grid import *

def setup():
# Put code to run once here
size(400, 400) # width and height
# Put code to run once here
size(400, 400) # width and height

def draw():
# Put code to run every frame here
background(255, 255, 255) # move under draw() to reset the drawing every frame
grid() # add a # to the beginning of this line to hide the grid
# Put code to run every frame here
background(255, 255, 255)
# Add code to draw your face here

grid() # add a # to the beginning of this line to hide the grid


# Keep this to run your code
run()
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def quadrant():

def outer():

# Thehe cake is wrapped in an outer layer
# The cake is wrapped in an outer layer
yellowgreen = Color(154, 205, 50)

no_fill() # Don't cover up the cake quadrants!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ def draw():


# Keep this to run your code
run()
run(frame_rate = 5)
90 changes: 44 additions & 46 deletions lib/tasks/project_components/rocket_launch_example/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,67 +6,65 @@

# Setup global variables
screen_size = 400
rocket_y = screen_size # start at the bottom
burn = 100 # how much fuel is burned in each frame
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

global rocket_y, fuel, burn

if fuel >= burn and rocket_y > orbit_y: # still flying
rocket_y -= 1 # 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
ellipse(width/2, rocket_y + i, 8, 3) # i increases each time the loop repeats
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: # No more fuel and not in orbit
tint(255, 0, 0) # Failure
elif fuel < 1000 and rocket_y <= orbit_y:
tint(0, 255, 0) # Success
elif fuel >= 1000 and rocket_y <= orbit_y:
tint(255, 200, 0) # Too much fuel

image(rocket, width/2, rocket_y, 64, 64)
no_tint()
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) # short for background(0, 0, 0) - black
image(planet, width/2, height, 300, 300) # draw the image

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)

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') # your chosen planet
rocket = load_image('rocket.png')
# 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()

# Things to do in every frame
draw_background()
draw_rocket()

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