Polygon Fractals with Rhino Python


Again, another example of utilizing Rhino Python for educational purposes and especially for designers.

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
# Drawing Simple Polygon Fractals
# 02.08.2017 www.designcoding.net - Tugrul Yazar
import rhinoscriptsyntax as rs
centerPoint = rs.GetPoint("Specify the center of polygon")
numberEdges = rs.GetInteger("Enter the number of edges", 6, 3)
radius = rs.GetReal("Specify the radius of polygon", 10)
iterat = rs.GetInteger("Enter the number of iterations", 3)
scale1 = rs.GetReal("Specify the first scale",0.5)
scale2 = rs.GetReal("Specify the fractal scale",0.4)
rs.EnableRedraw (False)
tempCircle = rs.AddCircle(centerPoint, radius)
pointList = rs.DivideCurve(tempCircle, numberEdges)
pointList.append(pointList[0])
rs.DeleteObject(tempCircle)
polygon = rs.AddPolyline(pointList)
nextRow = []
scale = scale1
for i in range(0, iterat):
	for x in pointList:
		vector = rs.VectorCreate(x, centerPoint)
		object = rs.CopyObject(polygon, vector)
		temp = rs.ScaleObject(object, x, [scale,scale,scale])
		prep = rs.ExplodeCurves(temp)
		for y in prep:
			nextRow.append(rs.CurveStartPoint(y))
			rs.DeleteObject(y)
	pointList = nextRow
	nextRow = []
	scale = scale * scale2
rs.EnableRedraw (True)
«
»