- float noiseScale = 300f, noiseStrength = 3f;
- Particle[] particles = new Particle[50];
- void setup() {
- size(400, 400);
- smooth();
- noFill();
- stroke(0);
- strokeWeight(7);
- strokeCap(SQUARE);
- for(int i = 0; i < particles.length; i++) {
- particles[i] = new Particle();
- }
- }
- void draw() {
- background(255);
- for(int i = 0; i < particles.length; i++) {
- particles[i].update();
- }
- }
- class Particle {
- float x, y, r, t, ss;
- float xx, yy;
- boolean oob = false;
- Particle() {
- x = random(width);
- y = random(height);
- r = random(25);
- ss = random(.1, 2);
- }
- void update() {
- t = noiseStrength * noise(x / noiseScale, y / noiseScale);
- x += cos(t) * ss;
- y += sin(t) * ss;
- if(x < -r || x > width + r ||
- y < -r || y > height + r) {
- oob = true;
- }
- if(oob) {
- place();
- }
- render();
- }
- void place() {
- int d = int(random(4));
- switch(d) {
- case 0:
- x = -r;
- y = random(height);
- break;
- case 1:
- x = width + r;
- y = random(height);
- break;
- case 2:
- x = random(width);
- y = -r;
- break;
- case 3:
- x = random(width);
- y = height + r;
- break;
- default:
- x = random(width);
- y = height + r;
- break;
- }
- oob = false;
- }
- void render() {
- pushMatrix();
- translate(x, y);
- rotate(TWO_PI * t);
- arc(0, 0, r, r, PI / 64, TWO_PI - PI / 64);
- popMatrix();
- }
- }
This sketch works great as a Processing Applet, but I was recently asked to create a video of something similar to this as a seamless loopable video, around 5 seconds. Has anyone dealt with something like this before? I was thinking that maybe there is a way by saving the initial position of the Particle
and then setting that as the destination for the particle after a certain number of times it has been place
d? I thought I'd confer with the community first to see if anyone had dealt with something like this before?
1