villares 2019-05-22 17:10:37 -03:00
rodzic d5fc720438
commit 841765b992
7 zmienionych plików z 158 dodań i 0 usunięć

Plik binarny nie jest wyświetlany.

Po

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

Plik binarny nie jest wyświetlany.

Po

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

Plik binarny nie jest wyświetlany.

Po

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

Wyświetl plik

@ -0,0 +1,111 @@
CORTE, VINCO = color(255, 0, 0), color(0, 0, 255)
def face(x, y, w, h, e):
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:
mw -= e
mh -= e
beginContour()
vertex(-mw, -mh)
vertex(-mw, +mh)
vertex(+mw, +mh)
vertex(+mw, -mh)
endContour()
endShape(CLOSE)
popMatrix()
def frame_box(w, h, d, e=0):
mw, mh, md = w/2., h/2., d/2.
translate(0, 0, -md) # base
face(0, 0, w, h, e)
translate(0, 0, d) # topo
face(0, 0, w, h, e)
translate(0, 0, -md) # volta
rotateY(HALF_PI)
translate(0, 0, -mw) # lateral e
face(0, 0, d, h, e)
translate(0, 0, w) # lateral d
face(0, 0, d, h, e)
translate(0, 0, -mw) # volta
rotateY(-HALF_PI) # volta
rotateX(HALF_PI)
translate(0, 0, -mh) # lateral e
face(0, 0, w, d, e)
translate(0, 0, h) # lateral d
face(0, 0, w, d, e)
translate(0, 0, -mw) # volta
rotateX(-HALF_PI)
def unfolded_box(w, h, d, e=0, draw_main=True):
mw, mh, md = w / 2., h / 2., d / 2.
face_unfold(0, -h - md, w, d, "aaan", e, draw_main)
face_unfold(0, -mh, w, h, "vvvv", e, draw_main)
face_unfold(0, -mh + mh + md, w, d, "cncv", e, draw_main)
face_unfold(0, +mh + d, w, h, "cncc", e, draw_main)
face_unfold(-mw - md, -mh, d, h, "acna", e, draw_main)
face_unfold(mw + md, -mh, d, h, "ncaa", e, draw_main)
def face_unfold(x, y, w, h, sides, e=0, draw_main=True):
l0, l1, l2, l3 = sides
mw, mh = w / 2., h / 2.
pushMatrix()
translate(x, y)
if draw_main:
edge(-mw, +mh, -mw, -mh, l0)
edge(-mw, -mh, +mw, -mh, l1)
edge(+mw, -mh, +mw, +mh, l2)
edge(+mw, +mh, -mw, +mh, l3)
if e > 0 and mw - e > 0 and mh - e > 0:
face_unfold(0, 0, w - e * 2, h - e * 2, "cccc")
popMatrix()
def edge(x0, y0, x1, y1, edge_type):
if edge_type == "n":
return
elif edge_type == "c":
stroke(CORTE)
else:
stroke(VINCO)
line(x0, y0, x1, y1)
if edge_type == "a":
stroke(CORTE)
noFill()
glue_tab((x0, y0), (x1, y1), 10)
def glue_tab(p1, p2, tab_w, cut_ang=QUARTER_PI / 3):
"""
draws a trapezoidal or triangular glue tab along edge defined by p1 and p2,
with width tab_w and cut angle a
"""
al = atan2(p1[0] - p2[0], p1[1] - p2[1])
a1 = al + cut_ang + PI
a2 = al - 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()

Plik binarny nie jest wyświetlany.

Po

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

Wyświetl plik

@ -0,0 +1,42 @@
# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day
from frame_box import frame_box, unfolded_box
modes = [-1, 0, 1] # click mouse to switch modes
def setup():
size(600, 600, P3D)
def draw():
background(200)
translate(300, 300)
if modes[0] >= 0:
fill(255)
stroke(0)
pushMatrix()
translate(0, 0, 200)
rotateX(HALF_PI / 2)
frame_box(250, 150, 100, 30)
popMatrix()
if modes[0] <= 0:
unfolded_box(250, 150, 100, 30)
def mousePressed():
modes[:] = modes[1:] + [modes[0]]
def keyPressed():
saveFrame("a###.png")
# para gerar o markdown que vai na página do sketch-a-day
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())
)

Wyświetl plik

@ -22,6 +22,11 @@ Get updates from my sort-of-weekly newsletter: [[sketch-mail](https://villares.o
## 2019
---
![sketch_190522a](2019/sketch_190522a/sketch_190522a.gif)
[sketch_190522a](https://github.com/villares/sketch-a-day/tree/master/2019/sketch_190522a) [[Py.Processing](https://villares.github.io/como-instalar-o-processing-modo-python/index-EN)]
---