Alexandre B A Villares 2019-09-17 23:56:36 -03:00
rodzic f4b15d8ac4
commit a18e254b56
10 zmienionych plików z 423 dodań i 0 usunięć

Wyświetl plik

@ -0,0 +1,40 @@
"""
Alexandre B A Villares http://abav.lugaralgum.com - GPL v3
A helper for the Processing gifAnimation library https://github.com/extrapixel/gif-animation/tree/3.0
Download from https://github.com/villares/processing-play/blob/master/export_GIF/unzip_and_move_to_libraries_GifAnimation.zip
This helper was inspired by an example by Art Simon https://github.com/APCSPrinciples/AnimatedGIF/
# add at the start of your sketch:
add_library('gifAnimation')
from gif_exporter import gif_export
# add 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=255, # quality range 0 - 255
delay=200, # this is quick
frames=0, # 0 will stop on keyPressed or frameCount >= 100000
finish=False): # force stop
global gifExporter
try:
gifExporter
except NameError:
gifExporter = GifMaker(this, filename + ".gif")
gifExporter.setRepeat(repeat)
gifExporter.setQuality(quality)
gifExporter.setDelay(delay)
gifExporter.addFrame()
if frames == 0:
if keyPressed and key == "e":
finish = True
if finish:
gifExporter.finish()
print("gif saved")
exit()

Wyświetl plik

@ -0,0 +1,30 @@
def glue_tab(p1, p2, tab_w=10, cut_ang=QUARTER_PI/2):
"""
draws a trapezoidal or triangular glue tab
along edge defined by p1 and p2, with provided
width (tab_w) and cut angle (cut_ang)
"""
a1 = atan2(p1[0] - p2[0], p1[1] - p2[1]) + cut_ang + PI
a2 = atan2(p1[0] - p2[0], p1[1] - p2[1]) - cut_ang
# calculate cut_len to get the right tab width
cut_len = tab_w / sin(cut_ang)
f1 = (p1[0] + cut_len * sin(a1),
p1[1] + cut_len * cos(a1))
f2 = (p2[0] + cut_len * sin(a2),
p2[1] + cut_len * cos(a2))
edge_len = dist(p1[0], p1[1], p2[0], p2[1])
if edge_len > 2 * cut_len * cos(cut_ang): # 'normal' trapezoidal tab
beginShape()
vertex(*p1) # vertex(p1[0], p1[1])
vertex(*f1)
vertex(*f2)
vertex(*p2)
endShape()
else: # short triangular tab
fm = ((f1[0] + f2[0]) / 2, (f1[1] + f2[1]) / 2)
beginShape()
vertex(*p1)
vertex(*fm) # middle way of f1 and f2
vertex(*p2)
endShape()

Wyświetl plik

@ -0,0 +1,58 @@
class Face:
def __init__(self, points, thickness, orientation = (0, 0, 0)):
self.points = points
self.thickness = thickness
self.o = orientation
def draw_2D(self):
draw_poly(self.points)
def draw_3D(self, rot):
S = 35.28
t = self.thickness
pts = self.points
with pushMatrix():
translate(0, height/2)
rotateX(self.o[0] * 0 + rot)
translate(0, -height/2)
translate(0, 0, -t/2)
fill(230)
draw_poly(pts)
translate(0, 0, t)
fill(170)
draw_poly(pts)
fill(250)
for p1, p2 in pairwise(tuple(pts) + (pts[0],)):
# print((p1, p2))
beginShape(QUAD_STRIP)
vertex(p1[0]*S, p1[1]*S, 0)
vertex(p1[0]*S, p1[1]*S, -t)
vertex(p2[0]*S, p2[1]*S, 0)
vertex(p2[0]*S, p2[1]*S, -t)
endShape()
def edges(self):
return pairwise(tuple(self.points) + (self.points[0],))
def draw_poly(points, closed=True):
S = 35.28
beginShape()
for p in points:
vertex(p[0]*S, p[1]*S, 0)
if closed:
endShape(CLOSE)
else:
endShape()
def pairwise(iterable):
import itertools
"s -> (s0,s1), (s1,s2), (s2, s3), ..."
a, b = itertools.tee(iterable)
next(b, None)
return zip(a, b)

Plik binarny nie jest wyświetlany.

Po

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

Wyświetl plik

@ -0,0 +1,95 @@
# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day
"""
Unfold extrusion
"""
add_library('GifAnimation')
from gif_exporter import gif_export
from parts import Face
from glue_tab import glue_tab
faces = []
THICK = 20
def setup():
size(500, 500, P3D)
hint(ENABLE_DEPTH_SORT)
def draw():
background(200, 210, 220)
# Face
fill(255, 100)
face_2D(250, 100, 250, 150, 15)
# Caixa
translate(250, 300)
rotateX(QUARTER_PI + frameCount/50.)
caixa(250, 150, 100, 15)
if frameCount/50. < TWO_PI:
if frameCount % 2:
gif_export(GifMaker, filename=SKETCH_NAME)
else:
exit()
def face_2D(x, y, w, h, e=0, closed=True):
mw, mh = w/2., h/2.
pushMatrix()
translate(x, y)
beginShape()
vertex(-mw, -mh)
vertex(+mw, -mh)
vertex(+mw, +mh)
vertex(-mw, +mh)
if e > 0 and mw - e > 0 and mh - e > 0:
beginContour()
np = 24
for i in range(np):
ang = TWO_PI / np * i
x = sin(ang) * e
y = cos(ang) * e
vertex(x, y)
endContour()
if closed:
endShape(CLOSE)
else:
endShape()
popMatrix()
def caixa(w, h, d, e=0):
mw, mh, md = w/2., h/2., d/2.
translate(0, 0, -md) # base
face_2D(0, 0, w, h, e)
translate(0, 0, d) # topo
face_2D(0, 0, w, h, e)
translate(0, 0, -md) # volta
rotateY(HALF_PI)
translate(0, 0, -mw) # lateral e
face_2D(0, 0, d, h, e)
translate(0, 0, w) # lateral d
face_2D(0, 0, d, h, e)
translate(0, 0, -mw) # volta
rotateY(-HALF_PI) # volta
rotateX(HALF_PI)
translate(0, 0, -mh) # lateral e
face_2D(0, 0, w, d, e)
translate(0, 0, h) # lateral d
face_2D(0, 0, w, d, e)
translate(0, 0, -mw) # volta
rotateX(-HALF_PI)
# print text to add to the project's README.md
def settings():
from os import path
global SKETCH_NAME
SKETCH_NAME = path.basename(sketchPath())
OUTPUT = ".gif"
println(
"""
![{0}](2019/{0}/{0}{1})
[{0}](https://github.com/villares/sketch-a-day/tree/master/2019/{0}) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
""".format(SKETCH_NAME, OUTPUT)
)

Wyświetl plik

@ -0,0 +1,40 @@
"""
Alexandre B A Villares http://abav.lugaralgum.com - GPL v3
A helper for the Processing gifAnimation library https://github.com/extrapixel/gif-animation/tree/3.0
Download from https://github.com/villares/processing-play/blob/master/export_GIF/unzip_and_move_to_libraries_GifAnimation.zip
This helper was inspired by an example by Art Simon https://github.com/APCSPrinciples/AnimatedGIF/
# add at the start of your sketch:
add_library('gifAnimation')
from gif_exporter import gif_export
# add 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=255, # quality range 0 - 255
delay=200, # this is quick
frames=0, # 0 will stop on keyPressed or frameCount >= 100000
finish=False): # force stop
global gifExporter
try:
gifExporter
except NameError:
gifExporter = GifMaker(this, filename + ".gif")
gifExporter.setRepeat(repeat)
gifExporter.setQuality(quality)
gifExporter.setDelay(delay)
gifExporter.addFrame()
if frames == 0:
if keyPressed and key == "e":
finish = True
if finish:
gifExporter.finish()
print("gif saved")
exit()

