villares 2019-05-17 23:34:56 -03:00
rodzic 1708f6d165
commit b1ed1a432e
7 zmienionych plików z 219 dodań i 0 usunięć

Wyświetl plik

@ -0,0 +1,28 @@
from random import choice
from polys import poly, poly_arc_augmented
class Ensamble:
def __init__(self, points, radius):
self.p_list = points
self.rad_list = radius
def __eq__(self, other):
return self.p_list == other.p_list
def plot(self):
rad_list = self.rad_list
noFill()
# strokeWeight(10)
# stroke(0, 100, 200)
# strokeJoin(ROUND)
# poly(self.p_list)
strokeWeight(10)
for i in range(len(rad_list)):
colorMode(HSB)
stroke(i 8, 255, 255)
poly_arc_augmented(self.p_list, rad_list)
rad_list[:] = [rad_list[-1]] + rad_list[:-1]

Wyświetl plik

@ -0,0 +1,43 @@
"""
Alexandre B A Villares http://abav.lugaralgum.com - GPL v3
A helper for the Processing gifAnimation library (https://github.com/jordanorelli)
ported to Processing 3 by 01010101 (https://github.com/01010101)
Download the library from https://github.com/01010101/GifAnimation/archive/master.zip
This helper was inspired by an example by Art Simon https://github.com/APCSPrinciples/AnimatedGIF/
Put at the start of your sketch:
add_library('gifAnimation')
from gif_exporter import gif_export
and at the end of draw():
gif_export(GifMaker)
"""
def gif_export(GifMaker, # gets a reference to the library
filename="exported", # .gif will be added
repeat=0, # 0 makes it an "endless" animation
quality=182, # quality range 0 - 255
delay=170, # this is quick
frames=0): # 0 will stop on keyPressed or frameCount >= 100000
global gifExporter
try:
gifExporter
except NameError:
gifExporter = GifMaker(this, filename + ".gif")
gifExporter.setRepeat(repeat)
gifExporter.setQuality(quality)
gifExporter.setDelay(delay)
gif_export._frame = frameCount
print("gif start")
gifExporter.addFrame()
# if (frames == 0 and keyPressed or frameCount - gif_export._frame >= 100000) \
# or (frames != 0 and frameCount - gif_export._frame >= frames):
# gifExporter.finish()
# background(255)
# print("gif saved")
# del(gifExporter)
# return False
# else:
# return True

Wyświetl plik

@ -0,0 +1,60 @@
# -*- coding: utf-8 -*-
def poly(p_list, closed=True):
beginShape()
for p in p_list:
if p[2] == 0:
vertex(p[0], p[1])
else:
vertex(*p)
if closed:
endShape(CLOSE)
else:
endShape()
def poly_arc_augmented(p_list, r_list):
a_list = []
for i1 in range(len(p_list)):
i2 = (i1 + 1) % len(p_list)
p1, p2, r1, r2 = p_list[i1], p_list[i2], r_list[i1], r_list[i2]
a = circ_circ_tangent(p1, p2, r1, r2)
a_list.append(a)
# ellipse(p1.x, p1.y, 2, 2)
for i1 in range(len(a_list)):
i2 = (i1 + 1) % len(a_list)
p1, p2, r1, r2 = p_list[i1], p_list[i2], r_list[i1], r_list[i2]
#ellipse(p1.x, p1.y, r1 * 2, r1 * 2)
a1 = a_list[i1]
a2 = a_list[i2]
if a1 and a2:
start = a1 if a1 < a2 else a1 - TWO_PI
arc(p2.x, p2.y, r2 * 2, r2 * 2, start, a2)
else:
# println((a1, a2))
ellipse(p1.x, p1.y, r1 * 2, r1 * 2)
ellipse(p2.x, p2.y, r2 * 2, r2 * 2)
def circ_circ_tangent(p1, p2, r1, r2):
d = dist(p1.x, p1.y, p2.x, p2.y)
ri = r1 - r2
line_angle = atan2(p1.x - p2.x, p2.y - p1.y)
if d > abs(ri):
theta = asin(ri / float(d))
x1 = cos(line_angle - theta) * r1
y1 = sin(line_angle - theta) * r1
x2 = cos(line_angle - theta) * r2
y2 = sin(line_angle - theta) * r2
# line(p1.x - x1, p1.y - y1, p2.x - x2, p2.y - y2)
x1 = -cos(line_angle + theta) * r1
y1 = -sin(line_angle + theta) * r1
x2 = -cos(line_angle + theta) * r2
y2 = -sin(line_angle + theta) * r2
line(p1.x - x1, p1.y - y1, p2.x - x2, p2.y - y2)
return (line_angle + theta)
else:
line(p1.x, p1.y, p2.x, p2.y)
return None

