Skip to content

Commit

Permalink
adding code directories
Browse files Browse the repository at this point in the history
  • Loading branch information
m-bowley committed Nov 17, 2023
1 parent 71262cf commit 69e60a9
Show file tree
Hide file tree
Showing 14 changed files with 366 additions and 0 deletions.
38 changes: 38 additions & 0 deletions en/code/powerful_patterns_art_deco_wallpaper_example/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/python3

from p5 import *
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)
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(frame_rate=3)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: "Powerful Patterns: Art Deco Wallpaper Example"
identifier: "art-deco-example"
type: 'python'
64 changes: 64 additions & 0 deletions en/code/powerful_patterns_kek_lepis_sarawak/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/python3

from p5 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():
# The 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


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(frame_rate=5) # 5 frames per second
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: "Powerful Patterns: Kek Lepis Sarawak Example"
identifier: "repeated-patterns-example"
type: 'python'
77 changes: 77 additions & 0 deletions en/code/powerful_patterns_mcewen_tartan_example/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/python3

from p5 import *


def setup():
size(400, 400)


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


print('🏴󠁧󠁢󠁳󠁣󠁴󠁿󠁢󠁳󠁣󠁴󠁿 This is McEwen Tartan 🏴󠁧󠁢󠁳󠁣󠁴󠁿󠁧󠁢󠁳󠁣󠁴󠁿')
square_size = int(
input('What size 🏴󠁧󠁢󠁳󠁣󠁴󠁿tartan would you like? 20, 50, or 100'))

run(frame_rate=10)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: "Powerful Patterns: McEwen Tartan"
identifier: "mcewen-tartan-example"
type: 'python'
47 changes: 47 additions & 0 deletions en/code/powerful_patterns_random_faces_example/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/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
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)


def setup():
size(400, 400)
background(255)
no_stroke()


def draw():
push_matrix()
# offset by the width of the quarter-size face
translate(randint(-50, 350), randint(-50, 350))
scale(0.25, 0.25) # quarter size paths
draw_motif()
pop_matrix()


run(frame_rate=10)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: "Powerful Patterns: Random Faces"
identifier: "random-faces-example"
type: 'python'
33 changes: 33 additions & 0 deletions en/code/powerful_patterns_spirals_example/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/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)
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(frame_rate=10) # fast animation
3 changes: 3 additions & 0 deletions en/code/powerful_patterns_spirals_example/project_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: "Powerful Patterns: Spirals"
identifier: "spirals-pattern-example"
type: 'python'
20 changes: 20 additions & 0 deletions en/code/powerful_patterns_starter/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/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(frame_rate=5)
3 changes: 3 additions & 0 deletions en/code/powerful_patterns_starter/project_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: "Powerful Patterns"
identifier: "powerful-patterns-starter"
type: 'python'
66 changes: 66 additions & 0 deletions en/code/powerful_patterns_yakan_weaving_example/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/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
push_matrix() # save settings
rotate(radians(45)) # turn shape 45 degrees
motif()
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 ')


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(frame_rate=3)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: "Powerful Patterns: Yakan Weaving"
identifier: "yakan-weaving-example"
type: 'python'

0 comments on commit 69e60a9

Please sign in to comment.