-
Notifications
You must be signed in to change notification settings - Fork 0
/
voronoi.py
50 lines (36 loc) · 942 Bytes
/
voronoi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# voronoi stuff!
from scipy.spatial import Voronoi, voronoi_plot_2d
from cortexdraw import *
# Calculate Voronoi Polygons
square = [(0, 0), (0, 1), (1, 1), (1, 0)]
vor = Voronoi(square)
points = []
'''
# random points
for i in range(50):
points.append([random.random(), random.random()])
'''
'''
# trig curves, not really interesting it turns out
res = 10
for i in range(res):
x = i/res
y = math.sin(i/10)
y2 = math.cos(i/10) -1
points.append([x,y])
points.append([x,y2])
'''
vor = Voronoi(points)
def simple_voronoi(vor, saveas=None, lim=None):
# Make Voronoi Diagram
fig = voronoi_plot_2d(vor, show_points=True, show_vertices=False, s=4)
# Configure figure
fig.set_size_inches(5,5)
plt.axis("equal")
if lim:
plt.xlim(*lim)
plt.ylim(*lim)
# if not saveas is None:
# plt.savefig("../pics/%s.png"%saveas)
plt.show()
simple_voronoi(vor, saveas="square", lim=(-1.25,1.25))