diff --git a/2019/sketch_190812a/grid$py.class b/2019/sketch_190812a/grid$py.class index 0e07a142..ac1d92e1 100644 Binary files a/2019/sketch_190812a/grid$py.class and b/2019/sketch_190812a/grid$py.class differ diff --git a/2019/sketch_190813a/0049.png b/2019/sketch_190813a/0049.png new file mode 100644 index 00000000..f3a8eeaa Binary files /dev/null and b/2019/sketch_190813a/0049.png differ diff --git a/2019/sketch_190813a/0090.png b/2019/sketch_190813a/0090.png new file mode 100644 index 00000000..2faf8dcb Binary files /dev/null and b/2019/sketch_190813a/0090.png differ diff --git a/2019/sketch_190813a/0109.png b/2019/sketch_190813a/0109.png new file mode 100644 index 00000000..b1e02775 Binary files /dev/null and b/2019/sketch_190813a/0109.png differ diff --git a/2019/sketch_190813a/0129.png b/2019/sketch_190813a/0129.png new file mode 100644 index 00000000..94976291 Binary files /dev/null and b/2019/sketch_190813a/0129.png differ diff --git a/2019/sketch_190813a/0167.png b/2019/sketch_190813a/0167.png new file mode 100644 index 00000000..c6fdd347 Binary files /dev/null and b/2019/sketch_190813a/0167.png differ diff --git a/2019/sketch_190813a/grid.py b/2019/sketch_190813a/grid.py new file mode 100644 index 00000000..a8c1e9e7 --- /dev/null +++ b/2019/sketch_190813a/grid.py @@ -0,0 +1,75 @@ +from random import choice + +class Grid(): + + def __init__(self, pos, **args): + self.pos = PVector(*pos) + self.vel = PVector(choice((-1, 1, .5, -.5)), choice((.25, -.25))) + self.shapes = Grid.create_shapes((0, 0), **args) + self.space = args['space'] + + def update(self): + for sh in self.shapes: + Grid.draw_element(sh, self.pos.x, self.pos.y) + if dist(mouseX - width / 2, mouseY - width / 2, + self.pos.x, self.pos.y) < self.space * 5: + self.pos += self.vel * self.space + if self.pos.mag() > width / 2: # * height: + self.vel = self.vel * -1 + + @staticmethod + def create_shapes(pos, dims, space, elem): + gx, gy = pos + col_num, row_num = dims + 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 + noFill() + result.append(Grid.create_element(x, y, ix, iy, *elem)) + return result + + @staticmethod + def create_element(x, y, ix, iy, *args): + sh = args[0] # shape + si = args[1] # size + c = color(128) + # print ix, iy + if int(si) % 3 == 0: + si *= 0.25 + 0.25 * ((ix + iy) % 3) + elif int(si) % 2 == 0: + c = color(0, 0, 200) + si *= 0.5 + 0.5 * ((ix + iy) % 2) + + if (ix + iy) % 3 ==0: + c = color(200, 0, 0) + elif (ix + iy) % 2 == 0: + c = color(0, 0, 200) + + + + if args[0] in (RECT, ELLIPSE): + return (sh, x, y, si, si, c) + print sh + elif sh == TRIANGLE: + return (TRIANGLE, x, y, x + si, y, x, y + si, c) + elif sh == TRIANGLES: + return (TRIANGLE, x, y, x - si, y, x, y - si, c) + + @staticmethod + def draw_element(el, sx, sy): + fill(el[-1]) + sh, ex, ey = el[0], el[1], el[2] + pushMatrix() + translate(sx, sy) + if sh == RECT: + rect(ex, ey, el[3], el[4]) + if sh == ELLIPSE: + ellipse(ex, ey, el[3], el[4]) + print "e" + if sh == TRIANGLE: + triangle(ex, ey, el[3], el[4], el[5], el[6]) + popMatrix() diff --git a/2019/sketch_190813a/sketch_190813a.pyde b/2019/sketch_190813a/sketch_190813a.pyde new file mode 100644 index 00000000..f6931602 --- /dev/null +++ b/2019/sketch_190813a/sketch_190813a.pyde @@ -0,0 +1,49 @@ +"""Grid study""" + +from random import choice + +# add_library('GifAnimation') +# from gif_exporter import gif_export + +from grid import Grid + +def setup(): + size(500, 500) + rectMode(CENTER) + strokeJoin(ROUND) + strokeWeight(1.5) + create_grids() + frameRate(5) + noStroke() + +def create_grids(): + global grids + grids = [] + for i in range(20): + d = int(random(3, 11)) # TODO: rectangular grids + sp = 20 + x = int(random(-7, 8)) * sp + y = int(random(-7, 8)) * sp + si = random(10, 15) + sh = choice((ELLIPSE, ELLIPSE, ELLIPSE, ELLIPSE, TRIANGLE, RECT)) + grids.append(Grid(pos=(x, y), + dims=(d, d), + space=sp, + elem=(sh, si)) + ) + +def draw(): + background(240) + translate(width / 2., height / 2.) + # scale(.5, .5) + + for g in grids: + g.update() + + # gif_export(GifMaker, filename="sketch_190806a") + +def keyPressed(): + if key == "s": + saveFrame("####.png") + if key == " ": + create_grids()