noisy cube

squared

I had a previous idea boiling in my head since last week but I just couldn’t figure out a generic algorithm for it to apply to 3 < n < 11 sided regular polygons. I had the code half-written out, and then scrapped it because I felt stifled. Then I had the fantastic notion of working in 3D. It turns out working in 3D in Processing, especially on Windows, is a terrible idea: I kept getting errors that could only be avoided by working on a Mac. I slowly fell into a negative feedback loop of badness and felt bad in general while working on the GIF. Translating things from a drawing to a computational form is difficult and frustrating; so what you see above isn’t what I envisioned, but it’s as close as I can get with my current level of comfortableness with working with graphics in code. I wish I had more time to understand P3D better so that I could add more things to the GIF but ah well.

In short, I wanted to make the cube vibrate even more, and maybe even add more colors to it. Also, the particles were really supposed to be particles; instead they came out looking terribly rectangular, but I don’t really know why.

wow

int grad;
float vibrate = 0.5;
float wiggled = 0.1;
float wiggle;
int particleCount = 1000;
Particle[] particles = new Particle[particleCount+1];
float rx;
float ry;
float t = 0;

void setup()
{
  smooth();
  noFill();
  stroke(255);
  strokeWeight(3);
  smooth();
  size(600, 600, P3D);
  float horiz = 0;
  for (int i = 0; i < particleCount - 4; i+=5) {
    particles[i] = new Particle(width/2, horiz); 
    particles[i+1] = new Particle(width/2+1, horiz);
    particles[i+2] = new Particle(width/2-1, horiz);
    particles[i+3] = new Particle(width/2+1, horiz + 3);
    particles[i+4] = new Particle(width/2-1, horiz + 3);
    horiz+=5;
  }
  for (int j = 0; j < particleCount; j++) {
    particles[j].drawticle();
  }
  rx = 0;
  ry = 0;
  grad = 0;
}

void draw() {
  if (grad > 255) {
    grad = 0;
    background(255);
  }
  else  background(0);
  fill(grad);
  pushMatrix();
  translate(width/2+vibrate, height/2+vibrate);
  rotateX(rx);
  rotateY(ry);
  box(100*wiggle);
  popMatrix();
  for (int k = 0; k < particleCount; k++) {
    particles[k].update();
    particles[k].drawticle();
  }
  rx+=0.01;
  ry+=0.01;
  vibrate*=-1;
  grad+=10;
  wiggle = noise(wiggled);
  wiggled+=0.1;
}

class Particle {
  float xpos;
  float ypos;
  Particle(float x, float y) {
    xpos = x;
    ypos = y;
  }
  void update() {
    if (ypos == 0)
      ypos = 600;
    ypos-=1;
  }
  void drawticle() {
    hint(DISABLE_DEPTH_TEST);
    camera();
    noLights();
    ellipse(xpos, ypos, 0.1, 0.1);
    hint(ENABLE_DEPTH_TEST);
  }
}

Comments are closed.