Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Square Party

Name: Anonymous 2010-01-22 18:53

// It's time to get high /prog/. Load this into processing 1.0.9 and light yourself a fatty, preferably in that order.

RandSquare[] square;

float factor = 1.5;

int   squares = 300;
int   size_scale = int(400 * factor);
float len_max = 60 * factor;
float len_min = 20 * factor;
float pos = len_max/2 * factor;
float speed = 2 * factor;
float r, b, g, t = 0;
float freq = .001;
float amp_shift = 0;
float amplitude = 255/4;
float r_phase = random(2*3.1415);
float g_phase = random(2*3.1415);
float b_phase = random(2*3.1415);

void setup() {
  size(size_scale, size_scale);
  square = new RandSquare[squares];
  for(int i = 0; i < squares; i++) {
    square[i] = new RandSquare(color(random(255), random(255), random(255), random(255)), random(width), random(height), random(-speed, speed), random(-speed, speed), random(len_min, len_max));
  }
}

void draw() {
  bgshift();
  background(r, b, g);
  for(int i = 0; i < squares; i++) {
    square[i].move();
    square[i].display();
  }
}

void bgshift() {
  t += freq;
  if(t % (2 * 3.141) == 0) {
    t = 0;
  }
  r = amplitude * sin(t*r_phase) + amp_shift;
  b = amplitude * sin(t*b_phase) + amp_shift;
  g = amplitude * sin(t*g_phase) + amp_shift;
}

class RandSquare {
  color c;
  float xpos;
  float ypos;
  float xspeed;
  float yspeed;
  float len;
 
  RandSquare(color c_, float xpos_, float ypos_, float xspeed_, float yspeed_, float len_) {
    c = c_;
    xpos = xpos_;
    ypos = ypos_;
    xspeed = xspeed_;
    yspeed = yspeed_;
    len = len_;
  }
 
  void display() {
    noStroke();
    fill(c);
    rectMode(CENTER);
    rect(xpos, ypos, len, len);
  }
 
  void move() {
    xpos = xpos + xspeed;
    ypos = ypos + yspeed;
    if((xpos > width + pos + 1) || (xpos < -pos - 1) || (ypos > height + pos + 1) || (ypos < -pos - 1)) {
      reset();
    }
  }
 
  void reset() {
    int coin = int(random(4));
      c = color(random(255), random(255), random(255), random(127,245));
      len = random(len_min, len_max);
      if (coin == 0) {
        xpos = width + pos;
        ypos = random(-pos, height + pos);
        xspeed = random(-speed,0);
        yspeed = random(-speed,speed);
      }
      else if (coin == 1) {
        xpos = -pos;
        ypos = random(-pos, height + pos);
        xspeed = random(0,speed);
        yspeed = random(-speed,speed);
      }
      else if (coin == 2) {
        xpos = random(-pos, width + pos);
        ypos = height + pos;
        xspeed = random(-speed,speed);
        yspeed = random(-speed,0);
      }
      else {
        xpos = random(-pos, width + pos);
        ypos = -pos;
        xspeed = random(-speed,speed);
        yspeed = random(0,speed);
      }
  }
}

Name: Anonymous 2010-01-23 15:27

Look at how I write /prog/
Haha!

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List