Daily Creative Coding

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

触れると動くスライム

/**
* touchable slime
*
* @author aa_debdeb
* @date 2016/11/29
*/

float noiseValue;
float time;

void setup(){
  size(640, 640);
  noiseValue = 0.5;  
  time = 0.0;
  background(150);
}

void draw(){
  fill(150, 100);
  rect(0, 0, width, height);
  translate(width / 2, height / 2);
  rotate(frameCount * 0.001);
  noStroke();
  fill(0, 200, 50);
  beginShape();
  float angStep = 10.0;
  for(float angle = 0; angle < 360 + angStep * 3; angle += angStep){
    float radius = 200;
    float radian = radians(angle);
    PVector pos = new PVector(radius * cos(radian), radius * sin(radian));
    float nradius = radius + noiseValue * map(noise(pos.x * 0.1 + 1000, pos.y * 0.1 + 1000, frameCount * time), 0, 1, -100, 100); 
    curveVertex(nradius * cos(radian), nradius * sin(radian));
  }
  endShape();
  
  if(mousePressed && sqrt(sq(mouseX - width / 2) + sq(mouseY - height / 2)) < 200){
    noiseValue = constrain(noiseValue * 1.1, 0.0, 1.0); 
  }
  noiseValue = constrain(noiseValue * 0.98, 0.0, 1.0);
  
  time += map(noiseValue, 0, 1.0, 0, 0.0005);
    
}
f:id:aa_debdeb:20161121072056j:plain