10_and_recover_8!

main
villares 2019-08-10 23:32:52 -03:00
rodzic bdcbfb009f
commit 7071201f9d
10 zmienionych plików z 291 dodań i 42 usunięć

Plik binarny nie jest wyświetlany.

Przed

Szerokość:  |  Wysokość:  |  Rozmiar: 18 KiB

Wyświetl plik

@ -1,48 +1,66 @@
"""Grid study"""
from random import choice
# add_library('GifAnimation')
# from gif_exporter import gif_export
class Grid():
from grid import 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 setup():
size(500, 500)
rectMode(CENTER)
strokeJoin(ROUND)
strokeWeight(1.5)
create_grids()
frameRate(5)
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
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, 25)
sh = choice((ELLIPSE, ELLIPSE, RECT, RECT, TRIANGLE, TRIANGLES))
grids.append(Grid(pos=(x, y),
dims=(d, d),
space=sp,
elem=(sh, si))
)
@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(0)
if int(si) % 3 == 0:
c = color(200, 0, 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 args[0] in (RECT, ELLIPSE):
return (sh, x, y, si, si, c)
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)
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()
@staticmethod
def draw_element(el, sx, sy):
stroke(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:
rect(ex, ey, el[3], el[4])
if sh == TRIANGLE:
triangle(ex, ey, el[3], el[4], el[5], el[6])
popMatrix()

Wyświetl plik

@ -0,0 +1,67 @@
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:
c = color(200, 0, 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 args[0] in (RECT, ELLIPSE):
return (sh, x, y, si, si, c)
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:
rect(ex, ey, el[3], el[4])
if sh == TRIANGLE:
triangle(ex, ey, el[3], el[4], el[5], el[6])
popMatrix()

Wyświetl plik

Przed

Szerokość:  |  Wysokość:  |  Rozmiar: 20 KiB

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 20 KiB

Wyświetl plik

@ -0,0 +1,48 @@
"""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)
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, 25)
sh = choice((ELLIPSE, ELLIPSE, RECT, RECT, TRIANGLE, TRIANGLES))
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()

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 9.3 KiB

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 11 KiB

Wyświetl plik

@ -0,0 +1,67 @@
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:
c = color(200, 0, 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 args[0] in (RECT, ELLIPSE):
return (sh, x, y, si, si, c)
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:
rect(ex, ey, el[3], el[4])
if sh == TRIANGLE:
triangle(ex, ey, el[3], el[4], el[5], el[6])
popMatrix()

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 13 KiB

Wyświetl plik

@ -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, RECT, RECT, TRIANGLE, TRIANGLES))
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()