/
sketch_190727a.pyde
57 lines (49 loc) · 1.41 KB
/
sketch_190727a.pyde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""Grid study"""
def setup():
size(500, 500)
colorMode(HSB)
create_grids()
def create_grids():
global shapes
shapes = []
for i in range(10):
d = int(random(7, 14))
sp = 25
x = int(random(-7, 8)) * sp
y = int(random(-7, 8)) * sp
si = random(15, 35)
shapes.extend(grid(pos=(x, y),
dims=(d, d),
space=sp,
elem=(create_element, si))
)
def draw():
background(100)
translate(width / 2., height / 2.)
for s in shapes:
shape(s)
def grid(pos, dims, space, elem):
gx, gy = pos
col_num, row_num = dims
func, args = elem[0], elem[1:]
result = []
half_w = col_num * space / 2.
half_h = row_num * space / 2.
for ix in range(col_num):
x = gx + ix * space + space / 2. - half_w
for iy in range(row_num):
y = gy + iy * space + space / 2. - half_h
fill(color_rule(ix, iy, row_num))
result.append(func(x, y, *args))
return result
def color_rule(ix, iy, row_num):
return color(row_num * 8 + (ix + iy) % 3 * 32 , 200, 200, 100)
def create_element(x, y, *args):
noStroke()
# fill(255, 100)
return createShape(ELLIPSE, x, y, args[0], args[0])
def keyPressed():
if key == "s":
saveFrame("####.png")
if key == " ":
create_grids()