Wyświetl plik

@ -0,0 +1,30 @@
def glue_tab(p1, p2, tab_w=10, cut_ang=QUARTER_PI/2):
"""
draws a trapezoidal or triangular glue tab
along edge defined by p1 and p2, with provided
width (tab_w) and cut angle (cut_ang)
"""
a1 = atan2(p1[0] - p2[0], p1[1] - p2[1]) + cut_ang + PI
a2 = atan2(p1[0] - p2[0], p1[1] - p2[1]) - cut_ang
# calculate cut_len to get the right tab width
cut_len = tab_w / sin(cut_ang)
f1 = (p1[0] + cut_len * sin(a1),
p1[1] + cut_len * cos(a1))
f2 = (p2[0] + cut_len * sin(a2),
p2[1] + cut_len * cos(a2))
edge_len = dist(p1[0], p1[1], p2[0], p2[1])
if edge_len > 2 * cut_len * cos(cut_ang): # 'normal' trapezoidal tab
beginShape()
vertex(*p1) # vertex(p1[0], p1[1])
vertex(*f1)
vertex(*f2)
vertex(*p2)
endShape()
else: # short triangular tab
fm = ((f1[0] + f2[0]) / 2, (f1[1] + f2[1]) / 2)
beginShape()
vertex(*p1)
vertex(*fm) # middle way of f1 and f2
vertex(*p2)
endShape()

