kopia lustrzana https://github.com/villares/sketch-a-day
190610a
rodzic
470634c186
commit
325ab196cc
|
@ -5,10 +5,10 @@ p1
|
|||
(dp2
|
||||
S'closed'
|
||||
p3
|
||||
I01
|
||||
I00
|
||||
sS'lw'
|
||||
p4
|
||||
I1
|
||||
I5
|
||||
sS'id'
|
||||
p5
|
||||
I0
|
||||
|
@ -16,19 +16,19 @@ sS'pts'
|
|||
p6
|
||||
(lp7
|
||||
(I0
|
||||
I7
|
||||
I0
|
||||
I-1
|
||||
tp8
|
||||
a(I6
|
||||
I0
|
||||
a(I0
|
||||
I-1
|
||||
I1
|
||||
tp9
|
||||
a(I6
|
||||
I6
|
||||
a(I4
|
||||
I-1
|
||||
I1
|
||||
tp10
|
||||
a(I0
|
||||
I6
|
||||
a(I4
|
||||
I7
|
||||
I0
|
||||
tp11
|
||||
asS'holes'
|
||||
|
@ -51,36 +51,108 @@ I1
|
|||
sS'pts'
|
||||
p20
|
||||
(lp21
|
||||
(I-1
|
||||
I-1
|
||||
(I-2
|
||||
I2
|
||||
I0
|
||||
tp22
|
||||
a(I-6
|
||||
I-1
|
||||
a(I-3
|
||||
I2
|
||||
I0
|
||||
tp23
|
||||
a(I-6
|
||||
I-6
|
||||
a(I-3
|
||||
I-1
|
||||
I0
|
||||
tp24
|
||||
a(I-1
|
||||
I-6
|
||||
a(I-9
|
||||
I-1
|
||||
I0
|
||||
tp25
|
||||
asS'holes'
|
||||
p26
|
||||
(lp27
|
||||
(lp28
|
||||
(I-2
|
||||
a(I-9
|
||||
I2
|
||||
I0
|
||||
tp26
|
||||
a(I-10
|
||||
I2
|
||||
I0
|
||||
tp27
|
||||
a(I-10
|
||||
I-1
|
||||
I0
|
||||
tp28
|
||||
a(I-10
|
||||
I-3
|
||||
I0
|
||||
tp29
|
||||
a(I-3
|
||||
I-3
|
||||
I1
|
||||
a(I-6
|
||||
I-7
|
||||
I0
|
||||
tp30
|
||||
a(I-2
|
||||
I-2
|
||||
I-3
|
||||
I0
|
||||
tp31
|
||||
aasba.
|
||||
asS'holes'
|
||||
p32
|
||||
(lp33
|
||||
(lp34
|
||||
(I-3
|
||||
I-2
|
||||
I0
|
||||
tp35
|
||||
a(I-6
|
||||
I-5
|
||||
I1
|
||||
tp36
|
||||
a(I-9
|
||||
I-2
|
||||
I0
|
||||
tp37
|
||||
aasba(ipoly
|
||||
Poly
|
||||
p38
|
||||
(dp39
|
||||
S'closed'
|
||||
p40
|
||||
I00
|
||||
sS'lw'
|
||||
p41
|
||||
I5
|
||||
sS'id'
|
||||
p42
|
||||
I2
|
||||
sS'pts'
|
||||
p43
|
||||
(lp44
|
||||
sS'holes'
|
||||
p45
|
||||
(lp46
|
||||
(lp47
|
||||
asba(ipoly
|
||||
Poly
|
||||
p48
|
||||
(dp49
|
||||
S'closed'
|
||||
p50
|
||||
I00
|
||||
sS'lw'
|
||||
p51
|
||||
I5
|
||||
sS'id'
|
||||
p52
|
||||
I3
|
||||
sS'pts'
|
||||
p53
|
||||
(lp54
|
||||
(I0
|
||||
I3
|
||||
I0
|
||||
tp55
|
||||
a(I4
|
||||
I3
|
||||
I0
|
||||
tp56
|
||||
asS'holes'
|
||||
p57
|
||||
(lp58
|
||||
(lp59
|
||||
asba.
|
|
@ -65,12 +65,11 @@ class Poly():
|
|||
pp = cls.grid_to_screen(pts[i - 1])
|
||||
np = cls.grid_to_screen(pts[(i + 1) % len(pts)])
|
||||
r = corner * cls.cell_size
|
||||
b_roundedCorner((sx, sy), np, pp, r) # pt[2])
|
||||
b_roundedCorner((sx, sy), np, pp, r) # pt[2])
|
||||
else:
|
||||
if keyPressed:
|
||||
vertex(sx, sy)
|
||||
|
||||
|
||||
def remove_pt(self):
|
||||
snap = self.mouse_snap()
|
||||
if snap:
|
||||
|
@ -121,7 +120,9 @@ class Poly():
|
|||
cls.cell_size, cls.cell_size)
|
||||
|
||||
@staticmethod
|
||||
def clockwise_sort(xy_pairs):
|
||||
def clockwise_sort(pts):
|
||||
d = {(x, y): z for x, y, z in pts}
|
||||
xy_pairs = [(x, y) for x, y, z in pts]
|
||||
# https://stackoverflow.com/questions/51074984/sorting-according-to-clockwise-point-coordinates
|
||||
data_len = len(xy_pairs)
|
||||
if data_len > 2:
|
||||
|
@ -134,7 +135,8 @@ class Poly():
|
|||
xy_sorted_xy = [
|
||||
coord for pair in list(zip(*xy_sorted)) for coord in pair]
|
||||
half_len = int(len(xy_sorted_xy) / 2)
|
||||
return list(zip(xy_sorted_xy[:half_len], xy_sorted_xy[half_len:]))
|
||||
s = list(zip(xy_sorted_xy[:half_len], xy_sorted_xy[half_len:]))
|
||||
return [(x, y, d[(x, y)]) for x, y in s]
|
||||
|
||||
@classmethod
|
||||
def mouse_snap(cls):
|
||||
|
@ -150,15 +152,10 @@ class Poly():
|
|||
|
||||
@classmethod
|
||||
def mouse_pressed(cls):
|
||||
if keyPressed and keyCode == CONTROL:
|
||||
for p in cls.polys:
|
||||
if p.remove_pt(): # io, jo):
|
||||
return
|
||||
else:
|
||||
for ip, p in enumerate(cls.polys):
|
||||
if p.set_drag(): # io, jo):
|
||||
cls.selected_drag = ip
|
||||
return
|
||||
for ip, p in enumerate(cls.polys):
|
||||
if p.set_drag(): # io, jo):
|
||||
cls.selected_drag = ip
|
||||
return
|
||||
cls.selected_drag = -1 # click outside known vertices deselects
|
||||
|
||||
@classmethod
|
||||
|
@ -183,11 +180,11 @@ class Poly():
|
|||
dx, dy = mx - dragged_pt[0], my - dragged_pt[1]
|
||||
pts = poly.pts
|
||||
for i, pt in enumerate(pts):
|
||||
pts[i] = (pt[0] + dx, pt[1] + dy, pt[2] )
|
||||
pts[i] = (pt[0] + dx, pt[1] + dy, pt[2])
|
||||
for hole in poly.holes:
|
||||
for i, pt in enumerate(hole):
|
||||
hole[i] = (pt[0] + dx, pt[1] + dy, pt[2])
|
||||
|
||||
|
||||
@classmethod
|
||||
def grid_to_screen(cls, *args):
|
||||
if len(args) == 1:
|
||||
|
@ -209,24 +206,28 @@ class Poly():
|
|||
# and SHIFT key is pressed...
|
||||
if cls.drag_hole == -1: # if no hole wase selected
|
||||
poly = cls.polys[cls.selected_drag]
|
||||
i, j = cls.screen_to_grid(mouseX, mouseY )
|
||||
i, j = cls.screen_to_grid(mouseX, mouseY)
|
||||
poly.pts.insert(cls.drag_pt, (i, j, 0))
|
||||
else:
|
||||
poly = cls.polys[cls.selected_drag]
|
||||
hole = poly.holes[Poly.drag_hole]
|
||||
i, j = cls.screen_to_grid(mouseX, mouseY )
|
||||
i, j = cls.screen_to_grid(mouseX, mouseY)
|
||||
hole.insert(cls.drag_pt, (i, j, 0))
|
||||
elif cls.selected_drag >= 0 and keyPressed and keyCode == CONTROL:
|
||||
for p in cls.polys:
|
||||
if p.remove_pt(): # io, jo):
|
||||
return
|
||||
# Poly.selected_drag = -1 # No poly selected
|
||||
Poly.drag_hole = -1 # No hole selected
|
||||
Poly.drag_pt = -1 # No point selected
|
||||
|
||||
|
||||
@classmethod
|
||||
def duplicate_selected(cls, off=1):
|
||||
if Poly.selected_drag >= 0:
|
||||
new_poly = deepcopy(cls.polys[cls.selected_drag])
|
||||
for i, pt in enumerate(new_poly.pts):
|
||||
new_poly.pts[i] = (pt[0] + off, pt[1] + off, pt[2])
|
||||
for h in new_poly.holes:
|
||||
for i, pt in enumerate(h):
|
||||
h[i] = (pt[0] + off, pt[1] + off, pt[2])
|
||||
cls.polys.append(new_poly)
|
||||
def duplicate_selected(cls, offset=1):
|
||||
if Poly.selected_drag >= 0:
|
||||
new_poly = deepcopy(cls.polys[cls.selected_drag])
|
||||
for i, pt in enumerate(new_poly.pts):
|
||||
new_poly.pts[i] = (pt[0] + offset, pt[1] + offset, pt[2])
|
||||
for h in new_poly.holes:
|
||||
for i, pt in enumerate(h):
|
||||
h[i] = (pt[0] + off, pt[1] + off, pt[2])
|
||||
cls.polys.append(new_poly)
|
||||
|
|
Plik binarny nie jest wyświetlany.
Po Szerokość: | Wysokość: | Rozmiar: 60 KiB |
|
@ -1,16 +1,16 @@
|
|||
# Alexandre B A Villares - https://abav.lugaralgum.com/sketch-a-day
|
||||
"""
|
||||
A minimal poly editor
|
||||
- Add points
|
||||
- MODES: move, add vertex, change vertex, remove vertex
|
||||
"""
|
||||
import pickle
|
||||
from poly import Poly
|
||||
# add_library('GifAnimation')
|
||||
# from gif_exporter import gif_export
|
||||
add_library('GifAnimation')
|
||||
from gif_exporter import gif_export
|
||||
|
||||
|
||||
def setup():
|
||||
size(500, 500, P2D)
|
||||
size(500, 500)
|
||||
|
||||
f = createFont("Fira Mono", 16)
|
||||
textFont(f)
|
||||
|
@ -55,12 +55,19 @@ def keyPressed():
|
|||
p.pts[:] = Poly.clockwise_sort(p.pts)
|
||||
for h in p.holes:
|
||||
h[:] = Poly.clockwise_sort(h)[::-1]
|
||||
# if key == "g":
|
||||
# gif_export(GifMaker, filename=SKETCH_NAME)
|
||||
if key == "g":
|
||||
gif_export(GifMaker, filename=SKETCH_NAME)
|
||||
if key == "p":
|
||||
saveFrame(SKETCH_NAME + ".png")
|
||||
if key == "t":
|
||||
Poly.text_on = not Poly.text_on
|
||||
if key == "c" and Poly.selected_drag >= 0:
|
||||
p = Poly.polys[Poly.selected_drag]
|
||||
p.closed = not p.closed
|
||||
if p.closed:
|
||||
p.lw = 1
|
||||
else:
|
||||
p.lw = 5
|
||||
|
||||
if key == "s":
|
||||
with open("data/project.data", "wb") as file_out:
|
||||
|
|
Ładowanie…
Reference in New Issue