Houdini VEX - Sierpinski Triangle Algorithm
Inspired by a TikTok video that talks about the Sierpinski Triangle Algorithm. I’m recreating it in Houdini.

int points_to_generate = chi("Points");
vector positions[];
resize(positions, points_to_generate);
// Initial three vertices of the triangle from your input points
vector p1 = point(0, "P", 0); // (0.0, 1.0, 0.0)
vector p2 = point(0, "P", 1); // (0.866025, -0.5, 0.0)
vector p3 = point(0, "P", 2); // (-0.866025, -0.5, 0.0)
// Start with a random point inside the triangle
vector current = p1; // You can start anywhere, it will converge
// Generate points using the chaos game algorithm
for(int i = 0; i < points_to_generate; i++) {
// Pick a random vertex (1, 2, or 3)
float rand = random(i);
vector target;
if(rand < 0.333) {
target = p1;
} else if(rand < 0.666) {
target = p2;
} else {
target = p3;
}
// Move halfway to the chosen vertex
current = (current + target) * 0.5;
// Store the new point
positions[i] = current;
}
// Create points from the generated positions
for(int i = 0; i < points_to_generate; i++) {
addpoint(0, positions[i]);
}