sketch-a-day/2018/s141/s141.pyde

57 wiersze
1.8 KiB
Plaintext
Czysty Zwykły widok Historia

2018-05-20 03:05:32 +00:00
# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day
2018-05-21 11:05:49 +00:00
SKETCH_NAME = "s141" # 180521 Revisitig ideas from sketch s071 180312
2018-05-20 03:05:32 +00:00
2018-05-21 11:05:49 +00:00
# add_library('gifAnimation')
# from gif_exporter import *
2018-05-20 03:05:32 +00:00
def setup():
2018-05-21 11:05:49 +00:00
print_text_for_readme(SKETCH_NAME)
2018-05-20 03:05:32 +00:00
size(700, 700)
noFill()
def draw():
background(200)
grid = 4
2018-05-21 11:05:49 +00:00
border = 5
2018-05-20 03:05:32 +00:00
space = (width - border * 2) / grid
for x in range(grid):
for y in range(grid):
px = border + space / 2 + x * space
py = border + space / 2 + y * space
2018-05-21 11:05:49 +00:00
poly_shape(px, py, TWO_PI / (3 + y), x, 4, 2.7)
2018-05-20 03:05:32 +00:00
#gif_export(GifMaker, frames=10, filename=SKETCH_NAME)
2018-05-21 11:05:49 +00:00
saveFrame(SKETCH_NAME+".png")
2018-05-20 03:05:32 +00:00
noLoop()
2018-05-21 11:05:49 +00:00
def poly_shape(x, y, angle, rnd, gen, S):
2018-05-20 03:05:32 +00:00
with pushMatrix():
translate(x, y)
2018-05-21 11:05:49 +00:00
radius = gen * gen * S #+ random(-rnd, rnd)
2018-05-20 03:05:32 +00:00
ps = createShape() # to create a polygon on a ps PShape object
ps.beginShape()
a = 0
while a < TWO_PI:
sx = cos(a) * radius
sy = sin(a) * radius
ps.vertex(sx + random(-rnd, rnd), sy + random(-rnd, rnd))
a += angle
ps.endShape(CLOSE) # end of PShape creation
2018-05-21 11:05:49 +00:00
shape(ps, 0, 0) # genraw the PShape
if gen > 1: # if the recursion 'distance'/'depth' allows...
2018-05-20 03:05:32 +00:00
for i in range(ps.getVertexCount()):
# for each vertex
pv = ps.getVertex(i) # gets vertex as a PVector
2018-05-21 11:05:49 +00:00
# recusively call poly_shape with a smaller gen
poly_shape(pv.x, pv.y, angle, rnd, gen - 1, S)
2018-05-20 03:05:32 +00:00
def keyPressed():
loop()
2018-05-21 11:05:49 +00:00
def print_text_for_readme(name):
2018-05-20 03:05:32 +00:00
println("""
2018-05-21 11:05:49 +00:00
![{0}]({0}/{0}.png)
{1}: [code](https://github.com/villares/sketch-a-day/tree/master/{0}) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
""".format(name, name[1:])
2018-05-20 03:05:32 +00:00
)