kopia lustrzana https://github.com/villares/sketch-a-day
190420
rodzic
30696498c7
commit
54ee80aaf7
Plik binarny nie jest wyświetlany.
|
Przed Szerokość: | Wysokość: | Rozmiar: 243 KiB |
Plik binarny nie jest wyświetlany.
|
Po Szerokość: | Wysokość: | Rozmiar: 147 KiB |
|
|
@ -75,13 +75,6 @@ def annotate_pts(pts, c):
|
||||||
point(x, y)
|
point(x, y)
|
||||||
text(str((i, j)), x, y)
|
text(str((i, j)), x, y)
|
||||||
|
|
||||||
def keyPressed():
|
|
||||||
global outer_pts
|
|
||||||
if key == " ":
|
|
||||||
outer_pts = [] # empty outer_pts
|
|
||||||
if key == "p":
|
|
||||||
println(outer_pts)
|
|
||||||
|
|
||||||
def mousePressed():
|
def mousePressed():
|
||||||
global outer_drag, inner_drag
|
global outer_drag, inner_drag
|
||||||
|
|
||||||
|
|
@ -131,19 +124,23 @@ def mouseReleased():
|
||||||
def keyPressed():
|
def keyPressed():
|
||||||
global outer_pts, inner_pts
|
global outer_pts, inner_pts
|
||||||
if key == " ":
|
if key == " ":
|
||||||
|
|
||||||
outer_pts = clockwise_sort(outer_pts)
|
outer_pts = clockwise_sort(outer_pts)
|
||||||
inner_pts = clockwise_sort(inner_pts)[::-1]
|
inner_pts = clockwise_sort(inner_pts)[::-1]
|
||||||
# if key == "g":
|
if key == "g":
|
||||||
# gif_export(GifMaker, filename=SKETCH_NAME)
|
gif_export(GifMaker, filename=SKETCH_NAME)
|
||||||
|
if key == "p":
|
||||||
def centeroidpython(data):
|
println(outer_pts)
|
||||||
x, y = zip(*data)
|
println(inner_pts)
|
||||||
data_len = len(x)
|
|
||||||
return sum(x) / data_len, sum(y) / data_len
|
|
||||||
|
|
||||||
def clockwise_sort(xy_pairs):
|
def clockwise_sort(xy_pairs):
|
||||||
# https://stackoverflow.com/questions/51074984/sorting-according-to-clockwise-point-coordinates
|
# https://stackoverflow.com/questions/51074984/sorting-according-to-clockwise-point-coordinates
|
||||||
centroid_x, centroid_y = centeroidpython(xy_pairs)
|
data_len = len(xy_pairs)
|
||||||
|
if data_len > 2:
|
||||||
|
x, y = zip(*xy_pairs)
|
||||||
|
else:
|
||||||
|
return xy_pairs
|
||||||
|
centroid_x, centroid_y = sum(x) / data_len, sum(y) / data_len
|
||||||
xy_sorted = sorted(xy_pairs,
|
xy_sorted = sorted(xy_pairs,
|
||||||
key = lambda p: atan2((p[1]-centroid_y), (p[0]-centroid_x)))
|
key = lambda p: atan2((p[1]-centroid_y), (p[0]-centroid_x)))
|
||||||
xy_sorted_xy = [coord for pair in list(zip(*xy_sorted)) for coord in pair]
|
xy_sorted_xy = [coord for pair in list(zip(*xy_sorted)) for coord in pair]
|
||||||
|
|
|
||||||
Ładowanie…
Reference in New Issue