kopia lustrzana https://github.com/villares/sketch-a-day
main
rodzic
3150be81db
commit
dc07c0d9f2
|
@ -1,28 +1,30 @@
|
||||||
"""Grid study"""
|
"""Grid study"""
|
||||||
shapes = []
|
|
||||||
|
|
||||||
def setup():
|
def setup():
|
||||||
size(500, 500)
|
size(500, 500)
|
||||||
rectMode(CENTER)
|
rectMode(CENTER)
|
||||||
shapes.extend(grid(10, 12, 25, thing))
|
global shapes
|
||||||
|
shapes = grid(cols=10,
|
||||||
|
rows=12,
|
||||||
|
space=25,
|
||||||
|
func=(create_element, 10))
|
||||||
|
|
||||||
def draw():
|
def draw():
|
||||||
translate(width / 2, height / 2)
|
translate(width / 2., height / 2.)
|
||||||
rect(0, 0, 250, 300)
|
rect(0, 0, 250, 300)
|
||||||
for s in shapes:
|
for s in shapes:
|
||||||
shape(s)
|
shape(s)
|
||||||
|
|
||||||
def grid(cols, rows, space, func):
|
def grid(cols, rows, space, func):
|
||||||
result = []
|
result = []
|
||||||
half_w = -cols * space / 2.
|
half_w = cols * space / 2.
|
||||||
half_h = -rows * space / 2.
|
half_h = rows * space / 2.
|
||||||
for ix in range(cols):
|
for ix in range(cols):
|
||||||
x = half_w + ix * space + space / 2
|
x = ix * space + space / 2. - half_w
|
||||||
for iy in range(rows):
|
for iy in range(rows):
|
||||||
y = half_h + iy * space + space / 2
|
y = iy * space + space / 2. - half_h
|
||||||
result.append(func(x, y))
|
result.append(func[0](x, y, *func[1:]))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def thing(x=0, y=0, w=10, h=10):
|
def create_element(x, y, *args):
|
||||||
t = createShape(ELLIPSE, x, y, w, h)
|
return createShape(ELLIPSE, x, y, args[0], args[0])
|
||||||
return t
|
|
||||||
|
|
Ładowanie…
Reference in New Issue