From c0cb62192f41f7e8d80b4495b06923a78250ab94 Mon Sep 17 00:00:00 2001 From: Pete Bell <104009652+pjbRPF@users.noreply.github.com> Date: Wed, 28 Jun 2023 13:22:17 +0100 Subject: [PATCH 01/10] Update main.py --- .../project_components/target_practice_starter/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/tasks/project_components/target_practice_starter/main.py b/lib/tasks/project_components/target_practice_starter/main.py index e257fa60a..c9e2a0dc3 100644 --- a/lib/tasks/project_components/target_practice_starter/main.py +++ b/lib/tasks/project_components/target_practice_starter/main.py @@ -8,12 +8,12 @@ def setup(): # Setup your game here - size(400, 400) # width and height + size(400, 400) # width and height of screen def draw(): # Things to do in every frame - fill('cyan') - rect(0, 0, 400, 250) # Sky + fill('cyan') # Set the fill color for the sky to cyan + rect(0, 0, 400, 250) # Draw a rectangle for the sky with these values for x, y, width, height # Keep this to run your code run(frame_rate=2) From 64aa240b5e1c53c0ab946c1a84af632d5029219f Mon Sep 17 00:00:00 2001 From: Pete Bell <104009652+pjbRPF@users.noreply.github.com> Date: Wed, 28 Jun 2023 13:23:31 +0100 Subject: [PATCH 02/10] Create p5.py --- .../target_practice_starter/p5.py | 138 ++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 lib/tasks/project_components/target_practice_starter/p5.py diff --git a/lib/tasks/project_components/target_practice_starter/p5.py b/lib/tasks/project_components/target_practice_starter/p5.py new file mode 100644 index 000000000..45f3e0c42 --- /dev/null +++ b/lib/tasks/project_components/target_practice_starter/p5.py @@ -0,0 +1,138 @@ +# Definitions for compatibility with the p5py processing library +from processing import * +import __main__ + +# Shape +from processing import rectMode as rect_mode +from processing import ellipseMode as ellipse_mode +from processing import strokeWeight as stroke_weight +from processing import strokeCap as stroke_cap +from processing import strokeJoin as stroke_join +from processing import noStroke as no_stroke +from processing import noFill as no_fill + +# Fonts +from processing import createFont as create_font +from processing import loadFont as load_font +from processing import textFont as text_font + +# Text +from processing import textAlign as text_align +from processing import textLeading as text_leading +from processing import textMode as text_mode +from processing import textSize as text_size +from processing import textWidth as text_width + +# Colour +from processing import blendColor as blend_color +from processing import lerpColor as lerp_color +from processing import color as Color + +# Images +from processing import createImage as create_image +from processing import imageMode as image_mode +from processing import loadImage as load_image +from processing import noTint as no_tint +from processing import requestImage as request_image + +# Environment +from processing import frameRate as frame_rate +from processing import noCursor as no_cursor +from processing import noLoop as no_loop + +# Transform +from processing import applyMatrix as apply_matrix +from processing import popMatrix as pop_matrix +from processing import printMatrix as print_matrix +from processing import pushMatrix as push_matrix +from processing import resetMatrix as reset_matrix +from processing import rotateX as rotate_x +from processing import rotateY as rotate_y +from processing import pushStyle as push_style +from processing import popStyle as pop_style + +from processing import run as main_run + +# Keyboard + +def mousePressed(): + if hasattr(__main__, "mouse_pressed"): + mouse_pressed = getattr(__main__, "mouse_pressed") + mouse_pressed() + +def mouseReleased(): + if hasattr(__main__, "mouse_released"): + mouse_released = getattr(__main__, "mouse_released") + mouse_released() + +__main__.mouse_x = 0 +__main__.mouse_y = 0 +__main__.mouse_px = 0 +__main__.mouse_py = 0 +__main__.frame_count = 0 +__main__.frame_rate = 60 + +def mouseMoved(): + __main__.mouse_x = mouse.x + __main__.mouse_y = mouse.y + __main__.mouse_px = mouse.px + __main__.mouse_py = mouse.py + if hasattr(__main__, "mouse_moved"): + mouse_moved = getattr(__main__, "mouse_moved") + mouse_moved() + +def mouseDragged(): + if hasattr(__main__, "mouse_dragged"): + mouse_dragged = getattr(__main__, "mouse_dragged") + mouse_dragged() + +def new_draw(): + __main__.frame_count = frameCount + frameRate = __main__.frame_rate + old_draw() + +def run(): + global old_draw + old_draw = __main__.draw + __main__.draw = new_draw + main_run() + +def grid(): + pushMatrix() + stroke(200) + fill(0) + line(0, height/2, width, height/2) + line(width/2, 0, width/2, height) + x_coords = [0, width/2, width] + y_coords = [0, height/2, height] + + for x in x_coords: + for y in y_coords: + show_coord(x, y) + + popMatrix() + +def circle(x, y, w): + ellipse(x, y, w, w) + +def show_coord(x, y): + if x == width: + x_align = RIGHT + elif x == 0: + x_align = LEFT + else: + x_align = CENTER + + if y == height: + y_align = BASELINE + elif y == 0: + y_align = TOP + else: + y_align = CENTER + + pushStyle() + fill(100) + text_align(x_align, y_align) + text('(' + str(int(x)) + ', ' + str(int(y)) + ')', x, y) + popStyle() + From 27d6e59336e42883f69fa1b739364f34822f676d Mon Sep 17 00:00:00 2001 From: Pete Bell <104009652+pjbRPF@users.noreply.github.com> Date: Wed, 28 Jun 2023 13:47:52 +0100 Subject: [PATCH 03/10] Delete p5.py --- .../target_practice_starter/p5.py | 138 ------------------ 1 file changed, 138 deletions(-) delete mode 100644 lib/tasks/project_components/target_practice_starter/p5.py diff --git a/lib/tasks/project_components/target_practice_starter/p5.py b/lib/tasks/project_components/target_practice_starter/p5.py deleted file mode 100644 index 45f3e0c42..000000000 --- a/lib/tasks/project_components/target_practice_starter/p5.py +++ /dev/null @@ -1,138 +0,0 @@ -# Definitions for compatibility with the p5py processing library -from processing import * -import __main__ - -# Shape -from processing import rectMode as rect_mode -from processing import ellipseMode as ellipse_mode -from processing import strokeWeight as stroke_weight -from processing import strokeCap as stroke_cap -from processing import strokeJoin as stroke_join -from processing import noStroke as no_stroke -from processing import noFill as no_fill - -# Fonts -from processing import createFont as create_font -from processing import loadFont as load_font -from processing import textFont as text_font - -# Text -from processing import textAlign as text_align -from processing import textLeading as text_leading -from processing import textMode as text_mode -from processing import textSize as text_size -from processing import textWidth as text_width - -# Colour -from processing import blendColor as blend_color -from processing import lerpColor as lerp_color -from processing import color as Color - -# Images -from processing import createImage as create_image -from processing import imageMode as image_mode -from processing import loadImage as load_image -from processing import noTint as no_tint -from processing import requestImage as request_image - -# Environment -from processing import frameRate as frame_rate -from processing import noCursor as no_cursor -from processing import noLoop as no_loop - -# Transform -from processing import applyMatrix as apply_matrix -from processing import popMatrix as pop_matrix -from processing import printMatrix as print_matrix -from processing import pushMatrix as push_matrix -from processing import resetMatrix as reset_matrix -from processing import rotateX as rotate_x -from processing import rotateY as rotate_y -from processing import pushStyle as push_style -from processing import popStyle as pop_style - -from processing import run as main_run - -# Keyboard - -def mousePressed(): - if hasattr(__main__, "mouse_pressed"): - mouse_pressed = getattr(__main__, "mouse_pressed") - mouse_pressed() - -def mouseReleased(): - if hasattr(__main__, "mouse_released"): - mouse_released = getattr(__main__, "mouse_released") - mouse_released() - -__main__.mouse_x = 0 -__main__.mouse_y = 0 -__main__.mouse_px = 0 -__main__.mouse_py = 0 -__main__.frame_count = 0 -__main__.frame_rate = 60 - -def mouseMoved(): - __main__.mouse_x = mouse.x - __main__.mouse_y = mouse.y - __main__.mouse_px = mouse.px - __main__.mouse_py = mouse.py - if hasattr(__main__, "mouse_moved"): - mouse_moved = getattr(__main__, "mouse_moved") - mouse_moved() - -def mouseDragged(): - if hasattr(__main__, "mouse_dragged"): - mouse_dragged = getattr(__main__, "mouse_dragged") - mouse_dragged() - -def new_draw(): - __main__.frame_count = frameCount - frameRate = __main__.frame_rate - old_draw() - -def run(): - global old_draw - old_draw = __main__.draw - __main__.draw = new_draw - main_run() - -def grid(): - pushMatrix() - stroke(200) - fill(0) - line(0, height/2, width, height/2) - line(width/2, 0, width/2, height) - x_coords = [0, width/2, width] - y_coords = [0, height/2, height] - - for x in x_coords: - for y in y_coords: - show_coord(x, y) - - popMatrix() - -def circle(x, y, w): - ellipse(x, y, w, w) - -def show_coord(x, y): - if x == width: - x_align = RIGHT - elif x == 0: - x_align = LEFT - else: - x_align = CENTER - - if y == height: - y_align = BASELINE - elif y == 0: - y_align = TOP - else: - y_align = CENTER - - pushStyle() - fill(100) - text_align(x_align, y_align) - text('(' + str(int(x)) + ', ' + str(int(y)) + ')', x, y) - popStyle() - From 703bf3a2bf35ee98e12d4ac9a4c91181d50f5758 Mon Sep 17 00:00:00 2001 From: Pete Bell <104009652+pjbRPF@users.noreply.github.com> Date: Wed, 28 Jun 2023 13:48:09 +0100 Subject: [PATCH 04/10] Delete p5.py --- .../target_practice_example/p5.py | 139 ------------------ 1 file changed, 139 deletions(-) delete mode 100644 lib/tasks/project_components/target_practice_example/p5.py diff --git a/lib/tasks/project_components/target_practice_example/p5.py b/lib/tasks/project_components/target_practice_example/p5.py deleted file mode 100644 index 4249cd99a..000000000 --- a/lib/tasks/project_components/target_practice_example/p5.py +++ /dev/null @@ -1,139 +0,0 @@ -# Definitions for compatibility with the p5py processing library -from processing import * -import __main__ - -# Shape -from processing import rectMode as rect_mode -from processing import ellipseMode as ellipse_mode -from processing import strokeWeight as stroke_weight -from processing import strokeCap as stroke_cap -from processing import strokeJoin as stroke_join -from processing import noStroke as no_stroke -from processing import noFill as no_fill - -# Fonts -from processing import createFont as create_font -from processing import loadFont as load_font -from processing import textFont as text_font - -# Text -from processing import textAlign as text_align -from processing import textLeading as text_leading -from processing import textMode as text_mode -from processing import textSize as text_size -from processing import textWidth as text_width - -# Colour -from processing import blendColor as blend_color -from processing import lerpColor as lerp_color -from processing import color as Color - -# Images -from processing import createImage as create_image -from processing import imageMode as image_mode -from processing import loadImage as load_image -from processing import noTint as no_tint -from processing import requestImage as request_image - -# Environment -from processing import frameRate as frame_rate -from processing import noCursor as no_cursor -from processing import noLoop as no_loop - -# Transform -from processing import applyMatrix as apply_matrix -from processing import popMatrix as pop_matrix -from processing import printMatrix as print_matrix -from processing import pushMatrix as push_matrix -from processing import resetMatrix as reset_matrix -from processing import rotateX as rotate_x -from processing import rotateY as rotate_y -from processing import pushStyle as push_style -from processing import popStyle as pop_style - -from processing import run as main_run - -# Keyboard - -def mousePressed(): - if hasattr(__main__, "mouse_pressed"): - mouse_pressed = getattr(__main__, "mouse_pressed") - mouse_pressed() - -def mouseReleased(): - if hasattr(__main__, "mouse_released"): - mouse_released = getattr(__main__, "mouse_released") - mouse_released() - -__main__.mouse_x = 0 -__main__.mouse_y = 0 -__main__.mouse_px = 0 -__main__.mouse_py = 0 -__main__.frame_count = 0 -__main__.frame_rate = 60 - -def mouseMoved(): - __main__.mouse_x = mouse.x - __main__.mouse_y = mouse.y - __main__.mouse_px = mouse.px - __main__.mouse_py = mouse.py - if hasattr(__main__, "mouse_moved"): - mouse_moved = getattr(__main__, "mouse_moved") - mouse_moved() - -def mouseDragged(): - if hasattr(__main__, "mouse_dragged"): - mouse_dragged = getattr(__main__, "mouse_dragged") - mouse_dragged() - -def new_draw(): - __main__.frame_count = frameCount - frameRate = __main__.frame_rate - old_draw() - -def run(): - global old_draw - old_draw = __main__.draw - __main__.draw = new_draw - main_run() - -def grid(): - pushMatrix() - stroke(200) - fill(0) - line(0, height/2, width, height/2) - line(width/2, 0, width/2, height) - x_coords = [0, width/2, width] - y_coords = [0, height/2, height] - - for x in x_coords: - for y in y_coords: - show_coord(x, y) - - popMatrix() - -def circle(x, y, w): - ellipse(x, y, w, w) - -def show_coord(x, y): - if x == width: - x_align = RIGHT - elif x == 0: - x_align = LEFT - else: - x_align = CENTER - - if y == height: - y_align = BASELINE - elif y == 0: - y_align = TOP - else: - y_align = CENTER - - pushStyle() - fill(100) - text_align(x_align, y_align) - text('(' + str(int(x)) + ', ' + str(int(y)) + ')', x, y) - popStyle() - - From ae7716de27eba43599958c6a8bb5328e66a64ba6 Mon Sep 17 00:00:00 2001 From: Pete Bell <104009652+pjbRPF@users.noreply.github.com> Date: Wed, 28 Jun 2023 14:24:12 +0100 Subject: [PATCH 05/10] Update main.py --- .../project_components/target_practice_example/main.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/tasks/project_components/target_practice_example/main.py b/lib/tasks/project_components/target_practice_example/main.py index 802ec07b5..bccec750d 100644 --- a/lib/tasks/project_components/target_practice_example/main.py +++ b/lib/tasks/project_components/target_practice_example/main.py @@ -4,21 +4,21 @@ # The mouse_pressed function goes here def mouse_pressed(): - if hit_color == Color('blue'): # Like functions, 'if' statements are indented + if hit_colour == Color('blue'): # Like functions, 'if' statements are indented print('You hit the outer circle, 50 points!') - elif hit_color == Color('red'): + elif hit_colour == Color('red'): print('You hit the inner circle, 200 points!') - elif hit_color == Color('yellow'): + elif hit_colour == Color('yellow'): print('You hit the middle, 500 points!') else: print('You missed! No points!') # The shoot_arrow function goes here def shoot_arrow(): - global hit_color # Can be used in other functions + global hit_colour # Can be used in other functions arrow_x = randint(100, 300) # Store a random number between 100 and 300 arrow_y = randint(100, 300) # Store a random number between 100 and 300 - hit_color = get(arrow_x, arrow_y) # Get the hit colour + hit_colour = get(arrow_x, arrow_y) # Get the hit colour fill('sienna') # Set the arrow to fill colour to brown circle(arrow_x, arrow_y, 15) # Draw a small circle at random coordinates From acf8340a7729e09c1104b0778c112366903632a6 Mon Sep 17 00:00:00 2001 From: Pete Bell <104009652+pjbRPF@users.noreply.github.com> Date: Wed, 28 Jun 2023 14:52:49 +0100 Subject: [PATCH 06/10] Update main.py --- lib/tasks/project_components/target_practice_example/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/project_components/target_practice_example/main.py b/lib/tasks/project_components/target_practice_example/main.py index bccec750d..454309394 100644 --- a/lib/tasks/project_components/target_practice_example/main.py +++ b/lib/tasks/project_components/target_practice_example/main.py @@ -40,7 +40,7 @@ def draw(): fill('red') circle(200, 200, 110) # Inner circle fill('yellow') - circle(200, 200, 30) # Middle + circle(200, 200, 30) # Middle circle shoot_arrow() # Keep this to run your code From 4135a71df71c48c58e07bed6296318bf80b2013f Mon Sep 17 00:00:00 2001 From: Pete Bell <104009652+pjbRPF@users.noreply.github.com> Date: Thu, 29 Jun 2023 14:09:20 +0100 Subject: [PATCH 07/10] Update main.py - Fixed typo in comment --- .../powerful_patterns_kek_lepis_sarawak/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/project_components/powerful_patterns_kek_lepis_sarawak/main.py b/lib/tasks/project_components/powerful_patterns_kek_lepis_sarawak/main.py index e9816f307..3c1f5c80a 100644 --- a/lib/tasks/project_components/powerful_patterns_kek_lepis_sarawak/main.py +++ b/lib/tasks/project_components/powerful_patterns_kek_lepis_sarawak/main.py @@ -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! From a629e854932c5fd0581549061eb69f7cb6c1f879 Mon Sep 17 00:00:00 2001 From: Pete Bell <104009652+pjbRPF@users.noreply.github.com> Date: Thu, 29 Jun 2023 15:02:05 +0100 Subject: [PATCH 08/10] Added frame_rate parameter in call to run() --- lib/tasks/project_components/powerful_patterns_starter/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/project_components/powerful_patterns_starter/main.py b/lib/tasks/project_components/powerful_patterns_starter/main.py index 84f2849da..28ebb719c 100644 --- a/lib/tasks/project_components/powerful_patterns_starter/main.py +++ b/lib/tasks/project_components/powerful_patterns_starter/main.py @@ -16,4 +16,4 @@ def draw(): # Keep this to run your code -run() +run(frame_rate = 5) From f6ec2a830ec9c59843a4b271ab314ef0ab256791 Mon Sep 17 00:00:00 2001 From: Mac Bowley <36036152+m-bowley@users.noreply.github.com> Date: Thu, 29 Jun 2023 16:46:57 +0100 Subject: [PATCH 09/10] Update main.py to match project --- .../rocket_launch_example/main.py | 90 +++++++++---------- 1 file changed, 44 insertions(+), 46 deletions(-) diff --git a/lib/tasks/project_components/rocket_launch_example/main.py b/lib/tasks/project_components/rocket_launch_example/main.py index e8637ceff..71cc9488a 100644 --- a/lib/tasks/project_components/rocket_launch_example/main.py +++ b/lib/tasks/project_components/rocket_launch_example/main.py @@ -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() From 725560b5df7c47c8ddc7bfe23d31038a735fb036 Mon Sep 17 00:00:00 2001 From: Mac Bowley <36036152+m-bowley@users.noreply.github.com> Date: Fri, 30 Jun 2023 11:28:39 +0100 Subject: [PATCH 10/10] Update main.py - fixing tabulation and adding a comment --- .../project_components/make_a_face_starter/main.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/tasks/project_components/make_a_face_starter/main.py b/lib/tasks/project_components/make_a_face_starter/main.py index 140cbaadf..3641009ad 100644 --- a/lib/tasks/project_components/make_a_face_starter/main.py +++ b/lib/tasks/project_components/make_a_face_starter/main.py @@ -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()