node = hou.pwd()
geo = node.geometry()
# Create Variables.
iterations = node.parm("iterations").eval()
originx = float(node.parm("originx").eval())
originy = float(node.parm("originy").eval())
point1x = float(node.parm("point1x").eval())
point1y = float(node.parm("point1y").eval())
point2x = float(node.parm("point2x").eval())
point2y = float(node.parm("point2y").eval())
# Import math for the hilbert function
import sys, math
# Create the class that does the heavy lifting for the Hilbert Curve
class Hilbert:
# Recieve the variables from Hilbertclass
def __init__(self, x0, y0, xi, xj, yi, yj, n):
# Send variables to hilbert function for math to be done
self.hilbert(x0, y0, xi, xj, yi, yj, n)
def hilbert(self, x0, y0, xi, xj, yi, yj, n):
if n <= 0:
X = x0 + (xi + yi)/2
Y = y0 + (xj + yj)/2
point = [X, Y, 0]
# Send data to data, which whill pass it back to Hilbertclass
self.data(point)
else:
# The fancy math. Thank you Malcolm Kesson!
self.hilbert(x0, y0, yi/2, yj/2, xi/2, xj/2, n - 1)
self.hilbert(x0 + xi/2, y0 + xj/2, xi/2, xj/2, yi/2, yj/2, n - 1)
self.hilbert(x0 + xi/2 + yi/2, y0 + xj/2 + yj/2, xi/2, xj/2, yi/2, yj/2, n - 1)
self.hilbert(x0 + xi/2 + yi, y0 + xj/2 + yj, -yi/2,-yj/2,-xi/2,-xj/2, n - 1)
def data(self, point):
# Pass data back to Hilbertclass
pass
# This is the class that creates the points for the Hilbert Curve
class Hilbertclass(Hilbert):
def __init__(self, x0, y0, xi, xj, yi, yj, n):
# Give the input data to the base class
Hilbert.__init__(self, x0, y0, xi, xj, yi, yj, n)
def data(self, point):
# Create the point
curve = geo.createPoint()
# Set the position of the point
curve.setPosition(point)
# Add this newly set point to the polygon
poly.addVertex(curve)
# Create a Polygon to hold the vertex data
poly = geo.createPolygon()
# Set the polygon to be open so it acts like a line
polygon = poly.setIsClosed(False)
# Call Hilbertclass to begin all the procedures
Hilbertclass(originx,originy, point1x,point1y,point2x,point2y, iterations)
plus you have L-system that you can have more fun
tutorials.cgrecord.net/2016/12/vex-in-houdini-space-filling-curves.html