kopia lustrzana https://github.com/villares/sketch-a-day
190414
rodzic
9b9c44638f
commit
0e690b4535
Plik binarny nie jest wyświetlany.
|
Po Szerokość: | Wysokość: | Rozmiar: 35 KiB |
|
|
@ -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()
|
||||||
|
|
@ -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()
|
||||||
|
|
@ -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(100, 200, 100)
|
||||||
|
draw_poly(pts)
|
||||||
|
translate(0, 0, t)
|
||||||
|
fill(100, 100, 200)
|
||||||
|
draw_poly(pts)
|
||||||
|
fill(200, 100, 100)
|
||||||
|
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: 329 KiB |
Plik binarny nie jest wyświetlany.
|
Po Szerokość: | Wysokość: | Rozmiar: 1.4 MiB |
|
|
@ -0,0 +1,67 @@
|
||||||
|
# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day
|
||||||
|
"""
|
||||||
|
|
||||||
|
"""
|
||||||
|
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(100, 100, 200)
|
||||||
|
f.draw_2D()
|
||||||
|
translate(200, 0)
|
||||||
|
fill(100, 200, 100)
|
||||||
|
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(200, 100, 100)
|
||||||
|
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}](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(SKETCH_NAME, OUTPUT)
|
||||||
|
)
|
||||||
|
|
@ -24,6 +24,13 @@ Get updates from my sort-of-weekly newsletter: [[sketch-mail](https://villares.o
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
[sketch_190414a](https://github.com/villares/sketch-a-day/tree/master/sketch_190414a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
|
||||||
|
|
||||||
|
Let's unfold some simple extrudes
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|
|
||||||
Ładowanie…
Reference in New Issue