From be429dbddd11d7cfd7e8a7c767f821e127fbdf94 Mon Sep 17 00:00:00 2001 From: Lois Wells Date: Thu, 17 Mar 2022 14:41:25 +0000 Subject: [PATCH 01/13] Rocket launch content --- .../rocket_launch_example/main.py | 72 +++++++++++++++++++ .../rocket_launch_example/project_config.yml | 8 +++ .../rocket_launch_starter/main.py | 28 ++++++++ .../rocket_launch_starter/project_config.yml | 8 +++ 4 files changed, 116 insertions(+) create mode 100644 lib/tasks/project_components/rocket_launch_example/main.py create mode 100644 lib/tasks/project_components/rocket_launch_example/project_config.yml create mode 100644 lib/tasks/project_components/rocket_launch_starter/main.py create mode 100644 lib/tasks/project_components/rocket_launch_starter/project_config.yml diff --git a/lib/tasks/project_components/rocket_launch_example/main.py b/lib/tasks/project_components/rocket_launch_example/main.py new file mode 100644 index 000000000..e8637ceff --- /dev/null +++ b/lib/tasks/project_components/rocket_launch_example/main.py @@ -0,0 +1,72 @@ +#!/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 + +# The draw_rocket function goes here +def draw_rocket(): + + 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 + + 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() + + +# 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) + + +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') + + +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() diff --git a/lib/tasks/project_components/rocket_launch_example/project_config.yml b/lib/tasks/project_components/rocket_launch_example/project_config.yml new file mode 100644 index 000000000..3fa9056d1 --- /dev/null +++ b/lib/tasks/project_components/rocket_launch_example/project_config.yml @@ -0,0 +1,8 @@ +NAME: "Rocket Launch Example" +IDENTIFIER: "rocket-launch-example" +COMPONENTS: + - name: "main" + extension: "py" + location: "main.py" + index: 0 + default: true diff --git a/lib/tasks/project_components/rocket_launch_starter/main.py b/lib/tasks/project_components/rocket_launch_starter/main.py new file mode 100644 index 000000000..e95dc10f9 --- /dev/null +++ b/lib/tasks/project_components/rocket_launch_starter/main.py @@ -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() diff --git a/lib/tasks/project_components/rocket_launch_starter/project_config.yml b/lib/tasks/project_components/rocket_launch_starter/project_config.yml new file mode 100644 index 000000000..5f0b9d7c8 --- /dev/null +++ b/lib/tasks/project_components/rocket_launch_starter/project_config.yml @@ -0,0 +1,8 @@ +NAME: "Rocket Launch" +IDENTIFIER: "rocket-launch-starter" +COMPONENTS: + - name: "main" + extension: "py" + location: "main.py" + index: 0 + default: true From d0642f686c3db712cbdd6bbbb8578318bcc7b20b Mon Sep 17 00:00:00 2001 From: Lois Wells Date: Thu, 17 Mar 2022 16:30:53 +0000 Subject: [PATCH 02/13] Make a face starter and example content --- .../make_a_face_animated_example/main.py | 46 +++++++++ .../project_config.yml | 8 ++ .../make_a_face_interactive_example/main.py | 58 +++++++++++ .../project_config.yml | 8 ++ .../make_a_face_kawaii_fruit_example/main.py | 42 ++++++++ .../project_config.yml | 8 ++ .../make_a_face_stacked_faces_example/main.py | 96 +++++++++++++++++++ .../project_config.yml | 8 ++ .../make_a_face_starter/main.py | 15 +++ .../make_a_face_starter/project_config.yml | 8 ++ .../make_a_face_tribal_mask_example/main.py | 55 +++++++++++ .../project_config.yml | 8 ++ 12 files changed, 360 insertions(+) create mode 100644 lib/tasks/project_components/make_a_face_animated_example/main.py create mode 100644 lib/tasks/project_components/make_a_face_animated_example/project_config.yml create mode 100644 lib/tasks/project_components/make_a_face_interactive_example/main.py create mode 100644 lib/tasks/project_components/make_a_face_interactive_example/project_config.yml create mode 100644 lib/tasks/project_components/make_a_face_kawaii_fruit_example/main.py create mode 100644 lib/tasks/project_components/make_a_face_kawaii_fruit_example/project_config.yml create mode 100644 lib/tasks/project_components/make_a_face_stacked_faces_example/main.py create mode 100644 lib/tasks/project_components/make_a_face_stacked_faces_example/project_config.yml create mode 100644 lib/tasks/project_components/make_a_face_starter/main.py create mode 100644 lib/tasks/project_components/make_a_face_starter/project_config.yml create mode 100644 lib/tasks/project_components/make_a_face_tribal_mask_example/main.py create mode 100644 lib/tasks/project_components/make_a_face_tribal_mask_example/project_config.yml diff --git a/lib/tasks/project_components/make_a_face_animated_example/main.py b/lib/tasks/project_components/make_a_face_animated_example/main.py new file mode 100644 index 000000000..d88241be9 --- /dev/null +++ b/lib/tasks/project_components/make_a_face_animated_example/main.py @@ -0,0 +1,46 @@ +#!/bin/python3 + +from processing import * +import random + +def setup(): + size(400, 400) + noStroke() + frameRate(5) + + +def draw(): + background(255) + + # Hair and face + fill(0) + ellipse(200, 220, 220, 230) + fill(251, 233, 201) + ellipse(200, 245, 200, 200) + fill(0) + ellipse(245, 185, 120, 130) + ellipse(155, 185, 120, 130) + fill(230 , 108, 129) + for i in range (0, 30): + fill(random.randint(100, 230) , random.randint(90, 110), random.randint(100, 130)) + ellipse(random.randint(100,300), random.randint(150,210), 20, 20) + + # Eyes + fill(0) + ellipse(160, 270, 85, 30) + ellipse(240, 270, 85, 30) + fill(251, 233, 201) + ellipse(160, 280, 80, 30) + ellipse(240, 280, 80, 30) + fill(0) + ellipse(160, 290, 30, 30) + ellipse(240, 290, 30, 30) + fill(255) + ellipse(165, 285, 10, 10) + ellipse(245, 285, 10, 10) + + # Mouth + fill(0) + rect(185, 320, 30, 5) + +run() diff --git a/lib/tasks/project_components/make_a_face_animated_example/project_config.yml b/lib/tasks/project_components/make_a_face_animated_example/project_config.yml new file mode 100644 index 000000000..57df63fb2 --- /dev/null +++ b/lib/tasks/project_components/make_a_face_animated_example/project_config.yml @@ -0,0 +1,8 @@ +NAME: "Make A Face Animated Example" +IDENTIFIER: "animated-face-example" +COMPONENTS: + - name: "main" + extension: "py" + location: "main.py" + index: 0 + default: true diff --git a/lib/tasks/project_components/make_a_face_interactive_example/main.py b/lib/tasks/project_components/make_a_face_interactive_example/main.py new file mode 100644 index 000000000..b50630044 --- /dev/null +++ b/lib/tasks/project_components/make_a_face_interactive_example/main.py @@ -0,0 +1,58 @@ +#!/bin/python3 + +from p5 import * +from random import randint + +def sad(x_middle, y_eye, y_mouth): + ellipse(x_middle - 50, y_eye - 20, 60, 50) # x, y, width, height + ellipse(x_middle + 50, y_eye - 20, 60, 50) + ellipse(x_middle, y_mouth + 30, 100, 65) + +def happy(x_middle, y_eye, y_mouth): + ellipse(x_middle - 50, y_eye + 20, 60, 50) # x, y, width, height + ellipse(x_middle + 50, y_eye + 20, 60, 50) + ellipse(x_middle, y_mouth - 30, 100, 65) + +def setup(): +# Put code to run once here + size(400, 400) # width and height + background(0, 0, 0) # move under draw() to reset the drawing every frame + rect_mode(CENTER) + no_stroke() + +def draw(): +# Put code to run every frame here + mask_width = width / 2 + x_middle = width / 2 + y_eye = 180 + y_mouth = 255 + # draw mask + fill(255, 255, 255) # white + rect(200, 150, mask_width, mask_width) + ellipse(x_middle, 250, mask_width, 140) + # eyes and mouth + fill(0) # black + ellipse(x_middle - 50, y_eye, 60, 50) # x, y, width, height + ellipse(x_middle + 50 , y_eye, 60, 50) + ellipse(x_middle, y_mouth, 100, 75) + # partly cover eyes and mouth + fill(255) + if mouse_x > x_middle: + happy(x_middle, y_eye, y_mouth) + else: + sad(x_middle, y_eye, y_mouth) + # cover top of mask + fill(0) + ellipse(x_middle, 60, 250, 90) + # shade half of the mask + fill(0, 25) + rect(300, 200, width/2, height) + #grid() + +def mouse_pressed(): +# Put code to run when the mouse is pressed here + print(mouse_x, mouse_y) + +# Keep this to run your code +run() + diff --git a/lib/tasks/project_components/make_a_face_interactive_example/project_config.yml b/lib/tasks/project_components/make_a_face_interactive_example/project_config.yml new file mode 100644 index 000000000..aa6cd38fb --- /dev/null +++ b/lib/tasks/project_components/make_a_face_interactive_example/project_config.yml @@ -0,0 +1,8 @@ +NAME: "Make A Face Interactive Example" +IDENTIFIER: "interactive-face-example" +COMPONENTS: + - name: "main" + extension: "py" + location: "main.py" + index: 0 + default: true diff --git a/lib/tasks/project_components/make_a_face_kawaii_fruit_example/main.py b/lib/tasks/project_components/make_a_face_kawaii_fruit_example/main.py new file mode 100644 index 000000000..6110a85fb --- /dev/null +++ b/lib/tasks/project_components/make_a_face_kawaii_fruit_example/main.py @@ -0,0 +1,42 @@ +#!/bin/python3 + +from processing import * + +def setup(): + size(400, 400) + noStroke() + + +def draw(): + background(255) + orange = color(255, 165, 0) + brown = color(200, 120, 0) + green = color(100, 155, 0) + fill(orange) + ellipse(200, 200, 200, 190) + fill(0) + # Eyes + ellipse(160, 220, 30, 30) + ellipse(240, 220, 30, 30) + fill(255) + ellipse(165, 215, 10, 10) + ellipse(245, 215, 10, 10) + # Mouth + fill(0) + ellipse(200, 240, 15, 15) + fill(orange) + ellipse(200, 235, 15, 15) + # Highlights + fill(255, 70) + ellipse(170, 150, 35, 35) + ellipse(150, 160, 25, 25) + # stalk + fill(brown) + triangle(200, 130, 220, 60, 240, 60); + fill(green) + translate(180, 85) + rotate(radians(45)) + ellipse(0, 0, 75, 35) + +run() + diff --git a/lib/tasks/project_components/make_a_face_kawaii_fruit_example/project_config.yml b/lib/tasks/project_components/make_a_face_kawaii_fruit_example/project_config.yml new file mode 100644 index 000000000..2cedb232d --- /dev/null +++ b/lib/tasks/project_components/make_a_face_kawaii_fruit_example/project_config.yml @@ -0,0 +1,8 @@ +NAME: "Make A Face Kawaii Fruit Example" +IDENTIFIER: "fruit-face-example" +COMPONENTS: + - name: "main" + extension: "py" + location: "main.py" + index: 0 + default: true diff --git a/lib/tasks/project_components/make_a_face_stacked_faces_example/main.py b/lib/tasks/project_components/make_a_face_stacked_faces_example/main.py new file mode 100644 index 000000000..fe0d87ca7 --- /dev/null +++ b/lib/tasks/project_components/make_a_face_stacked_faces_example/main.py @@ -0,0 +1,96 @@ +#!/bin/python3 + +from processing import * + +def setup(): + size(400, 600) + background(255, 255, 255) + noStroke() + + +def draw(): + blue = color(92, 204, 206) + green = color(149, 212, 122) + red = color(239, 62, 91) + purple = color(75, 37, 109) + brown = color(178, 162, 150) + grey = color(201, 201, 201) + lilac = color(160, 158, 214) + + # Top face background + fill(blue) + rect(50, 100, 300, 200) + fill(0) + + # Top face Hair + fill(purple) + gap = 0 + for i in range (0,5): + triangle(100+gap, 140, 120+gap, 120, 140+gap, 140) + gap = gap+40 + + # Top face Left Eye + fill(grey) + rect(80, 190, 100, 50) + fill(red) + triangle(190, 250, 70, 150, 180, 160); + fill(green) + triangle(190, 250, 60, 160, 180, 170); + fill(lilac) + ellipse(160, 200, 30, 30) + + # Top face Right Eye + fill(grey) + rect(220, 190, 100, 50) + fill(red) + triangle(210, 250, 330, 150, 220, 160); + fill(green) + triangle(210, 250, 340, 160, 220, 170); + fill(lilac) + ellipse(240, 200, 30, 30) + + # Top face Mouth + fill(brown) + rect(100, 220, 200, 50) + fill(purple) + rect(110, 240, 180, 10) + +# Bottom face background + fill(purple) + rect(50, 300, 300, 200) + fill(0) + + # Bottom face Hair + fill(green) + gap = 0 + for i in range (0,5): + triangle(100+gap, 340, 120+gap, 320, 140+gap, 340) + gap = gap+40 + + # Bottom face Left Eye + fill(red) + rect(80, 390, 100, 50) + fill(lilac) + triangle(190, 450, 70, 350, 180, 360); + fill(brown) + triangle(190, 450, 60, 360, 180, 370); + fill(purple) + ellipse(160, 400, 30, 30) + + # Bottom face Right Eye + fill(red) + rect(220, 390, 100, 50) + fill(lilac) + triangle(210, 450, 330, 350, 220, 360); + fill(brown) + triangle(210, 450, 340, 360, 220, 370); + fill(purple) + ellipse(240, 400, 30, 30) + + # Bottom face Mouth + fill(green) + rect(100, 420, 200, 50) + fill(red) + rect(110, 440, 180, 10) + +run() diff --git a/lib/tasks/project_components/make_a_face_stacked_faces_example/project_config.yml b/lib/tasks/project_components/make_a_face_stacked_faces_example/project_config.yml new file mode 100644 index 000000000..2db4d49e2 --- /dev/null +++ b/lib/tasks/project_components/make_a_face_stacked_faces_example/project_config.yml @@ -0,0 +1,8 @@ +NAME: "Make A Face: Stacked Faces Example" +IDENTIFIER: "stacked-faces-example" +COMPONENTS: + - name: "main" + extension: "py" + location: "main.py" + index: 0 + default: true diff --git a/lib/tasks/project_components/make_a_face_starter/main.py b/lib/tasks/project_components/make_a_face_starter/main.py new file mode 100644 index 000000000..192cb2b41 --- /dev/null +++ b/lib/tasks/project_components/make_a_face_starter/main.py @@ -0,0 +1,15 @@ +#!/bin/python3 + +from p5 import * + +def setup(): + # 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 + +# Keep this to run your code +run() diff --git a/lib/tasks/project_components/make_a_face_starter/project_config.yml b/lib/tasks/project_components/make_a_face_starter/project_config.yml new file mode 100644 index 000000000..4c2ab09e6 --- /dev/null +++ b/lib/tasks/project_components/make_a_face_starter/project_config.yml @@ -0,0 +1,8 @@ +NAME: "Make A Face" +IDENTIFIER: "make-face-starter" +COMPONENTS: + - name: "main" + extension: "py" + location: "main.py" + index: 0 + default: true diff --git a/lib/tasks/project_components/make_a_face_tribal_mask_example/main.py b/lib/tasks/project_components/make_a_face_tribal_mask_example/main.py new file mode 100644 index 000000000..af469d042 --- /dev/null +++ b/lib/tasks/project_components/make_a_face_tribal_mask_example/main.py @@ -0,0 +1,55 @@ +#!/bin/python3 + +from processing import * + +def setup(): + size(400, 400) + noStroke() + + +def draw(): + background(255) + fill(74, 50, 47) + ellipse(200, 200, 200, 190) + fill(0) + + # Eyes + fill(175, 65, 0) + ellipse(160, 180, 60, 60) + ellipse(240, 180, 60, 60) + fill(0) + ellipse(160, 180, 30, 30) + ellipse(240, 180, 30, 30) + fill(255) + ellipse(165, 175, 10, 10) + ellipse(245, 175, 10, 10) + + # Nose + fill(108, 75, 73) + triangle(185, 240, 200, 160, 215, 240) + + # Face markings + gap = 0 + for i in range (0,6): + fill(0, 240, 209) + ellipse(150+gap, 140, 10, 10) + fill(108, 75, 73) + ellipse(150+gap, 220, 10, 10) + gap = gap+20 + + # Mouth + fill(185, 85, 0) + ellipse(190, 260, 30, 30) + ellipse(210, 260, 30, 30) + ellipse(195, 275, 20, 20) + ellipse(205, 275, 20, 20) + fill(0) + rect(185, 265, 30, 3) + + # Hair + fill(246, 170, 19) + triangle(200, 130, 220, 60, 240, 60) + triangle(200, 130, 180, 60, 160, 60) + +run() + diff --git a/lib/tasks/project_components/make_a_face_tribal_mask_example/project_config.yml b/lib/tasks/project_components/make_a_face_tribal_mask_example/project_config.yml new file mode 100644 index 000000000..b800c6acd --- /dev/null +++ b/lib/tasks/project_components/make_a_face_tribal_mask_example/project_config.yml @@ -0,0 +1,8 @@ +NAME: "Make A Face: Tribal Mask Example" +IDENTIFIER: "tribal-mask-example" +COMPONENTS: + - name: "main" + extension: "py" + location: "main.py" + index: 0 + default: true From 3cf7bc6dde01a1288981cd2dc42153faee9fccea Mon Sep 17 00:00:00 2001 From: Lois Wells Date: Thu, 17 Mar 2022 16:31:27 +0000 Subject: [PATCH 03/13] Dont collide starter and example content --- .../dont-collide-starter/main.py | 18 +++ .../dont-collide-starter/project_config.yml | 8 ++ .../dont_collide_avoid_germs_example/main.py | 122 +++++++++++++++++ .../project_config.yml | 8 ++ .../dont_collide_clean_car_example/main.py | 86 ++++++++++++ .../project_config.yml | 8 ++ .../main.py | 129 ++++++++++++++++++ .../project_config.yml | 8 ++ .../dont_collide_dont_pop_example/main.py | 79 +++++++++++ .../project_config.yml | 8 ++ .../dont_collide_skiing_cat_example/main.py | 75 ++++++++++ .../project_config.yml | 8 ++ 12 files changed, 557 insertions(+) create mode 100644 lib/tasks/project_components/dont-collide-starter/main.py create mode 100644 lib/tasks/project_components/dont-collide-starter/project_config.yml create mode 100644 lib/tasks/project_components/dont_collide_avoid_germs_example/main.py create mode 100644 lib/tasks/project_components/dont_collide_avoid_germs_example/project_config.yml create mode 100644 lib/tasks/project_components/dont_collide_clean_car_example/main.py create mode 100644 lib/tasks/project_components/dont_collide_clean_car_example/project_config.yml create mode 100644 lib/tasks/project_components/dont_collide_dodge_asteroids_example/main.py create mode 100644 lib/tasks/project_components/dont_collide_dodge_asteroids_example/project_config.yml create mode 100644 lib/tasks/project_components/dont_collide_dont_pop_example/main.py create mode 100644 lib/tasks/project_components/dont_collide_dont_pop_example/project_config.yml create mode 100644 lib/tasks/project_components/dont_collide_skiing_cat_example/main.py create mode 100644 lib/tasks/project_components/dont_collide_skiing_cat_example/project_config.yml diff --git a/lib/tasks/project_components/dont-collide-starter/main.py b/lib/tasks/project_components/dont-collide-starter/main.py new file mode 100644 index 000000000..2856d8e41 --- /dev/null +++ b/lib/tasks/project_components/dont-collide-starter/main.py @@ -0,0 +1,18 @@ +#!/bin/python3 + +from p5 import * +from random import randint, seed + +# Include global variables here + + +def setup(): +# Put code to run once here + + +def draw(): +# Put code to run every frame here + + +# Keep this to run your code +run() diff --git a/lib/tasks/project_components/dont-collide-starter/project_config.yml b/lib/tasks/project_components/dont-collide-starter/project_config.yml new file mode 100644 index 000000000..b1b634032 --- /dev/null +++ b/lib/tasks/project_components/dont-collide-starter/project_config.yml @@ -0,0 +1,8 @@ +NAME: "Don't Collide!" +IDENTIFIER: "dont-collide-starter" +COMPONENTS: + - name: "main" + extension: "py" + location: "main.py" + index: 0 + default: true diff --git a/lib/tasks/project_components/dont_collide_avoid_germs_example/main.py b/lib/tasks/project_components/dont_collide_avoid_germs_example/main.py new file mode 100644 index 000000000..e62012514 --- /dev/null +++ b/lib/tasks/project_components/dont_collide_avoid_germs_example/main.py @@ -0,0 +1,122 @@ +#!/bin/python3 + +from p5 import * +from random import randint, seed + +level = 1 +score = 0 + +def safe_player(): + + global player_y + + # Face + fill(200, 134, 145) + ellipse(mouse_x, player_y, 60, 60) + + # Eyes + fill(178, 200, 145) + ellipse(mouse_x - 10, player_y - 10, 20, 20) + ellipse(mouse_x + 10, player_y - 10, 20, 20) + fill(0) + ellipse(mouse_x - 10, player_y - 10, 10, 10) + ellipse(mouse_x + 10, player_y - 10, 10, 10) + fill(255) + ellipse(mouse_x - 12, player_y - 12, 5, 5) + ellipse(mouse_x + 12, player_y - 12, 5, 5) + + # Mouth + fill(0) + ellipse(mouse_x, player_y + 10, 15, 10) + fill(200, 134, 145) + ellipse(mouse_x, player_y + 5, 10, 10) + +def crashed_player(): + + global player_y + + # Face + fill(178, 200, 145) + ellipse(mouse_x, player_y, 60, 60) + + # Eyes + fill(149, 161, 195) + ellipse(mouse_x - 10, player_y - 10, 20, 20) + ellipse(mouse_x + 10, player_y - 10, 20, 20) + fill(0) + ellipse(mouse_x - 10, player_y - 10, 10, 10) + ellipse(mouse_x + 10, player_y - 10, 10, 10) + fill(255) + ellipse(mouse_x - 12, player_y - 12, 5, 5) + ellipse(mouse_x + 12, player_y - 12, 5, 5) + + # Mouth + fill(0) + ellipse(mouse_x, player_y + 15, 15, 10) + fill(178, 200, 145) + ellipse(mouse_x, player_y + 20, 10, 10) + +def draw_player(): + + global player_y, safe, score, level + + player_y = int(height * 0.8) + + collide = get(mouse_x, player_y) + collide2 = get(mouse_x, player_y + 30) + collide3 = get(mouse_x + 30, player_y) + collide4 = get(mouse_x, player_y - 30) + + if mouse_x < width: # off the left of the screen + collide2 = safe + + if mouse_x > width: # off the right of the screen + collide3 = safe + + #print(collide, collide2, collide3, collide4) + + if collide == safe and collide2 == safe and collide3 == safe and collide4 == safe: + safe_player() + score += level + else: # Collided + crashed_player() + level = 0 + +def draw_obstacles(): + + global level + + seed(41143644) + + if frame_count & height == height - 1 and level < 5: + level += 1 + print('You reached level', level) + + for i in range(9 + level): + ob_x = randint(0, width) + ob_y = randint(0, height) + frame_count + ob_y %= height + text('🦠', ob_x, ob_y) + +def setup(): +# Put code to run once here + size(400, 400) # width and height + noStroke() + text_size(40) + text_align(CENTER, TOP) + +def draw(): +# Put code to run every frame here + global safe, score, level + + safe = color(149, 161, 195) + + if level > 0: + background(safe) + fill(145, 134, 126) + text('Score: ' + str(score), width/2, 20) + draw_obstacles() + draw_player() + +# Keep this to run your code +run() diff --git a/lib/tasks/project_components/dont_collide_avoid_germs_example/project_config.yml b/lib/tasks/project_components/dont_collide_avoid_germs_example/project_config.yml new file mode 100644 index 000000000..59324b6f7 --- /dev/null +++ b/lib/tasks/project_components/dont_collide_avoid_germs_example/project_config.yml @@ -0,0 +1,8 @@ +NAME: "Don't Collide: Skiing Cat" +IDENTIFIER: "skiing-cat-example" +COMPONENTS: + - name: "main" + extension: "py" + location: "main.py" + index: 0 + default: true diff --git a/lib/tasks/project_components/dont_collide_clean_car_example/main.py b/lib/tasks/project_components/dont_collide_clean_car_example/main.py new file mode 100644 index 000000000..e8c63ee4f --- /dev/null +++ b/lib/tasks/project_components/dont_collide_clean_car_example/main.py @@ -0,0 +1,86 @@ +#!/bin/python3 + +# Import library code +from p5 import * +from random import randint, seed + +level = 1 +score = 0 + +# The draw_obstacle function goes here +def draw_obstacles(): + + global level + + seed(123456789) + + if frame_count % width == width - 1 and level < 10: + level += 1 + print('You reached level', level) + + for i in range(6 + level): + ob_x = randint(0, width) - (frame_count * level) + ob_y = randint(0, height) + ob_x %= width # wrap around + text('πŸ’©', ob_x, ob_y) + +# The draw_player function goes here +def draw_player(): + + global score, level + + player_x = int(width * 0.2) + player_y = mouse_y + + collide = get(player_x + 50, player_y + 15) + collide2 = get(player_x + 50, player_y - 15) + collide3 = get(player_x, player_y + 15) + collide4 = get(player_x, player_y - 15) + collide5 = get(player_x - 50, player_y + 15) + collide6 = get(player_x - 50, player_y - 15) + + if player_y > height - 18: # Off the bottom of the screen + collide = safe + collide3 = safe + collide5 = safe + + elif player_y < 18: # Off the top of the screen + collide2 = safe + collide4 = safe + collide6 = safe + + if collide == safe and collide2 == safe and collide3 == safe and collide4 == safe: + image(car, player_x, player_y, 100, 31) + score += level + else: + text('πŸ’₯', player_x, player_y) + level = 0 + + +def setup(): + # Setup your animation here + global car + + size(400, 400) + car = load_image('car.png') + image_mode(CENTER) + + +def draw(): + # Things to do in every frame + global score, safe, level + safe = color(128) + + if level > 0: + background(safe) + fill(255) + text_size(16) + text_align(RIGHT, TOP) + text('Score', width * 0.45, 10, width * 0.5, 20) + text(str(score), width * 0.45, 25, width * 0.5, 20) + text_size(20) + text_align(CENTER, TOP) # position around the centre, top + draw_obstacles() + draw_player() + +run() diff --git a/lib/tasks/project_components/dont_collide_clean_car_example/project_config.yml b/lib/tasks/project_components/dont_collide_clean_car_example/project_config.yml new file mode 100644 index 000000000..298aafcc3 --- /dev/null +++ b/lib/tasks/project_components/dont_collide_clean_car_example/project_config.yml @@ -0,0 +1,8 @@ +NAME: "Don't Collide: Clean Car" +IDENTIFIER: "clean-car-example" +COMPONENTS: + - name: "main" + extension: "py" + location: "main.py" + index: 0 + default: true diff --git a/lib/tasks/project_components/dont_collide_dodge_asteroids_example/main.py b/lib/tasks/project_components/dont_collide_dodge_asteroids_example/main.py new file mode 100644 index 000000000..513948065 --- /dev/null +++ b/lib/tasks/project_components/dont_collide_dodge_asteroids_example/main.py @@ -0,0 +1,129 @@ +#!/bin/python3 + +# Import library code +from p5 import * +from random import randint, seed + +level = 1 +score = 0 +lives = 3 +invun = 0 + +# The draw_obstacle function goes here +def draw_obstacles(): + + global level + + seed(random_seed) + + if frame_count % height == height - 1 and level < 8: + level += 1 + print('You reached level', level) + + for i in range(6 + level): + ob_x = randint(0, width) + ob_y = randint(0, height) + (frame_count * level) + ob_y %= height # wrap around + push_matrix() + translate(ob_x, ob_y) + rotate(degrees(randint(1, 359)+frame_count / 1000)) + image(rock, 0, 0, randint(18,24), randint(18,24)) + pop_matrix() + + +# The draw_player function goes here +def draw_player(): + + global score, level, lives, invun + + player_y = int(height * 0.8) + player_x = mouse_x + + collide = get(player_x, player_y) + collide2 = get(player_x - 18, player_y + 17) + collide3 = get(player_x + 18, player_y + 17) + collide4 = get(player_x, player_y + 25) + + if player_x < width: # off the left of the screen + collide2 = safe + + if player_x > width: # off the right of the screen + collide3 = safe + + if (collide == safe and collide2 == safe and collide3 == safe and collide4 == safe) or invun > 0: + if lives == 0 and frame_count % 12 == 0: + tint(200, 0, 0) + + image(rocket, player_x, player_y + 25, 64, 64) + score += level + invun -= 1 + no_tint() + + if invun > 0: + stroke(220) + fill(220, 220, 220, 60) + ellipse(player_x, player_y + 18, 47, 47) + + elif lives > 0: + lives -= 1 + invun = 50 + tint(200, 0, 0) + image(rocket, player_x, player_y + 25, 64, 64) + no_tint() + score += level + else: + text('πŸ’₯', player_x + 10, player_y + 5) + level = 0 + + +def display_score(): + global level + + fill(255) + text_size(16) + text_align(RIGHT, TOP) + text('Score', width * 0.45, 10, width * 0.5, 20) + text(str(score), width * 0.45, 25, width * 0.5, 20) + + if score > 10000: + level = 0 + print('πŸŽ‰πŸŽ‰ You win! πŸŽ‰πŸŽ‰') + + +def display_lives(): + fill(255) + text_size(16) + text_align(LEFT, TOP) + text('Lives', width * 0.05, 10, 30, 20) + + for i in range(lives): + image(rocket, width * 0.05 + i * 25, 40, 20, 20) + + +def setup(): + # Setup your animation here + global rocket, rock, random_seed + + text_size(40) + text_align(CENTER, TOP) # position around the centre, top + size(400, 400) + + rocket = load_image('rocket.png') + rock = load_image('moon.png') + random_seed = randint(0, 1000000) + +def draw(): + # Things to do in every frame + global score, safe, level + safe = color(0) + + if level > 0: + background(safe) + fill(255) + image_mode(CENTER) + draw_obstacles() + draw_player() + display_score() + display_lives() + +run() diff --git a/lib/tasks/project_components/dont_collide_dodge_asteroids_example/project_config.yml b/lib/tasks/project_components/dont_collide_dodge_asteroids_example/project_config.yml new file mode 100644 index 000000000..59324b6f7 --- /dev/null +++ b/lib/tasks/project_components/dont_collide_dodge_asteroids_example/project_config.yml @@ -0,0 +1,8 @@ +NAME: "Don't Collide: Skiing Cat" +IDENTIFIER: "skiing-cat-example" +COMPONENTS: + - name: "main" + extension: "py" + location: "main.py" + index: 0 + default: true diff --git a/lib/tasks/project_components/dont_collide_dont_pop_example/main.py b/lib/tasks/project_components/dont_collide_dont_pop_example/main.py new file mode 100644 index 000000000..457e65302 --- /dev/null +++ b/lib/tasks/project_components/dont_collide_dont_pop_example/main.py @@ -0,0 +1,79 @@ +#!/bin/python3 + +# Import library code +from p5 import * +from random import randint, seed + +level = 1 +score = 0 + +# The draw_obstacle function goes here +def draw_obstacles(): + + global level + + seed(12345678) + + if frame_count % height == height - 1 and level < 5: + level += 1 + print('You reached level', level) + + for i in range(6 + level): + ob_x = randint(0, height) + ob_y = randint(0, height) + (frame_count * level) + ob_y %= height # wrap around + text('🌡', ob_x, ob_y) + + +# The draw_player function goes here +def draw_player(): + + global score, level + + player_y = int(height * 0.8) + + no_fill() + #ellipse(mouse_x, player_y, 10, 10) # draw collision point + #ellipse(mouse_x, player_y + 40, 10, 10) + #ellipse(mouse_x - 12, player_y + 20, 10, 10) + #ellipse(mouse_x + 12, player_y + 20, 10, 10) + + collide = get(mouse_x, player_y) + collide2 = get(mouse_x - 12, player_y + 20) + collide3 = get(mouse_x + 12, player_y + 20) + collide4 = get(mouse_x, player_y + 40) + + if mouse_x < width: # off the left of the screen + collide2 = safe + + if mouse_x > width: # off the right of the screen + collide3 = safe + + if collide == safe and collide2 == safe and collide3 == safe and collide4 == safe: + text('🎈', mouse_x, player_y) + score += level + else: + text('πŸ’₯', mouse_x, player_y) + level = 0 + + +def setup(): + # Setup your animation here + text_size(40) + text_align(CENTER, TOP) # position around the centre, top + size(400, 400) + + +def draw(): + # Things to do in every frame + global score, safe, level + safe = color(200, 150, 0) + + if level > 0: + background(safe) + fill(255) + text('Score: ' + str(score), width/2, 20) + draw_obstacles() + draw_player() + +run() diff --git a/lib/tasks/project_components/dont_collide_dont_pop_example/project_config.yml b/lib/tasks/project_components/dont_collide_dont_pop_example/project_config.yml new file mode 100644 index 000000000..59324b6f7 --- /dev/null +++ b/lib/tasks/project_components/dont_collide_dont_pop_example/project_config.yml @@ -0,0 +1,8 @@ +NAME: "Don't Collide: Skiing Cat" +IDENTIFIER: "skiing-cat-example" +COMPONENTS: + - name: "main" + extension: "py" + location: "main.py" + index: 0 + default: true diff --git a/lib/tasks/project_components/dont_collide_skiing_cat_example/main.py b/lib/tasks/project_components/dont_collide_skiing_cat_example/main.py new file mode 100644 index 000000000..d68fc9762 --- /dev/null +++ b/lib/tasks/project_components/dont_collide_skiing_cat_example/main.py @@ -0,0 +1,75 @@ +#!/bin/python3 + +# Import library code +from p5 import * +from random import randint, seed + +speed = 1 +score = 0 + +# The draw_background function goes here +def draw_obstacles(): + + global speed + + seed(12345678) + + if frame_count % height == height - 1 and speed < 5: + speed += 1 + print('You reached level', speed) + + for i in range(6): + ob_x = randint(0, height) + ob_y = randint(0, height) + (frame_count * speed) + ob_y %= height # wrap around + no_stroke() + fill(0,255,0) + triangle(ob_x + 20, ob_y + 20, ob_x + 10, ob_y + 40, ob_x + 30, ob_y + 40) + triangle(ob_x + 20, ob_y + 30, ob_x + 5, ob_y + 55, ob_x + 35, ob_y + 55) + triangle(ob_x + 20, ob_y + 40, ob_x + 0, ob_y + 70, ob_x + 40, ob_y + 70) + fill(150,100,100) + rect(ob_x + 15, ob_y + 70, 10, 10) + +# The draw_player function goes here +def draw_player(): + + global score, speed, skiing, crashed + + player_y = int(height * 0.8) + + fill(safe) + + collide = get(mouse_x, player_y) + + if collide == safe: + image(skiing, mouse_x, player_y, 30, 30) + score += speed + else: + image(crashed, mouse_x, player_y, 30, 30) + speed = 0 + + +def setup(): + + global skiing, crashed + + # Setup your animation here + text_size(40) + text_align(CENTER, TOP) # position around the centre + size(400, 400) + skiing = load_image('skiing.png') + crashed = load_image('fallenover.png') + +def draw(): + # Things to do in every frame + global score, safe, speed, skiing, crashed + safe = color(255) + + if speed > 0: + background(safe) + fill(0) + text('Score: ' + str(score), width/2, 20) + draw_obstacles() + draw_player() + +run() diff --git a/lib/tasks/project_components/dont_collide_skiing_cat_example/project_config.yml b/lib/tasks/project_components/dont_collide_skiing_cat_example/project_config.yml new file mode 100644 index 000000000..59324b6f7 --- /dev/null +++ b/lib/tasks/project_components/dont_collide_skiing_cat_example/project_config.yml @@ -0,0 +1,8 @@ +NAME: "Don't Collide: Skiing Cat" +IDENTIFIER: "skiing-cat-example" +COMPONENTS: + - name: "main" + extension: "py" + location: "main.py" + index: 0 + default: true From 3957c4c6f614cb0cf190c55dca66fbbf81e22d28 Mon Sep 17 00:00:00 2001 From: Lois Wells Date: Thu, 17 Mar 2022 17:11:23 +0000 Subject: [PATCH 04/13] Powerful patterns starter and example content --- .../main.py | 46 +++++++++++ .../project_config.yml | 8 ++ .../main.py | 67 ++++++++++++++++ .../project_config.yml | 8 ++ .../main.py | 79 +++++++++++++++++++ .../project_config.yml | 8 ++ .../main.py | 37 +++++++++ .../project_config.yml | 8 ++ .../powerful_patterns_spirals_example/main.py | 30 +++++++ .../project_config.yml | 8 ++ .../powerful_patterns_starter/main.py | 19 +++++ .../project_config.yml | 8 ++ .../main.py | 64 +++++++++++++++ .../project_config.yml | 8 ++ 14 files changed, 398 insertions(+) create mode 100644 lib/tasks/project_components/powerful_patterns_art_deco_wallpaper_example/main.py create mode 100644 lib/tasks/project_components/powerful_patterns_art_deco_wallpaper_example/project_config.yml create mode 100644 lib/tasks/project_components/powerful_patterns_kek_lepis_sarawak/main.py create mode 100644 lib/tasks/project_components/powerful_patterns_kek_lepis_sarawak/project_config.yml create mode 100644 lib/tasks/project_components/powerful_patterns_mcewan_tartan_example/main.py create mode 100644 lib/tasks/project_components/powerful_patterns_mcewan_tartan_example/project_config.yml create mode 100644 lib/tasks/project_components/powerful_patterns_random_faces_example/main.py create mode 100644 lib/tasks/project_components/powerful_patterns_random_faces_example/project_config.yml create mode 100644 lib/tasks/project_components/powerful_patterns_spirals_example/main.py create mode 100644 lib/tasks/project_components/powerful_patterns_spirals_example/project_config.yml create mode 100644 lib/tasks/project_components/powerful_patterns_starter/main.py create mode 100644 lib/tasks/project_components/powerful_patterns_starter/project_config.yml create mode 100644 lib/tasks/project_components/powerful_patterns_yakan_weaving_example/main.py create mode 100644 lib/tasks/project_components/powerful_patterns_yakan_weaving_example/project_config.yml diff --git a/lib/tasks/project_components/powerful_patterns_art_deco_wallpaper_example/main.py b/lib/tasks/project_components/powerful_patterns_art_deco_wallpaper_example/main.py new file mode 100644 index 000000000..c46bf2df3 --- /dev/null +++ b/lib/tasks/project_components/powerful_patterns_art_deco_wallpaper_example/main.py @@ -0,0 +1,46 @@ +#!/bin/python3 + +from p5 import * +from random import randint + +def draw_motif(): + orange = color(191, 64, 191) + brown = color(200, 120, 0) + green = color(100, 155, 0) + fill(orange) + ellipse(200, 200, 200, 190) + fill(0) + # Eyes + ellipse(160, 190, 30, 30) + ellipse(240, 190, 30, 30) + fill(255) + ellipse(165, 200, 10, 10) + ellipse(245, 200, 10, 10) + # Mouth + noFill() + stroke(255, 255, 255) + ellipse(150, 250, 30, 30) + ellipse(250, 250, 30, 30) + fill(255, 255, 255) + noStroke() + rect(150, 230, 100, 40) + fill(108, 200, 206) + rect(152, 235, 96, 30) + + +def setup(): + size(400, 400) + background(255) + no_stroke() + frame_rate(10) + + +def draw(): + push_matrix() + translate(randint(-50, 350), randint(-50, 350)) # offset by the width of the quarter-size face + scale(0.25) # quarter size paths + draw_motif() + pop_matrix() + + +run() diff --git a/lib/tasks/project_components/powerful_patterns_art_deco_wallpaper_example/project_config.yml b/lib/tasks/project_components/powerful_patterns_art_deco_wallpaper_example/project_config.yml new file mode 100644 index 000000000..b2aa47154 --- /dev/null +++ b/lib/tasks/project_components/powerful_patterns_art_deco_wallpaper_example/project_config.yml @@ -0,0 +1,8 @@ +NAME: "Powerful Patterns: Art Deco Wallpaper" +IDENTIFIER: "art-deco-example" +COMPONENTS: + - name: "main" + extension: "py" + location: "main.py" + index: 0 + default: true 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 new file mode 100644 index 000000000..4dc73554a --- /dev/null +++ b/lib/tasks/project_components/powerful_patterns_kek_lepis_sarawak/main.py @@ -0,0 +1,67 @@ +#!/bin/python3 + +from draw import * +from time import * + +# Based on the amazing Malaysian geometric cake art: Kek lapis Sarawak + +def quadrant(): + + # Choose some gorgeous colours for the cake layers + turquoise = color(64, 224, 208) + gold = color(255, 215, 0) + tomato = color(255, 99, 71) + + # Jam sticks the layers together + jam = color(255, 165, 0) + stroke(jam) + stroke_weight(2) # Change the number to change the amount of jam + + # Nine layers of cake, repeating the 3 colours 3 times + for i in range(3): + start_y = i * 60 # height of 3 blocks of cake + fill(turquoise) + rect(0, start_y, 180, 20) + fill(gold) + rect(0, start_y + 20, 180, 20) + fill(tomato) + rect(0, start_y + 40, 180, 20) + + +def outer(): + + # Thehe cake is wrapped in an outer layer + yellowgreen = Color(154, 205, 50) + + no_fill() # Don't cover up the cake quadrants! + stroke(yellowgreen) + stroke_weight(20) + rect(10, 10, 380, 380, 20) + + +def setup(): + size(400, 400) # make the cake square + background(255, 255, 255, 0) # transparent background + frame_rate(5) # 5 frames per second + + +def draw(): + + # Define a quarter turn so our code is easy to read + quarter = radians(90) + + translate(200, 200) # start from the center + + # Make the bottom right quarter of the cake then rotate for the other quarters + + if frame_count <= 4: # draw up to 4 quadrants + for i in range(frame_count): + quadrant() + rotate(quarter) + + if frame_count == 5: # add the outer layer + translate(-200, -200) # back to the top corner + outer() # outer layer + + +run() diff --git a/lib/tasks/project_components/powerful_patterns_kek_lepis_sarawak/project_config.yml b/lib/tasks/project_components/powerful_patterns_kek_lepis_sarawak/project_config.yml new file mode 100644 index 000000000..fbf378f6f --- /dev/null +++ b/lib/tasks/project_components/powerful_patterns_kek_lepis_sarawak/project_config.yml @@ -0,0 +1,8 @@ +NAME: "Powerful Patterns: Kek Lepis Sarawak Example" +IDENTIFIER: "repeated-patterns-example" +COMPONENTS: + - name: "main" + extension: "py" + location: "main.py" + index: 0 + default: true diff --git a/lib/tasks/project_components/powerful_patterns_mcewan_tartan_example/main.py b/lib/tasks/project_components/powerful_patterns_mcewan_tartan_example/main.py new file mode 100644 index 000000000..b107f3fc0 --- /dev/null +++ b/lib/tasks/project_components/powerful_patterns_mcewan_tartan_example/main.py @@ -0,0 +1,79 @@ +#!/bin/python3 + +from p5 import * + +def setup(): + size(400, 400) + frame_rate(10) + print('🏴󠁧󠁒󠁳󠁣󠁴󠁿󠁒󠁳󠁣󠁴󠁿 This is McEwen Tartan 🏴󠁧󠁒󠁳󠁣󠁴󠁿󠁧󠁒󠁳󠁣󠁴󠁿') + + global square_size + square_size = int(input('What size 🏴󠁧󠁒󠁳󠁣󠁴󠁿tartan would you like? 20, 50, or 100')) + +def draw(): + + lines = 10 * frame_count # Use in shape width/length to animate over time + + # McEwen tartan colours + # Base square colours + BLUE = color(83, 143, 200) + GREEN = color(78, 163, 162) + BASE_COLORS = [GREEN, BLUE] + + # Cross colours + YELLOW = color(155, 176, 135) + RED = color(155, 129, 113) + CROSS_COLORS = [YELLOW, RED] + + # Stitching and overlap colour + GREY = color(78, 99, 86) + + # Draw all the GREEN and BLUE alternating Base squares + no_stroke() + y_coordinate = 0 + squares = width/square_size + + for i in range (int(squares)): + gap = 0 + for j in range (int(squares)): + fill(BASE_COLORS[j % 2]) # GREEN and BLUE + rect(gap, y_coordinate, square_size, square_size) + gap = gap + square_size + y_coordinate = y_coordinate + square_size + + # Crosses + stroke(GREY) + + # DRAW THE YELLOW and RED alternating crosses + for i in range (4): + fill(YELLOW) + cross = square_size / 2 - 2 + for i in range (int(squares/2)): + fill(CROSS_COLORS[i % 2]) # YELLOW and RED + rect(cross, 0, 4, lines) + rect(0, cross, lines, 4) + cross = cross + 2 * square_size + # Draw the stiching crosses + no_fill() + cross = square_size + square_size / 2 - 2 + for i in range (int(squares)): + rect(cross, 0, 4, lines) + rect(0, cross, lines, 4) + cross = cross + square_size + + # Draw the grey lines where material overlaps + no_stroke() + fill(GREY, 100) + gap = square_size - 4 + for i in range (int(squares)): + rect(gap, 0, 8, lines) + gap = gap + square_size + gap = square_size - 4 + for i in range (int(squares)): + rect(0, gap, lines, 8) + gap = gap + square_size + +run() + + + diff --git a/lib/tasks/project_components/powerful_patterns_mcewan_tartan_example/project_config.yml b/lib/tasks/project_components/powerful_patterns_mcewan_tartan_example/project_config.yml new file mode 100644 index 000000000..018f93580 --- /dev/null +++ b/lib/tasks/project_components/powerful_patterns_mcewan_tartan_example/project_config.yml @@ -0,0 +1,8 @@ +NAME: "Powerful Patterns: McEwen Tartan" +IDENTIFIER: "mcewen-tartan-example" +COMPONENTS: + - name: "main" + extension: "py" + location: "main.py" + index: 0 + default: true diff --git a/lib/tasks/project_components/powerful_patterns_random_faces_example/main.py b/lib/tasks/project_components/powerful_patterns_random_faces_example/main.py new file mode 100644 index 000000000..5616a2838 --- /dev/null +++ b/lib/tasks/project_components/powerful_patterns_random_faces_example/main.py @@ -0,0 +1,37 @@ +#!/bin/python3 + +from p5 import * +from math import random +from random import randint + +def motif(): + global circle_size + for i in range(5): + ellipse(0, 0, circle_size / 5 * (5 - i), circle_size / 5 * (5 - i)) + +def setup(): + size(400, 400) + frame_rate(3) + print('πŸ–Œ This art uses lots of circles!') + + global circle_size + + circle_size = 50 + +def draw(): + + # Pattern colours + stroke(40, 35, 100) # blue + stroke_weight(2) # thick border + fill(200, 180, 128) # gold + + translate(0,0) # start from the top left of the screen + + if frame_count <= 16: # creates 16 rows then stops + for row in range (frame_count): # animates 1 row at a time + for shape in range (16): # create a row of motifs + motif() + translate(circle_size / 2, 0) + translate(-width, circle_size / 2) # move down to start next row + +run() diff --git a/lib/tasks/project_components/powerful_patterns_random_faces_example/project_config.yml b/lib/tasks/project_components/powerful_patterns_random_faces_example/project_config.yml new file mode 100644 index 000000000..f985d326a --- /dev/null +++ b/lib/tasks/project_components/powerful_patterns_random_faces_example/project_config.yml @@ -0,0 +1,8 @@ +NAME: "Powerful Patterns: Random Faces" +IDENTIFIER: "random-faces-example" +COMPONENTS: + - name: "main" + extension: "py" + location: "main.py" + index: 0 + default: true diff --git a/lib/tasks/project_components/powerful_patterns_spirals_example/main.py b/lib/tasks/project_components/powerful_patterns_spirals_example/main.py new file mode 100644 index 000000000..2d953d8f1 --- /dev/null +++ b/lib/tasks/project_components/powerful_patterns_spirals_example/main.py @@ -0,0 +1,30 @@ +#!/bin/python3 + +from p5 import * +from math import random +from random import randint + +def motif(): + fill(randint(0, 255),randint(0, 255) ,randint(0, 255)) + ellipse(0, 0, 25, 25) + fill(0, 0, 0) + ellipse(0, 0, 15, 15) + fill(randint(0, 255),randint(0, 255) ,randint(0, 255)) + for i in range(4): # a short row of squares + rect(i * 5, 0, 5, 5) + +def setup(): + size(400, 400) + frame_rate(10) # fast animation + stroke_weight(2) # thick border + background(255) + +def draw(): + translate(200, 200) # start from the centre of the screen + if frame_count < 150: + for i in range(frame_count): # animates the pattern + motif() + rotate(5) # turns the motif + translate(i,i) # moves the motif + +run() diff --git a/lib/tasks/project_components/powerful_patterns_spirals_example/project_config.yml b/lib/tasks/project_components/powerful_patterns_spirals_example/project_config.yml new file mode 100644 index 000000000..8a99e7eca --- /dev/null +++ b/lib/tasks/project_components/powerful_patterns_spirals_example/project_config.yml @@ -0,0 +1,8 @@ +NAME: "Powerful Patterns: Spirals" +IDENTIFIER: "spirals-pattern-example" +COMPONENTS: + - name: "main" + extension: "py" + location: "main.py" + index: 0 + default: true diff --git a/lib/tasks/project_components/powerful_patterns_starter/main.py b/lib/tasks/project_components/powerful_patterns_starter/main.py new file mode 100644 index 000000000..84f2849da --- /dev/null +++ b/lib/tasks/project_components/powerful_patterns_starter/main.py @@ -0,0 +1,19 @@ +#!/bin/python3 + +from p5 import * +from random import randint + +def setup(): +# Put code to run once here + size(400, 400) + background(255, 255, 255) + + +def draw(): +# Put code to run every frame here + fill(255, 0, 255) + rect(50, 50, 120, 100) + + +# Keep this to run your code +run() diff --git a/lib/tasks/project_components/powerful_patterns_starter/project_config.yml b/lib/tasks/project_components/powerful_patterns_starter/project_config.yml new file mode 100644 index 000000000..9644645b2 --- /dev/null +++ b/lib/tasks/project_components/powerful_patterns_starter/project_config.yml @@ -0,0 +1,8 @@ +NAME: "Powerful Patterns" +IDENTIFIER: "powerful-patterns-starter" +COMPONENTS: + - name: "main" + extension: "py" + location: "main.py" + index: 0 + default: true diff --git a/lib/tasks/project_components/powerful_patterns_yakan_weaving_example/main.py b/lib/tasks/project_components/powerful_patterns_yakan_weaving_example/main.py new file mode 100644 index 000000000..a350a8c1d --- /dev/null +++ b/lib/tasks/project_components/powerful_patterns_yakan_weaving_example/main.py @@ -0,0 +1,64 @@ +#!/bin/python3 + +from p5 import * +from math import random + +def motif(): + motif_size = 100 + + #Thread colours + ORANGE = color(254, 96, 1) + PURPLE = color(135, 18, 192) + YELLOW = color(243, 200, 19) + BLUE = color(83, 171, 176) + + # Squares + fill(ORANGE) + rect(0, 0, motif_size/2, motif_size/2) + fill(PURPLE) + rect(50, 0, motif_size/2, motif_size/2) + fill(YELLOW) + rect(0, 50, motif_size/2, motif_size/2) + fill(BLUE) + rect(50, 50, motif_size/2, motif_size/2) + fill(PURPLE) + rect(0, 0, motif_size/4, motif_size/4) + fill(ORANGE) + rect(50, 0, motif_size/4, motif_size/4) + fill(BLUE) + rect(0, 50, motif_size/4, motif_size/4) + fill(YELLOW) + rect(50, 50, motif_size/4, motif_size/4) + +def rotate_motif(): + + for shape in range(5): # row of shapes + pushMatrix() # save settings + rotate(radians(45)) # turn shape 45 degrees + motif() + popMatrix() # go back to saved settings + translate(motif_width, 0) # move horizontally + +def setup(): + size(400, 400) + frame_rate(3) + background(250, 5, 94) # pink + no_stroke() + print('This is πŸ‡΅πŸ‡­ Yakan weaving ') + +def draw(): + + global motif_width + motif_width = 150 + + translate(-motif_width/2, -motif_width/2) # to start with half motifs + + if frame_count < 20: # maximum rows + for row in range(frame_count): + rotate_motif() + if row / 2 == 0: # to offset pattern on next row + translate(-motif_width * 5 + 75, 80) + else: + translate(-motif_width * 5 - 75, 80) + +run() diff --git a/lib/tasks/project_components/powerful_patterns_yakan_weaving_example/project_config.yml b/lib/tasks/project_components/powerful_patterns_yakan_weaving_example/project_config.yml new file mode 100644 index 000000000..c63596dd8 --- /dev/null +++ b/lib/tasks/project_components/powerful_patterns_yakan_weaving_example/project_config.yml @@ -0,0 +1,8 @@ +NAME: "Powerful Patterns: Yakan Weaving" +IDENTIFIER: "yakan-weaving-example" +COMPONENTS: + - name: "main" + extension: "py" + location: "main.py" + index: 0 + default: true From f6f5f8c56d9299c53849774568cbf0929411a4b9 Mon Sep 17 00:00:00 2001 From: Lois Wells Date: Fri, 18 Mar 2022 09:40:10 +0000 Subject: [PATCH 05/13] Corrections --- .../dont_collide_avoid_germs_example/project_config.yml | 4 ++-- .../dont_collide_dodge_asteroids_example/project_config.yml | 4 ++-- .../dont_collide_dont_pop_example/project_config.yml | 4 ++-- .../project_config.yml | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/tasks/project_components/dont_collide_avoid_germs_example/project_config.yml b/lib/tasks/project_components/dont_collide_avoid_germs_example/project_config.yml index 59324b6f7..f6a4355fe 100644 --- a/lib/tasks/project_components/dont_collide_avoid_germs_example/project_config.yml +++ b/lib/tasks/project_components/dont_collide_avoid_germs_example/project_config.yml @@ -1,5 +1,5 @@ -NAME: "Don't Collide: Skiing Cat" -IDENTIFIER: "skiing-cat-example" +NAME: "Don't Collide: Avoid the Germs" +IDENTIFIER: "avoid-germs-example" COMPONENTS: - name: "main" extension: "py" diff --git a/lib/tasks/project_components/dont_collide_dodge_asteroids_example/project_config.yml b/lib/tasks/project_components/dont_collide_dodge_asteroids_example/project_config.yml index 59324b6f7..dcf0ca6d9 100644 --- a/lib/tasks/project_components/dont_collide_dodge_asteroids_example/project_config.yml +++ b/lib/tasks/project_components/dont_collide_dodge_asteroids_example/project_config.yml @@ -1,5 +1,5 @@ -NAME: "Don't Collide: Skiing Cat" -IDENTIFIER: "skiing-cat-example" +NAME: "Don't Collide: Dodge Asteroids" +IDENTIFIER: "dodge-asteroids-example" COMPONENTS: - name: "main" extension: "py" diff --git a/lib/tasks/project_components/dont_collide_dont_pop_example/project_config.yml b/lib/tasks/project_components/dont_collide_dont_pop_example/project_config.yml index 59324b6f7..94ccf6ab8 100644 --- a/lib/tasks/project_components/dont_collide_dont_pop_example/project_config.yml +++ b/lib/tasks/project_components/dont_collide_dont_pop_example/project_config.yml @@ -1,5 +1,5 @@ -NAME: "Don't Collide: Skiing Cat" -IDENTIFIER: "skiing-cat-example" +NAME: "Don't Collide: Don't Pop" +IDENTIFIER: "dont-pop-example" COMPONENTS: - name: "main" extension: "py" diff --git a/lib/tasks/project_components/powerful_patterns_art_deco_wallpaper_example/project_config.yml b/lib/tasks/project_components/powerful_patterns_art_deco_wallpaper_example/project_config.yml index b2aa47154..2aa28922f 100644 --- a/lib/tasks/project_components/powerful_patterns_art_deco_wallpaper_example/project_config.yml +++ b/lib/tasks/project_components/powerful_patterns_art_deco_wallpaper_example/project_config.yml @@ -1,4 +1,4 @@ -NAME: "Powerful Patterns: Art Deco Wallpaper" +NAME: "Powerful Patterns: Art Deco Wallpaper Example" IDENTIFIER: "art-deco-example" COMPONENTS: - name: "main" From e644c27ce36287a471d02648dcbd09319a4cd910 Mon Sep 17 00:00:00 2001 From: Lois Wells Date: Fri, 18 Mar 2022 17:42:33 +0000 Subject: [PATCH 06/13] Make some faces examples work with actual p5 --- .../make_a_face_kawaii_fruit_example/main.py | 10 +++++----- .../make_a_face_stacked_faces_example/main.py | 16 ++++++++-------- .../make_a_face_tribal_mask_example/main.py | 4 ++-- .../target_practice_example/main.py | 16 +++++++--------- 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/lib/tasks/project_components/make_a_face_kawaii_fruit_example/main.py b/lib/tasks/project_components/make_a_face_kawaii_fruit_example/main.py index 6110a85fb..05269a879 100644 --- a/lib/tasks/project_components/make_a_face_kawaii_fruit_example/main.py +++ b/lib/tasks/project_components/make_a_face_kawaii_fruit_example/main.py @@ -1,17 +1,17 @@ #!/bin/python3 -from processing import * +from p5 import * def setup(): size(400, 400) - noStroke() + no_stroke() def draw(): background(255) - orange = color(255, 165, 0) - brown = color(200, 120, 0) - green = color(100, 155, 0) + orange = Color(255, 165, 0) + brown = Color(200, 120, 0) + green = Color(100, 155, 0) fill(orange) ellipse(200, 200, 200, 190) fill(0) diff --git a/lib/tasks/project_components/make_a_face_stacked_faces_example/main.py b/lib/tasks/project_components/make_a_face_stacked_faces_example/main.py index fe0d87ca7..f94c2daab 100644 --- a/lib/tasks/project_components/make_a_face_stacked_faces_example/main.py +++ b/lib/tasks/project_components/make_a_face_stacked_faces_example/main.py @@ -1,6 +1,6 @@ #!/bin/python3 -from processing import * +from p5 import * def setup(): size(400, 600) @@ -9,13 +9,13 @@ def setup(): def draw(): - blue = color(92, 204, 206) - green = color(149, 212, 122) - red = color(239, 62, 91) - purple = color(75, 37, 109) - brown = color(178, 162, 150) - grey = color(201, 201, 201) - lilac = color(160, 158, 214) + blue = Color(92, 204, 206) + green = Color(149, 212, 122) + red = Color(239, 62, 91) + purple = Color(75, 37, 109) + brown = Color(178, 162, 150) + grey = Color(201, 201, 201) + lilac = Color(160, 158, 214) # Top face background fill(blue) diff --git a/lib/tasks/project_components/make_a_face_tribal_mask_example/main.py b/lib/tasks/project_components/make_a_face_tribal_mask_example/main.py index af469d042..781c29bac 100644 --- a/lib/tasks/project_components/make_a_face_tribal_mask_example/main.py +++ b/lib/tasks/project_components/make_a_face_tribal_mask_example/main.py @@ -1,10 +1,10 @@ #!/bin/python3 -from processing import * +from p5 import * def setup(): size(400, 400) - noStroke() + no_stroke() def draw(): diff --git a/lib/tasks/project_components/target_practice_example/main.py b/lib/tasks/project_components/target_practice_example/main.py index 8d0da5672..7479fe1d4 100644 --- a/lib/tasks/project_components/target_practice_example/main.py +++ b/lib/tasks/project_components/target_practice_example/main.py @@ -27,18 +27,16 @@ def shoot_arrow(): def setup(): # Setup your game here size(400, 400) # width and height - frame_rate(2) - def draw(): # Things to do in every frame global outer, inner, bullseye - sky = color(92, 204, 206) # Red = 92, Green = 204, Blue = 206 - grass = color(149, 212, 122) - wood = color(145, 96, 51) - outer = color(0, 120, 180) - inner = color(210, 60, 60) - bullseye = color(220, 200, 0) + sky = Color(92, 204, 206) # Red = 92, Green = 204, Blue = 206 + grass = Color(149, 212, 122) + wood = Color(145, 96, 51) + outer = Color(0, 120, 180) + inner = Color(210, 60, 60) + bullseye = Color(220, 200, 0) no_stroke() fill(sky) @@ -58,4 +56,4 @@ def draw(): fill(wood) shoot_arrow() # Keep this to run your code -run() +run(frame_rate=2) From 5a9a94625e05f35e03b76c5adaa150194c241bc9 Mon Sep 17 00:00:00 2001 From: Lois Wells Date: Fri, 18 Mar 2022 17:44:39 +0000 Subject: [PATCH 07/13] Fixing stacked faces project --- .../make_a_face_stacked_faces_example/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/project_components/make_a_face_stacked_faces_example/main.py b/lib/tasks/project_components/make_a_face_stacked_faces_example/main.py index f94c2daab..caff6b4de 100644 --- a/lib/tasks/project_components/make_a_face_stacked_faces_example/main.py +++ b/lib/tasks/project_components/make_a_face_stacked_faces_example/main.py @@ -5,7 +5,7 @@ def setup(): size(400, 600) background(255, 255, 255) - noStroke() + no_stroke() def draw(): From 3535af90c688c8598b4a14cc03b7d4f64fd6a3f6 Mon Sep 17 00:00:00 2001 From: Lois Wells Date: Mon, 21 Mar 2022 15:29:01 +0000 Subject: [PATCH 08/13] Minor fixes to animated face project --- .../make_a_face_animated_example/main.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/tasks/project_components/make_a_face_animated_example/main.py b/lib/tasks/project_components/make_a_face_animated_example/main.py index d88241be9..d8d9eb3b8 100644 --- a/lib/tasks/project_components/make_a_face_animated_example/main.py +++ b/lib/tasks/project_components/make_a_face_animated_example/main.py @@ -1,13 +1,11 @@ #!/bin/python3 -from processing import * +from p5 import * import random def setup(): size(400, 400) - noStroke() - frameRate(5) - + no_stroke() def draw(): background(255) @@ -43,4 +41,4 @@ def draw(): fill(0) rect(185, 320, 30, 5) -run() +run(frame_rate=5) From faaaf384719b147707f1d2332b33ceb4cec6cb06 Mon Sep 17 00:00:00 2001 From: Lois Wells Date: Tue, 22 Mar 2022 10:33:24 +0000 Subject: [PATCH 09/13] Modifications to patterns projects --- .../main.py | 65 ++++++++---------- .../main.py | 13 ++-- .../main.py | 13 ++-- .../project_config.yml | 0 .../main.py | 66 +++++++++++-------- .../powerful_patterns_spirals_example/main.py | 5 +- .../main.py | 11 ++-- 7 files changed, 83 insertions(+), 90 deletions(-) rename lib/tasks/project_components/{powerful_patterns_mcewan_tartan_example => powerful_patterns_mcewen_tartan_example}/main.py (91%) rename lib/tasks/project_components/{powerful_patterns_mcewan_tartan_example => powerful_patterns_mcewen_tartan_example}/project_config.yml (100%) diff --git a/lib/tasks/project_components/powerful_patterns_art_deco_wallpaper_example/main.py b/lib/tasks/project_components/powerful_patterns_art_deco_wallpaper_example/main.py index c46bf2df3..4efa15ed4 100644 --- a/lib/tasks/project_components/powerful_patterns_art_deco_wallpaper_example/main.py +++ b/lib/tasks/project_components/powerful_patterns_art_deco_wallpaper_example/main.py @@ -3,44 +3,33 @@ from p5 import * from random import randint -def draw_motif(): - orange = color(191, 64, 191) - brown = color(200, 120, 0) - green = color(100, 155, 0) - fill(orange) - ellipse(200, 200, 200, 190) - fill(0) - # Eyes - ellipse(160, 190, 30, 30) - ellipse(240, 190, 30, 30) - fill(255) - ellipse(165, 200, 10, 10) - ellipse(245, 200, 10, 10) - # Mouth - noFill() - stroke(255, 255, 255) - ellipse(150, 250, 30, 30) - ellipse(250, 250, 30, 30) - fill(255, 255, 255) - noStroke() - rect(150, 230, 100, 40) - fill(108, 200, 206) - rect(152, 235, 96, 30) - - +def motif(): + global circle_size + for i in range(5): + ellipse(0, 0, circle_size / 5 * (5 - i), circle_size / 5 * (5 - i)) + def setup(): size(400, 400) - background(255) - no_stroke() - frame_rate(10) - - + print('πŸ–Œ This art uses lots of circles!') + + global circle_size + + circle_size = 50 + def draw(): - push_matrix() - translate(randint(-50, 350), randint(-50, 350)) # offset by the width of the quarter-size face - scale(0.25) # quarter size paths - draw_motif() - pop_matrix() - - -run() + + # Pattern colours + stroke(40, 35, 100) # blue + stroke_weight(2) # thick border + fill(200, 180, 128) # gold + + translate(0,0) # start from the top left of the screen + + if frame_count <= 16: # creates 16 rows then stops + for row in range (frame_count): # animates 1 row at a time + for shape in range (16): # create a row of motifs + motif() + translate(circle_size / 2, 0) + translate(-width, circle_size / 2) # move down to start next row + +run(frame_rate=3) 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 4dc73554a..e9816f307 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 @@ -1,6 +1,6 @@ #!/bin/python3 -from draw import * +from p5 import * from time import * # Based on the amazing Malaysian geometric cake art: Kek lapis Sarawak @@ -8,12 +8,12 @@ def quadrant(): # Choose some gorgeous colours for the cake layers - turquoise = color(64, 224, 208) - gold = color(255, 215, 0) - tomato = color(255, 99, 71) + turquoise = Color(64, 224, 208) + gold = Color(255, 215, 0) + tomato = Color(255, 99, 71) # Jam sticks the layers together - jam = color(255, 165, 0) + jam = Color(255, 165, 0) stroke(jam) stroke_weight(2) # Change the number to change the amount of jam @@ -42,7 +42,6 @@ def outer(): def setup(): size(400, 400) # make the cake square background(255, 255, 255, 0) # transparent background - frame_rate(5) # 5 frames per second def draw(): @@ -64,4 +63,4 @@ def draw(): outer() # outer layer -run() +run(frame_rate = 5) # 5 frames per second diff --git a/lib/tasks/project_components/powerful_patterns_mcewan_tartan_example/main.py b/lib/tasks/project_components/powerful_patterns_mcewen_tartan_example/main.py similarity index 91% rename from lib/tasks/project_components/powerful_patterns_mcewan_tartan_example/main.py rename to lib/tasks/project_components/powerful_patterns_mcewen_tartan_example/main.py index b107f3fc0..04af9c4f1 100644 --- a/lib/tasks/project_components/powerful_patterns_mcewan_tartan_example/main.py +++ b/lib/tasks/project_components/powerful_patterns_mcewen_tartan_example/main.py @@ -4,7 +4,6 @@ def setup(): size(400, 400) - frame_rate(10) print('🏴󠁧󠁒󠁳󠁣󠁴󠁿󠁒󠁳󠁣󠁴󠁿 This is McEwen Tartan 🏴󠁧󠁒󠁳󠁣󠁴󠁿󠁧󠁒󠁳󠁣󠁴󠁿') global square_size @@ -16,17 +15,17 @@ def draw(): # McEwen tartan colours # Base square colours - BLUE = color(83, 143, 200) - GREEN = color(78, 163, 162) + BLUE = Color(83, 143, 200) + GREEN = Color(78, 163, 162) BASE_COLORS = [GREEN, BLUE] # Cross colours - YELLOW = color(155, 176, 135) - RED = color(155, 129, 113) + YELLOW = Color(155, 176, 135) + RED = Color(155, 129, 113) CROSS_COLORS = [YELLOW, RED] # Stitching and overlap colour - GREY = color(78, 99, 86) + GREY = Color(78, 99, 86) # Draw all the GREEN and BLUE alternating Base squares no_stroke() @@ -73,7 +72,7 @@ def draw(): rect(0, gap, lines, 8) gap = gap + square_size -run() +run(frame_rate=10) diff --git a/lib/tasks/project_components/powerful_patterns_mcewan_tartan_example/project_config.yml b/lib/tasks/project_components/powerful_patterns_mcewen_tartan_example/project_config.yml similarity index 100% rename from lib/tasks/project_components/powerful_patterns_mcewan_tartan_example/project_config.yml rename to lib/tasks/project_components/powerful_patterns_mcewen_tartan_example/project_config.yml diff --git a/lib/tasks/project_components/powerful_patterns_random_faces_example/main.py b/lib/tasks/project_components/powerful_patterns_random_faces_example/main.py index 5616a2838..8695261ea 100644 --- a/lib/tasks/project_components/powerful_patterns_random_faces_example/main.py +++ b/lib/tasks/project_components/powerful_patterns_random_faces_example/main.py @@ -1,37 +1,45 @@ #!/bin/python3 from p5 import * -from math import random from random import randint -def motif(): - global circle_size - for i in range(5): - ellipse(0, 0, circle_size / 5 * (5 - i), circle_size / 5 * (5 - i)) - -def setup(): - size(400, 400) - frame_rate(3) - print('πŸ–Œ This art uses lots of circles!') - - global circle_size +def draw_motif(): + orange = Color(191, 64, 191) + brown = Color(200, 120, 0) + green = Color(100, 155, 0) + fill(orange) + ellipse(200, 200, 200, 190) + fill(0) + # Eyes + ellipse(160, 190, 30, 30) + ellipse(240, 190, 30, 30) + fill(255) + ellipse(165, 200, 10, 10) + ellipse(245, 200, 10, 10) + # Mouth + no_fill() + stroke(255, 255, 255) + ellipse(150, 250, 30, 30) + ellipse(250, 250, 30, 30) + fill(255, 255, 255) + no_stroke() + rect(150, 230, 100, 40) + fill(108, 200, 206) + rect(152, 235, 96, 30) - circle_size = 50 +def setup(): + size(400, 400) + background(255) + no_stroke() + + def draw(): - - # Pattern colours - stroke(40, 35, 100) # blue - stroke_weight(2) # thick border - fill(200, 180, 128) # gold - - translate(0,0) # start from the top left of the screen - - if frame_count <= 16: # creates 16 rows then stops - for row in range (frame_count): # animates 1 row at a time - for shape in range (16): # create a row of motifs - motif() - translate(circle_size / 2, 0) - translate(-width, circle_size / 2) # move down to start next row - -run() + push_matrix() + translate(randint(-50, 350), randint(-50, 350)) # offset by the width of the quarter-size face + scale(0.25, 0.25) # quarter size paths + draw_motif() + pop_matrix() + + +run(frame_rate=10) diff --git a/lib/tasks/project_components/powerful_patterns_spirals_example/main.py b/lib/tasks/project_components/powerful_patterns_spirals_example/main.py index 2d953d8f1..629f32eff 100644 --- a/lib/tasks/project_components/powerful_patterns_spirals_example/main.py +++ b/lib/tasks/project_components/powerful_patterns_spirals_example/main.py @@ -14,8 +14,7 @@ def motif(): rect(i * 5, 0, 5, 5) def setup(): - size(400, 400) - frame_rate(10) # fast animation + size(400, 400) stroke_weight(2) # thick border background(255) @@ -27,4 +26,4 @@ def draw(): rotate(5) # turns the motif translate(i,i) # moves the motif -run() +run(frame_rate=10) # fast animation diff --git a/lib/tasks/project_components/powerful_patterns_yakan_weaving_example/main.py b/lib/tasks/project_components/powerful_patterns_yakan_weaving_example/main.py index a350a8c1d..b3508d43a 100644 --- a/lib/tasks/project_components/powerful_patterns_yakan_weaving_example/main.py +++ b/lib/tasks/project_components/powerful_patterns_yakan_weaving_example/main.py @@ -7,10 +7,10 @@ def motif(): motif_size = 100 #Thread colours - ORANGE = color(254, 96, 1) - PURPLE = color(135, 18, 192) - YELLOW = color(243, 200, 19) - BLUE = color(83, 171, 176) + ORANGE = Color(254, 96, 1) + PURPLE = Color(135, 18, 192) + YELLOW = Color(243, 200, 19) + BLUE = Color(83, 171, 176) # Squares fill(ORANGE) @@ -41,7 +41,6 @@ def rotate_motif(): def setup(): size(400, 400) - frame_rate(3) background(250, 5, 94) # pink no_stroke() print('This is πŸ‡΅πŸ‡­ Yakan weaving ') @@ -61,4 +60,4 @@ def draw(): else: translate(-motif_width * 5 - 75, 80) -run() +run(frame_rate=3) From b5c677ff2594534523423a76f7c751519e3ea8ec Mon Sep 17 00:00:00 2001 From: Lois Wells Date: Wed, 23 Mar 2022 17:19:15 +0000 Subject: [PATCH 10/13] Minor changes to runner and tartan projects --- .../dont_collide_avoid_germs_example/main.py | 4 ++-- .../dont_collide_clean_car_example/main.py | 2 +- .../dont_collide_dodge_asteroids_example/main.py | 2 +- .../dont_collide_dont_pop_example/main.py | 2 +- .../dont_collide_skiing_cat_example/main.py | 4 ++-- .../powerful_patterns_mcewen_tartan_example/main.py | 7 +++---- 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/tasks/project_components/dont_collide_avoid_germs_example/main.py b/lib/tasks/project_components/dont_collide_avoid_germs_example/main.py index e62012514..c9b0f10c0 100644 --- a/lib/tasks/project_components/dont_collide_avoid_germs_example/main.py +++ b/lib/tasks/project_components/dont_collide_avoid_germs_example/main.py @@ -101,7 +101,7 @@ def draw_obstacles(): def setup(): # Put code to run once here size(400, 400) # width and height - noStroke() + no_stroke() text_size(40) text_align(CENTER, TOP) @@ -109,7 +109,7 @@ def draw(): # Put code to run every frame here global safe, score, level - safe = color(149, 161, 195) + safe = Color(149, 161, 195) if level > 0: background(safe) diff --git a/lib/tasks/project_components/dont_collide_clean_car_example/main.py b/lib/tasks/project_components/dont_collide_clean_car_example/main.py index e8c63ee4f..cdbbf093c 100644 --- a/lib/tasks/project_components/dont_collide_clean_car_example/main.py +++ b/lib/tasks/project_components/dont_collide_clean_car_example/main.py @@ -69,7 +69,7 @@ def setup(): def draw(): # Things to do in every frame global score, safe, level - safe = color(128) + safe = Color(128) if level > 0: background(safe) diff --git a/lib/tasks/project_components/dont_collide_dodge_asteroids_example/main.py b/lib/tasks/project_components/dont_collide_dodge_asteroids_example/main.py index 513948065..af584307b 100644 --- a/lib/tasks/project_components/dont_collide_dodge_asteroids_example/main.py +++ b/lib/tasks/project_components/dont_collide_dodge_asteroids_example/main.py @@ -115,7 +115,7 @@ def setup(): def draw(): # Things to do in every frame global score, safe, level - safe = color(0) + safe = Color(0) if level > 0: background(safe) diff --git a/lib/tasks/project_components/dont_collide_dont_pop_example/main.py b/lib/tasks/project_components/dont_collide_dont_pop_example/main.py index 457e65302..91efb48b1 100644 --- a/lib/tasks/project_components/dont_collide_dont_pop_example/main.py +++ b/lib/tasks/project_components/dont_collide_dont_pop_example/main.py @@ -67,7 +67,7 @@ def setup(): def draw(): # Things to do in every frame global score, safe, level - safe = color(200, 150, 0) + safe = Color(200, 150, 0) if level > 0: background(safe) diff --git a/lib/tasks/project_components/dont_collide_skiing_cat_example/main.py b/lib/tasks/project_components/dont_collide_skiing_cat_example/main.py index d68fc9762..acbad49da 100644 --- a/lib/tasks/project_components/dont_collide_skiing_cat_example/main.py +++ b/lib/tasks/project_components/dont_collide_skiing_cat_example/main.py @@ -54,16 +54,16 @@ def setup(): global skiing, crashed # Setup your animation here + size(400, 400) text_size(40) text_align(CENTER, TOP) # position around the centre - size(400, 400) skiing = load_image('skiing.png') crashed = load_image('fallenover.png') def draw(): # Things to do in every frame global score, safe, speed, skiing, crashed - safe = color(255) + safe = Color(255) if speed > 0: background(safe) diff --git a/lib/tasks/project_components/powerful_patterns_mcewen_tartan_example/main.py b/lib/tasks/project_components/powerful_patterns_mcewen_tartan_example/main.py index 04af9c4f1..4957ea44d 100644 --- a/lib/tasks/project_components/powerful_patterns_mcewen_tartan_example/main.py +++ b/lib/tasks/project_components/powerful_patterns_mcewen_tartan_example/main.py @@ -4,10 +4,6 @@ def setup(): size(400, 400) - print('🏴󠁧󠁒󠁳󠁣󠁴󠁿󠁒󠁳󠁣󠁴󠁿 This is McEwen Tartan 🏴󠁧󠁒󠁳󠁣󠁴󠁿󠁧󠁒󠁳󠁣󠁴󠁿') - - global square_size - square_size = int(input('What size 🏴󠁧󠁒󠁳󠁣󠁴󠁿tartan would you like? 20, 50, or 100')) def draw(): @@ -71,6 +67,9 @@ def draw(): for i in range (int(squares)): rect(0, gap, lines, 8) gap = gap + square_size + +print('🏴󠁧󠁒󠁳󠁣󠁴󠁿󠁒󠁳󠁣󠁴󠁿 This is McEwen Tartan 🏴󠁧󠁒󠁳󠁣󠁴󠁿󠁧󠁒󠁳󠁣󠁴󠁿') +square_size = int(input('What size 🏴󠁧󠁒󠁳󠁣󠁴󠁿tartan would you like? 20, 50, or 100')) run(frame_rate=10) From 93e714ab428dd4af0b9924b746e4e0f93f795f04 Mon Sep 17 00:00:00 2001 From: Ant Barnes Date: Thu, 24 Mar 2022 11:21:04 +0000 Subject: [PATCH 11/13] Add grid to face starter project --- .../make_a_face_interactive_example/main.py | 11 +++++------ .../project_components/make_a_face_starter/grid.py | 14 ++++++++++++++ .../project_components/make_a_face_starter/main.py | 3 ++- .../make_a_face_starter/project_config.yml | 5 +++++ 4 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 lib/tasks/project_components/make_a_face_starter/grid.py diff --git a/lib/tasks/project_components/make_a_face_interactive_example/main.py b/lib/tasks/project_components/make_a_face_interactive_example/main.py index b50630044..94e42f57d 100644 --- a/lib/tasks/project_components/make_a_face_interactive_example/main.py +++ b/lib/tasks/project_components/make_a_face_interactive_example/main.py @@ -7,12 +7,12 @@ def sad(x_middle, y_eye, y_mouth): ellipse(x_middle - 50, y_eye - 20, 60, 50) # x, y, width, height ellipse(x_middle + 50, y_eye - 20, 60, 50) ellipse(x_middle, y_mouth + 30, 100, 65) - + def happy(x_middle, y_eye, y_mouth): ellipse(x_middle - 50, y_eye + 20, 60, 50) # x, y, width, height ellipse(x_middle + 50, y_eye + 20, 60, 50) ellipse(x_middle, y_mouth - 30, 100, 65) - + def setup(): # Put code to run once here size(400, 400) # width and height @@ -23,7 +23,7 @@ def setup(): def draw(): # Put code to run every frame here mask_width = width / 2 - x_middle = width / 2 + x_middle = width / 2 y_eye = 180 y_mouth = 255 # draw mask @@ -47,12 +47,11 @@ def draw(): # shade half of the mask fill(0, 25) rect(300, 200, width/2, height) - #grid() def mouse_pressed(): # Put code to run when the mouse is pressed here - print(mouse_x, mouse_y) - + print(mouse_x, mouse_y) + # Keep this to run your code run() diff --git a/lib/tasks/project_components/make_a_face_starter/grid.py b/lib/tasks/project_components/make_a_face_starter/grid.py new file mode 100644 index 000000000..37cd5fe8b --- /dev/null +++ b/lib/tasks/project_components/make_a_face_starter/grid.py @@ -0,0 +1,14 @@ +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() 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 192cb2b41..140cbaadf 100644 --- a/lib/tasks/project_components/make_a_face_starter/main.py +++ b/lib/tasks/project_components/make_a_face_starter/main.py @@ -1,6 +1,7 @@ #!/bin/python3 from p5 import * +from grid import * def setup(): # Put code to run once here @@ -10,6 +11,6 @@ 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 - + # Keep this to run your code run() diff --git a/lib/tasks/project_components/make_a_face_starter/project_config.yml b/lib/tasks/project_components/make_a_face_starter/project_config.yml index 4c2ab09e6..a4fcfc07e 100644 --- a/lib/tasks/project_components/make_a_face_starter/project_config.yml +++ b/lib/tasks/project_components/make_a_face_starter/project_config.yml @@ -6,3 +6,8 @@ COMPONENTS: location: "main.py" index: 0 default: true + - name: "grid" + extension: "py" + location: "grid.py" + index: 1 + default: false From 528aaf847779e6ffef3302ff5baa7f39031396e0 Mon Sep 17 00:00:00 2001 From: Ant Barnes Date: Thu, 24 Mar 2022 11:22:50 +0000 Subject: [PATCH 12/13] pythonify function calls --- lib/tasks/project_components/make_a_face_starter/grid.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tasks/project_components/make_a_face_starter/grid.py b/lib/tasks/project_components/make_a_face_starter/grid.py index 37cd5fe8b..764ad91da 100644 --- a/lib/tasks/project_components/make_a_face_starter/grid.py +++ b/lib/tasks/project_components/make_a_face_starter/grid.py @@ -1,5 +1,5 @@ def grid(): - pushMatrix() + push_matrix() stroke(200) fill(0) line(0, height/2, width, height/2) @@ -11,4 +11,4 @@ def grid(): for y in y_coords: show_coord(x, y) - popMatrix() + pop_matrix() From ff1399da3da8f20343613c1a41e592413a8997e2 Mon Sep 17 00:00:00 2001 From: Ant Barnes Date: Thu, 24 Mar 2022 11:25:51 +0000 Subject: [PATCH 13/13] update method calls in yakan weaving --- .../main.py | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/tasks/project_components/powerful_patterns_yakan_weaving_example/main.py b/lib/tasks/project_components/powerful_patterns_yakan_weaving_example/main.py index b3508d43a..12d91ca92 100644 --- a/lib/tasks/project_components/powerful_patterns_yakan_weaving_example/main.py +++ b/lib/tasks/project_components/powerful_patterns_yakan_weaving_example/main.py @@ -5,13 +5,13 @@ def motif(): motif_size = 100 - + #Thread colours ORANGE = Color(254, 96, 1) PURPLE = Color(135, 18, 192) YELLOW = Color(243, 200, 19) BLUE = Color(83, 171, 176) - + # Squares fill(ORANGE) rect(0, 0, motif_size/2, motif_size/2) @@ -31,33 +31,33 @@ def motif(): rect(50, 50, motif_size/4, motif_size/4) def rotate_motif(): - + for shape in range(5): # row of shapes - pushMatrix() # save settings + push_matrix() # save settings rotate(radians(45)) # turn shape 45 degrees motif() - popMatrix() # go back to saved settings + pop_matrix() # go back to saved settings translate(motif_width, 0) # move horizontally def setup(): size(400, 400) background(250, 5, 94) # pink no_stroke() - print('This is πŸ‡΅πŸ‡­ Yakan weaving ') - + print('This is πŸ‡΅πŸ‡­ Yakan weaving ') + def draw(): - + global motif_width - motif_width = 150 - - translate(-motif_width/2, -motif_width/2) # to start with half motifs - + motif_width = 150 + + translate(-motif_width/2, -motif_width/2) # to start with half motifs + if frame_count < 20: # maximum rows for row in range(frame_count): rotate_motif() if row / 2 == 0: # to offset pattern on next row - translate(-motif_width * 5 + 75, 80) - else: - translate(-motif_width * 5 - 75, 80) - + translate(-motif_width * 5 + 75, 80) + else: + translate(-motif_width * 5 - 75, 80) + run(frame_rate=3)