Plik binarny nie jest wyświetlany.

Po

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

Plik binarny nie jest wyświetlany.

Po

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

Plik binarny nie jest wyświetlany.

Po

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

Wyświetl plik

@ -0,0 +1,88 @@
# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day
from __future__ import division
from random import choice
from ensamble import Ensamble
add_library('GifAnimation')
from gif_exporter import gif_export
SPACING, MARGIN = 100, 250
grid = []
N = 8
combinations = ((0, 1, 2), (0, 1, 3), (0, 1, 4), (0, 1, 5),
(0, 1, 6), (0, 1, 7), (0, 2, 3), (0, 2, 4),
(0, 2, 5), (0, 2, 6), (0, 2, 7), (0, 3, 4),
(0, 3, 5), (0, 3, 6), (0, 3, 7), (0, 4, 5),
(0, 4, 6), (0, 4, 7), (0, 5, 6), (0, 5, 7),
(0, 6, 7), (1, 2, 3), (1, 2, 4), (1, 2, 5),
(1, 2, 6), (1, 2, 7), (1, 3, 4), (1, 3, 5),
(1, 3, 6), (1, 3, 7), (1, 4, 5), (1, 4, 6),
(1, 4, 7), (1, 5, 6), (1, 5, 7), (1, 6, 7),
(2, 3, 4), (2, 3, 5), (2, 3, 6), (2, 3, 7),
(2, 4, 5), (2, 4, 6), (2, 4, 7), (2, 5, 6),
(2, 5, 7), (2, 6, 7), (3, 4, 5), (3, 4, 6),
(3, 4, 7), (3, 5, 6), (3, 5, 7), (3, 6, 7),
(4, 5, 6), (4, 5, 7), (4, 6, 7), (5, 6, 7))
def setup():
global grid_list, rad_list
size(700, 700)
W, H = 700, 700
X_LIST = [x for x in range(MARGIN, 1 + W - MARGIN, SPACING)]
Y_LIST = [y for y in range(MARGIN, 1 + H - MARGIN, SPACING)]
print X_LIST
grid_list = []
for x in X_LIST:
for y in Y_LIST:
grid_list.append((x, y))
grid_list.pop(len(grid_list) // 2)
rad_list = [20, 40, 60, 80, 100, 120, 140, 160]
create_grid(grid_list, rad_list)
def create_grid(grid_list, rad_list):
for a, b, c in combinations:
va = PVector(*grid_list[a])
vb = PVector(*grid_list[b])
vc = PVector(*grid_list[c])
e = Ensamble((va, vb, vc), [rad_list[a], rad_list[b], rad_list[c]])
grid.append(e)
def draw():
translate(0, 50)
scale(1 / N, 1 / N)
background(250, 250, 240)
for x in range(N):
for y in range(N):
pushMatrix()
translate(x * 700, y * 700)
if x + y * N < 56:
grid[x + y * N].plot()
popMatrix()
def keyPressed():
if key == " ":
grid[:] = []
rad_list[:] = rad_list[1::]+[rad_list[0]]
create_grid(grid_list, rad_list)
if key == "s":
saveFrame("###.png")
if key == "g":
gif_export(GifMaker, filename=SKETCH_NAME, delay=1200)
def settings():
from os import path
global SKETCH_NAME
SKETCH_NAME = path.basename(sketchPath())
OUTPUT = ".gif"
println(
"""
![{0}]({2}/{0}/{0}{1})
[{0}](https://github.com/villares/sketch-a-day/tree/master/{2}/{0}) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
""".format(SKETCH_NAME, OUTPUT, year())
)