|
@@ -1,8 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
import os, glob, errno
|
|
|
import math, random
|
|
|
from PIL import Image, ImageDraw
|
|
@@ -11,7 +9,7 @@ import datetime
|
|
|
from sympy.geometry import Circle, Point
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
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.
|
|
@@ -57,10 +55,9 @@ def generatePolygon( ctrX, ctrY, aveRadius, irregularity, spikeyness, numVerts )
|
|
|
|
|
|
angle = angle + angleSteps[i]
|
|
|
|
|
|
- for i in range(10):
|
|
|
- points = fractalize(points)
|
|
|
+ lines = fractalize(points)
|
|
|
|
|
|
- return points
|
|
|
+ return lines
|
|
|
|
|
|
def clip(x, min, max) :
|
|
|
if( min > max ) : return x
|
|
@@ -69,26 +66,46 @@ def clip(x, min, max) :
|
|
|
else : return x
|
|
|
|
|
|
|
|
|
-def fractalize(pts) :
|
|
|
- print("Fractalize")
|
|
|
- print(pts)
|
|
|
- points = []
|
|
|
- for v in range(0, len(pts)):
|
|
|
- p1 = pts[v]
|
|
|
- print(p1)
|
|
|
- points.append(p1)
|
|
|
- p2 = pts[0] if v >= len(pts)-1 else pts[v+1];
|
|
|
- d = distance(p1,p2)
|
|
|
-
|
|
|
- r = d*0.52
|
|
|
- ps1,ps2 = circle_intersection((p1[0],p1[1],r), (p2[0],p2[1],r))
|
|
|
- print(ps1)
|
|
|
-
|
|
|
- if random.randint(1,2) == 2:
|
|
|
- points.append(ps2)
|
|
|
- else:
|
|
|
- points.append(ps1)
|
|
|
- return points
|
|
|
+def fractalize(points) :
|
|
|
+
|
|
|
+
|
|
|
+ lines = []
|
|
|
+ for p in range(0, len(points)):
|
|
|
+ p1 = points[p]
|
|
|
+
|
|
|
+
|
|
|
+ p2 = points[0] if p >= len(points)-1 else points[p+1];
|
|
|
+ pts = [p1,p2]
|
|
|
+
|
|
|
+
|
|
|
+ if random.randint(1,10) > 3:
|
|
|
+
|
|
|
+ for i in range(10):
|
|
|
+
|
|
|
+ fpts = []
|
|
|
+ for v in range(0, len(pts)-1):
|
|
|
+ fp1 = pts[v]
|
|
|
+ fpts.append(fp1)
|
|
|
+ fp2 = pts[v+1];
|
|
|
+ d = distance(fp1,fp2)
|
|
|
+
|
|
|
+ r = d*0.52
|
|
|
+ fps1,fps2 = circle_intersection((fp1[0],fp1[1],r), (fp2[0],fp2[1],r))
|
|
|
+
|
|
|
+
|
|
|
+ if random.randint(1,2) == 2:
|
|
|
+ fpts.append(fps2)
|
|
|
+ else:
|
|
|
+ fpts.append(fps1)
|
|
|
+
|
|
|
+
|
|
|
+ fpts.append(fp2)
|
|
|
+ pts = fpts
|
|
|
+
|
|
|
+
|
|
|
+ lines.append(pts)
|
|
|
+
|
|
|
+ return lines
|
|
|
|
|
|
|
|
|
def distance(p1,p2):
|
|
@@ -143,10 +160,11 @@ except OSError as exception:
|
|
|
raise
|
|
|
|
|
|
|
|
|
-for i in range(0, 1):
|
|
|
-
|
|
|
+for i in range(0, 99):
|
|
|
+ print(i)
|
|
|
nv = random.randint(5,30)
|
|
|
- verts = generatePolygon( ctrX=500, ctrY=500, aveRadius=300, irregularity=1, spikeyness=0.4, numVerts=nv )
|
|
|
+ lines = generatePolygon( ctrX=500, ctrY=500, aveRadius=300, irregularity=1, spikeyness=0.4, numVerts=nv )
|
|
|
+
|
|
|
|
|
|
index = str(i) if i > 9 else '0'+str(i)
|
|
|
|
|
@@ -158,27 +176,40 @@ for i in range(0, 1):
|
|
|
|
|
|
svg = svgwrite.Drawing(filename = directory+"/map"+index+".svg",size = ("1000px", "1000px"))
|
|
|
|
|
|
-
|
|
|
- for v in range(0, len(verts)):
|
|
|
-
|
|
|
- p1 = verts[v]
|
|
|
- p2 = verts[0] if v >= len(verts)-1 else verts[v+1];
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- sda = "0 0"
|
|
|
- sdo = "0"
|
|
|
+
|
|
|
+ polygone = []
|
|
|
+ for l in range(0, len(lines)):
|
|
|
+ for p in range(0, len(lines[l])):
|
|
|
+ polygone.append(lines[l][p])
|
|
|
+
|
|
|
+ bgline = svg.polyline(polygone,
|
|
|
+ stroke = "white",
|
|
|
+ stroke_width = "30",
|
|
|
+ stroke_linejoin= "round",
|
|
|
+ stroke_linecap = "round",
|
|
|
+ fill = "white")
|
|
|
+ svg.add(bgline)
|
|
|
+
|
|
|
+
|
|
|
+ for l in range(0, len(lines)):
|
|
|
+
|
|
|
+ if random.randint(0,10) > 8:
|
|
|
+ sw = "1"
|
|
|
+ sda = "4 4"
|
|
|
+ sdo = "5"
|
|
|
+ else:
|
|
|
+ sw = "1"
|
|
|
+ sda = "0 0"
|
|
|
+ sdo = "0"
|
|
|
|
|
|
- line = svg.line(p1, p2,
|
|
|
- stroke_width = "1",
|
|
|
+ line = svg.polyline(lines[l],
|
|
|
stroke = "black",
|
|
|
+ stroke_width = sw,
|
|
|
+ stroke_linejoin= "round",
|
|
|
stroke_linecap = "round",
|
|
|
stroke_dasharray = sda,
|
|
|
- stroke_dashoffset = sdo)
|
|
|
+ stroke_dashoffset = sdo,
|
|
|
+ fill = "none")
|
|
|
svg.add(line)
|
|
|
|
|
|
svg.save()
|