見出し画像

ProcessingでGenerative art#33


Code

ArrayList<Particle> particles;
int num = 1000; 
float colNoise;
float hue;

void setup(){
  size(800, 600);
  pixelDensity(2);
  colorMode(HSB, 360, 100, 100, 100);
  blendMode(ADD);
  background(200, 2, 5);
  strokeWeight(0.5);
  noFill();
  
  particles = new ArrayList<Particle>();
  for(int i = 0; i < num; i++){
    particles.add(new Particle(map(i, 0, num, 0, 360)));
  }
  
  colNoise = random(10);
}

void draw(){
  hue = map(noise(colNoise), 0, 1, 0, 30);
  stroke(hue, 90, 80);
  for(Particle p: particles){
    p.update();
    p.display();  
  }
  
  colNoise += 0.002;
}

void keyPressed(){
  if(key ==' ')saveFrame("####.png");
}

//------------------------------------------------------------------------------

class Particle{
  
  PVector pos, pPos;
  PVector vel;
  PVector acc;
  float r = 200;
  
  float theta;
  Particle(float _t){
    theta = radians(_t);
    pos = new PVector(width/2 + r * cos(theta), height/2 + r * sin(theta));
    vel = new PVector(random(-0.5, 0.5), random(-0.5, 0.5));
    acc = new PVector();
  }
  
  void update(){
    pPos = pos;
    PVector center = new PVector(width/2, height/2);
    PVector dir = PVector.sub(center, pos);
    dir.normalize();
    dir.mult(0.001);
    acc = dir;
    vel.add(acc);
    pos.add(vel);
  }
  
  void display(){
    line(pos.x, pos.y, pPos.x, pPos.y);
  }

Happy coding!!

応援してくださる方!いつでもサポート受け付けてます!