Wyświetl plik

@ -0,0 +1,58 @@
class Face:
def __init__(self, points, thickness, orientation = (0, 0, 0)):
self.points = points
self.thickness = thickness
self.o = orientation
def draw_2D(self):
draw_poly(self.points)
def draw_3D(self, rot):
S = 35.28
t = self.thickness
pts = self.points
with pushMatrix():
translate(0, height/2)
rotateX(self.o[0] * 0 + rot)
translate(0, -height/2)
translate(0, 0, -t/2)
fill(230)
draw_poly(pts)
translate(0, 0, t)
fill(170)
draw_poly(pts)
fill(250)
for p1, p2 in pairwise(tuple(pts) + (pts[0],)):
# print((p1, p2))
beginShape(QUAD_STRIP)
vertex(p1[0]*S, p1[1]*S, 0)
vertex(p1[0]*S, p1[1]*S, -t)
vertex(p2[0]*S, p2[1]*S, 0)
vertex(p2[0]*S, p2[1]*S, -t)
endShape()
def edges(self):
return pairwise(tuple(self.points) + (self.points[0],))
def draw_poly(points, closed=True):
S = 35.28
beginShape()
for p in points:
vertex(p[0]*S, p[1]*S, 0)
if closed:
endShape(CLOSE)
else:
endShape()
def pairwise(iterable):
import itertools
"s -> (s0,s1), (s1,s2), (s2, s3), ..."
a, b = itertools.tee(iterable)
next(b, None)
return zip(a, b)

Wyświetl plik

@ -0,0 +1,67 @@
# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day
"""
Unfold extrusion
"""
add_library('GifAnimation')
from gif_exporter import gif_export
from parts import Face
from glue_tab import glue_tab
faces = []
THICK = 20
def setup():
size(740, 480, P3D)
zig = [(2.5, 3.5), (5.5, 3.5), (2.5, 5.5),
(5.5, 5.5), (2.5, 7.5), (5.5, 7.5),
(3.5, 9.5), (8.5, 6.5), (5.5, 6.5),
(8.5, 4.5), (5.5, 4.5), (8.5, 2.5),
(5.5, 2.5), (7.5, 0.5)]
faces.append(Face(zig, THICK))
def draw():
background(200, 210, 220)
for f in faces:
f.draw_3D(frameCount / -50.)
translate(200, 0)
fill(170)
f.draw_2D()
translate(200, 0)
fill(230)
f.draw_2D()
x, y = 25, 350
translate(-400, 0)
for p1, p2 in f.edges():
d = dist(p1[0], p1[1], p2[0], p2[1]) * 35
fill(250)
glue_tab((x, y), (x + d, y))
glue_tab((x + d, y + THICK),( x, y + THICK))
rect(x, y , d, THICK)
x += d
if x > width - d:
glue_tab((x, y), (x, y + THICK))
x = 25
y += THICK * 2.2
else: # a for else...
glue_tab((x, y), (x, y + THICK))
if frameCount/50. < TWO_PI:
if frameCount % 2:
gif_export(GifMaker, filename=SKETCH_NAME)
else:
exit()
# print text to add to the project's README.md
def settings():
from os import path
global SKETCH_NAME
SKETCH_NAME = path.basename(sketchPath())
OUTPUT = ".gif"
println(
"""
![{0}](2019/{0}/{0}{1})
[{0}](https://github.com/villares/sketch-a-day/tree/master/2019/{0}) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
""".format(SKETCH_NAME, OUTPUT)
)

Wyświetl plik

@ -18,6 +18,11 @@ You may also support my artistic work, open teaching resources and research with
## 2019
---
![sketch_190917a](2019/sketch_190917a/sketch_190917a.gif)
[sketch_190917a](https://github.com/villares/sketch-a-day/tree/master/2019/sketch_190917a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
---