|
@@ -0,0 +1,124 @@
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+import os, glob, errno
|
|
|
+import math, random
|
|
|
+from PIL import Image, ImageDraw
|
|
|
+import svgwrite
|
|
|
+
|
|
|
+def generatePolygon( ctrX, ctrY, aveRadius, irregularity, spikeyness, numVerts ) :
|
|
|
+ '''Start with the centre of the polygon at ctrX, ctrY,
|
|
|
+ then creates the polygon by sampling points on a circle around the centre.
|
|
|
+ Randon noise is added by varying the angular spacing between sequential points,
|
|
|
+ and by varying the radial distance of each point from the centre.
|
|
|
+
|
|
|
+ Params:
|
|
|
+ ctrX, ctrY - coordinates of the "centre" of the polygon
|
|
|
+ aveRadius - in px, the average radius of this polygon, this roughly controls how large the polygon is, really only useful for order of magnitude.
|
|
|
+ irregularity - [0,1] indicating how much variance there is in the angular spacing of vertices. [0,1] will map to [0, 2pi/numberOfVerts]
|
|
|
+ spikeyness - [0,1] indicating how much variance there is in each vertex from the circle of radius aveRadius. [0,1] will map to [0, aveRadius]
|
|
|
+ numVerts - self-explanatory
|
|
|
+
|
|
|
+ Returns a list of vertices, in CCW order.
|
|
|
+ '''
|
|
|
+
|
|
|
+ irregularity = clip( irregularity, 0,1 ) * 2*math.pi / numVerts
|
|
|
+ spikeyness = clip( spikeyness, 0,1 ) * aveRadius
|
|
|
+
|
|
|
+
|
|
|
+ angleSteps = []
|
|
|
+ lower = (2*math.pi / numVerts) - irregularity
|
|
|
+ upper = (2*math.pi / numVerts) + irregularity
|
|
|
+ sum = 0
|
|
|
+ for i in range(numVerts) :
|
|
|
+ tmp = random.uniform(lower, upper)
|
|
|
+ angleSteps.append( tmp )
|
|
|
+ sum = sum + tmp
|
|
|
+
|
|
|
+
|
|
|
+ k = sum / (2*math.pi)
|
|
|
+ for i in range(numVerts) :
|
|
|
+ angleSteps[i] = angleSteps[i] / k
|
|
|
+
|
|
|
+
|
|
|
+ points = []
|
|
|
+ angle = random.uniform(0, 2*math.pi)
|
|
|
+ for i in range(numVerts) :
|
|
|
+ r_i = clip( random.gauss(aveRadius, spikeyness), 0, 2*aveRadius )
|
|
|
+ x = ctrX + r_i*math.cos(angle)
|
|
|
+ y = ctrY + r_i*math.sin(angle)
|
|
|
+ points.append( (int(x),int(y)) )
|
|
|
+
|
|
|
+ angle = angle + angleSteps[i]
|
|
|
+
|
|
|
+ return points
|
|
|
+
|
|
|
+def clip(x, min, max) :
|
|
|
+ if( min > max ) : return x
|
|
|
+ elif( x < min ) : return min
|
|
|
+ elif( x > max ) : return max
|
|
|
+ else : return x
|
|
|
+
|
|
|
+
|
|
|
+directory = "maps"
|
|
|
+try:
|
|
|
+ os.makedirs(directory)
|
|
|
+except OSError as exception:
|
|
|
+ if exception.errno != errno.EEXIST:
|
|
|
+ raise
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+for i in range(0, 1):
|
|
|
+
|
|
|
+ verts = generatePolygon( ctrX=500, ctrY=500, aveRadius=300, irregularity=1, spikeyness=0.15, numVerts=13 )
|
|
|
+
|
|
|
+ index = str(i) if i > 9 else '0'+str(i)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ svg = svgwrite.Drawing(filename = directory+"/map"+index+".svg",size = ("1000px", "1000px"))
|
|
|
+
|
|
|
+ print(len(verts))
|
|
|
+ for v in range(0, len(verts)):
|
|
|
+ print('---- '+str(v)+' ----')
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ svg.save()
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|