Daily Creative Coding

元「30 min. Processing」。毎日、Creative Codingします。

血管

/**
* blood vessels
*
* @author aa_debdeb
* @date 2016/03/06
*/

ArrayList<Particle> particles;
float radianNoiseX, radianNoiseY;

void setup(){
  size(640, 640);
  particles = new ArrayList<Particle>();
  for(int i = 0; i < 1000; i++){
    particles.add(new Particle());
  }
  radianNoiseX = random(5000);
  radianNoiseY = random(5000);
 
  background(255);
  stroke(180, 0, 0, 20);
  strokeWeight(1);
}

void draw(){
  for(Particle particle: particles){
    // for java mode
//    float radian = map(noise(radianNoiseX + mouseX + particle.pos.x * 0.02, radianNoiseY + mouseY + particle.pos.y * 0.02), 0, 1, 0, TWO_PI * 5) + random(PI / 6);
    // for JavaScript mode
    float radian = map(noise(radianNoiseX + mouseX + particle.pos.x * 0.02, radianNoiseY + mouseY + particle.pos.y * 0.02), 0.3, 0.7, 0, TWO_PI * 5) + random(PI / 6);
    
    particle.update(radian);
    particle.display();  
  }
}

void keyPressed(){
  background(0);
}

class Particle{
  
  PVector pos, pPos;
  float step;
  
  Particle(){
    pos = new PVector(random(width), random(height));
    step = map(random(1), 0, 1, 1, 1.5);
  }
  
  void update(float radian){
    pPos = pos;
    pos = PVector.add(pos, new PVector(step * cos(radian), step * sin(radian)));  
    if(pos.x < 0 || pos.x >= width || pos.y < 0 || pos.y >= height){
      pos = new PVector(random(width), random(height));
      pPos = new PVector(pos.x, pos.y);
    }
  }
  
  void display(){
    line(pPos.x, pPos.y, pos.x, pos.y);
  }
  
  
  
}