Hey there!
Pretty new to VVVV and Fuse. So this is probably a very trivial question which I can’t figure out for some reason.
Basically I’m trying to recreate a Sierpinski triangle using the chaos game method Chaos game - Wikipedia.
I also created a p5.js version which I then wanted to ‘port’ to VVVV.
Sadly I can’t yet upload files (new user rule). The bottom is cut off, but it’s just basic particle rendering stuff. This patch just spawns a bunch of particles within a 2D plane and renders them using basic sprites.
My main goal is to get each particle to decide a new position every frame in the simulation stage. To do so my approach was this:
- Create a random value for each particle every frame
- Use that value to choose one of 3 methods for changing the position (lerp halfway to the top vertex, lerp halfway to the bottom left or lerp halfway to the bottom right)
- Set the new position
- Repeat the process every frame to approximate the Sierpinski shape
Right now I just substituted the random value with a constant x value (see top right). But this means that every particle uses the same value.
Wish I could share the file because that would be a bit easier. Anyway hope I managed to explain this in an at least somewhat understandable way. Maybe all of this can be done way more efficiently without using nested IFs or something.
In any case, I put the P5 code below. Maybe this helps.
Thank you so much in advance!
Best wishes!
let points = [];
const numPoints = 5000;
function setup() {
createCanvas(600, 600);
background(255);
stroke(0);
strokeWeight(1);
// Initialize the buffer with random points inside the canvas
for (let i = 0; i < numPoints; i++) {
points.push(createVector(random(width), random(height)));
}
}
function draw() {
background(255); // Clear the background each frame to avoid trails
// Apply Sierpinski transformations to each point in the buffer
for (let i = 0; i < numPoints; i++) {
let p = points[i];
let r = random(1);
if (r < 0.33) {
// Move halfway to the top vertex
p.x = lerp(p.x, width / 2, 0.5);
p.y = lerp(p.y, 0, 0.5);
} else if (r < 0.66) {
// Move halfway to the bottom-left vertex
p.x = lerp(p.x, 0, 0.5);
p.y = lerp(p.y, height, 0.5);
} else {
// Move halfway to the bottom-right vertex
p.x = lerp(p.x, width, 0.5);
p.y = lerp(p.y, height, 0.5);
}
// Draw the point at its new position
point(p.x, p.y);
}
}