sketch1

 

‘2017年5月8日’


processingで描いたスケッチ。

以下、コード。

Mover[] mover = new Mover[200];

void setup() {
  fullScreen();
  //background(0);
  smooth();
  for (int i = 0; i < mover.length; i++) {
    mover[i] = new Mover();
  }
}

void draw() {
  fill(0, 10);
  rect(0, 0, width, height);
  //fill(255);
  for (int i = 0; i < mover.length; i++) {
  mover[i].move();
  mover[i].update();
  mover[i].checkEdges();
  mover[i].display();
  }
  
  //saveFrame("frames/######.tif");
}


class Mover {

  PVector location;
  PVector velocity;
  PVector acceleration;
  float topspeed;
  float x, y;
  
  Mover(float xpos, float ypos, float dia, float sp) {
    x = xpos;
    y = ypos;
  }

  Mover() {
    location = new PVector(width/2, height/2);
    velocity = new PVector(0, 0);
    topspeed = 6;
  }
  
  void move() {
    
  }
  
  void update() {

    acceleration = PVector.random2D();
    acceleration.mult(random(2));

    velocity.add(acceleration);
    velocity.limit(topspeed);
    location.add(velocity);
  }

  void display() {
    noStroke();
    fill(255);
    ellipse(location.x, location.y, 4,4);
  }

  void checkEdges() {
    
    if (location.x > width) {
      location.x = 0;
    } 
    else if (location.x < 0) {
      location.x = width;
    }

    if (location.y > height) {
      location.y = 0;
    } 
    else if (location.y < 0) {
      location.y = height;
    }
  }
}