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

Party Squares Fix'd

Name: Anonymous 2010-01-23 10:31

Screenshot http://img706.imageshack.us/img706/4900/partysquares.png
Processing Dev. Env. http://processing.org/download/
Makes eye candy with ease (2D, 3D, OpenGL) and is fun to use. Tons of examples included with the IDE download. Downside is that it is Java based (double processing time?). In my example you can test how much it can handle at once by changing int squares to a higher value.


RandSquare[] square;

float factor = 1.5; //modify this to change the window size.

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 10:38

Wasn't thinking when I did this

  if(t % (2 * 3.141) == 0) {
    t = 0;
  }

should be

  if(t % (2 * 3.141) == 0) {
    t = .001;
  }

Name: Anonymous 2010-01-23 10:40

>>2
Actually never mind, previous statement does work. cocks

Name: Anonymous 2010-01-23 11:34

java

Name: Anonymous 2010-01-23 14:55

Involves actual programming; do not care

Name: sageru pantsu 2010-01-25 5:59

Impure code detected - skipping file...

Name: Anonymous 2011-02-03 7:35


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