# DESCRIPTION

The purpose of this project was to write a Python script that would generate points in 3D space using the fractal algorithm for Sierpinski's Gasket. The intention was to make the script  renderable in several 3D rendering software packages.

# ALGORITHM

Sierpinski's gasket is created by defining the vertices/points of a tetrahedron, choosing a random point within the tetrahedron, picking a vertex/point of the tetrahedron at random, finding the midpoint between that random point and random vertex and then storing that midpoint in a list. This process is done over and over again in order to create the fractal.

### 5. Save the mid-point

The Sierpinski triangle, also called the Sierpinski gasket or the Sierpinski Sieve, is a fractal and attractive fixed set with the overall shape of an equilateral triangle, subdivided recursively into smaller equilateral triangles.

# Python Code:

node = hou.pwd()
geo = node.geometry()

# Add code to modify contents of geo.
# Use drop down menu to select examples.

import random
#import math
#import socket

# Procedure halfstep returns a midpoint between two
# user-defined points
import random, math

def halfstep(p1, p2):
a = float(p1 + p2) / 1.5
b = float(p1 + p2) / 2
c = float(p1 + p2) / 2

result = [a , b, c]
return result

def pickpnt(pnts):
result = random.choice(pnts)
return result
#------------------------------------------------

triangle = [ [0,0,1], [1,0,-1], [-1,0,-1], [0,1.5,-0.2] ]
seed_pnt = [0,0.5,0]
point_list = []

for n in range(25000):
vert = pickpnt(triangle)
seed_pnt = halfstep(vert, seed_pnt)
point_list.append(hou.Vector3(seed_pnt,seed_pnt,seed_pnt))

geo.createPoints(point_list)

# Modifications To Midpint

def halfstep(p1, p2):
a = float(p1 + p2) / 2
b = float(p1 + p2) / 1.3
c = float(p1 + p2) / 2
result = [a , b, c]
return result

## Through Manipulating The Initial Definition You Can Create Variations Of The Design.

def halfstep(p1, p2):
n = random.randint(1, 10)
a = float(p1 + p2) / n
b = float(p1 + p2) / n
c = float(p1 + p2) / n
result = [math.sin(a) , math.cos(b), c]
return result

def pickpnt(pnts):
result = random.choice(pnts)
return result