Random value per particle per frame

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:

  1. Create a random value for each particle every frame
  2. 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)
  3. Set the new position
  4. 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);
  }
}

Nevermind, figured out that I can use noise 3D scalar with the position to get a fairly uniform result. Only thing is that this noise doesn’t seem to be uniformly between 0-1

So I have to use 0.5 and 0.6 now to make it look even

Oh yeah, just to update this post and leave an answer in case anyone ever needs this in the future for some reason:

A “Random” node instead of noise was the way to go. For some reason it didn’t play nice in my previous test which is why I switched to Noise. The difference in this case came down to the distribution of the random values. Random is ‘truly’ random across the range which is what I needed here.

Also got rid of the if statements by just multiplying each transformation with the boolean values of the comparisons (so if a particle uses a random value of 0.8 for example the >0.66 would be true (1) and all others would be false (0). Then the particle is moved using every transformation but the first two are just multiplied by 0 so they have no effect).

It seems to be slightly faster than before, but I haven’t done extensive testing. It does look cleaner though :D

2 Likes