Squares
In [1]:
Copied!
from PIL import Image as PILImage
import math
import random
from PIL import Image as PILImage import math import random
In [2]:
Copied!
from itertools import product
from itertools import product
In [3]:
Copied!
from colour import Color
from chalk import square, concat, empty
from colour import Color from chalk import square, concat, empty
In [4]:
Copied!
random.seed(0)
random.seed(0)
In [5]:
Copied!
def make_square():
colors = [
Color("#ff9700"), # papaya
Color("#005FDB"), # blue
]
# generate uniformly a value in [-max_angle, max_angle]
max_angle = math.pi / 24.0
θ = 2 * max_angle * random.random() - max_angle
# pick a random color
i = random.random() > 0.75
color = colors[i]
return square(0.75).line_color(color).rotate_rad(-θ)
make_square()
def make_square(): colors = [ Color("#ff9700"), # papaya Color("#005FDB"), # blue ] # generate uniformly a value in [-max_angle, max_angle] max_angle = math.pi / 24.0 θ = 2 * max_angle * random.random() - max_angle # pick a random color i = random.random() > 0.75 color = colors[i] return square(0.75).line_color(color).rotate_rad(-θ) make_square()
Out[5]:
In [6]:
Copied!
def make_group(num_squares=4):
return concat(make_square() for _ in range(num_squares))
make_group()
def make_group(num_squares=4): return concat(make_square() for _ in range(num_squares)) make_group()
Out[6]:
In [7]:
Copied!
disps = range(4)
diagram = concat(make_group().translate(x, y) for x, y in product(disps, disps))
disps = range(4) diagram = concat(make_group().translate(x, y) for x, y in product(disps, disps))
In [8]:
Copied!
diagram = diagram.line_width(0.02)
diagram
diagram = diagram.line_width(0.02) diagram
Out[8]:
Last update: 2022-08-21