Polygon Fractals with Rhino Python
We will see a simple Rhino Python exercise here. I called these Polygon Fractals (or Pentaflakes sometimes). It is both educational and fun to play with them. In Rhino, it can be a good exercise for basic CAD commands and transformations such as move, copy, and scale, and precision drawing operations such as object snapping. Also, in Grasshopper, it can be a good challenge for looping. In Rhino Python, it is already a good exercise for understanding Python and the rhinoscriptsyntax module.
This form generation method, Polygon Fractals is based on an exercise I tried earlier in the Design Geometry course. As you can see, I repeat the selected polygon using a loop. I form new vertices at each step and carried them to the next step of the iteration. This creates a pattern that you can repeat as many times as desired. In such fractals, the geometric displacement rule is applied. It may not be correct to call these shapes that I have produced fractals. But in terms of self-similarity and diversity derived from the repetition of a simple operation, I think they could be called fractals.
# 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)
The Python code starts with the user inputs. Then I define the first polygon by drawing a circle and dividing it. Unfortunately, Rhino Python still doesn’t have a polygon method. Then, I define some variables like scale. After that, the for loop runs. On each iteration, I use all the points in the pointList as the center points of copied-scaled versions of the polygon. Immediately after this operation, I explode the newly created polygons. Because, in another loop, I add the vertices of the exploded polygons to a temporary list. After modifying the scale ratio this whole operation is repeated.