text Flying particles.pde

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text Flying particles.pde相关的知识,希望对你有一定的参考价值。

// Creating an array of objects.
int oldx;
int oldy;

boolean recording = false;

Mover[] movers = new Mover[400];

void setup() {
  size(600,600);
  strokeWeight(2);
  strokeJoin(ROUND);
  smooth(8);
  background(255);
  // Initializing all the elements of the array
  for (int i = 0; i < movers.length; i++) {
    movers[i] = new Mover(); 
  }  
}

void keyPressed() {
 if (key == 'r' || key == 'R') {
  recording = !recording; 
 }
}

void draw() {
  noStroke();
  fill(134, 254, 145, 10);
  rect(0,0,width,height);
  background(255);

  // Calling functions of all of the objects in the array.
  for (int i = 0; i < movers.length; i++) {
    movers[i].update();
    movers[i].checkEdges();
    movers[i].display(); 
  }
  if (recording) {
  saveFrame("Beam/fram_####.png");
  }
}

class Mover {

  PVector location;
  PVector velocity;
  PVector acceleration;
  float topspeed;

  Mover() {
    location = new PVector(random(width),random(height));
    velocity = new PVector(0,0);
    topspeed = 3;
  }

  void update() {
oldx = int(location.x);
oldy = int(location.y);
    
    // Our algorithm for calculating acceleration:
  //  PVector mouse = new PVector(width+int(random(10, 40)), random(height));
      PVector mouse = new PVector(random(width), random(height));
    PVector dir = PVector.sub(mouse,location);  // Find vector pointing towards mouse
    dir.normalize();     // Normalize
    dir.mult(0.5);       // Scale 
    acceleration = dir;  // Set to acceleration

    // Motion 101!  Velocity changes by acceleration.  Location changes by velocity.
    velocity.add(acceleration);
    velocity.limit(topspeed);
    location.add(velocity);
  }

  void display() {
    stroke(0);
    fill(175);
//    ellipse(location.x,location.y,1,1);

    if (location.x > width-5 || location.x < 5 || location.y < 5 || location.y > height-5) {
    } else {
            line(location.x,location.y,oldx,oldy);
    }
    
    /*
        if (location.x > width-5) {

    } else if (location.x < 5) {

    }

    if (location.y > height+5) {

    }  else if (location.y < 5) {

    } else {
      line(location.x,location.y,oldx,oldy);
    }*/
    
  }

  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;
    }

  }

}

以上是关于text Flying particles.pde的主要内容,如果未能解决你的问题,请参考以下文章

flying saucer 修改报表格式

英语里 现在分词做定语flying saucer(飞碟现在分词做定语此处不是正在) running

Java使用Flying Saucer实现HTML代码生成PDF文档

flying中的AOP和IOC

hdu1800 Flying to the Mars(字典树)

HDOJ1800 Flying to the Mars