見出し画像

ProcessingでGenerative art #59

Code

int actRandomSeed = 0;
float maxAngle = 720;
float diameter = 50;
float h = 2;

void setup() {
  size(800, 800);
  pixelDensity(2);
  colorMode(HSB, 360, 100, 100, 100);
  background(213, 96, 8);
}

void draw() {
  randomSeed(actRandomSeed);
  
  if(mousePressed){
  fan(mouseX, mouseY);
  }
}

void fan(float posX, float posY) {
  drawCircle(posX, posY);
  for (float angle=0; angle < maxAngle; angle+= random(20, 90)) {
    float randomLength = map(angle, 0, maxAngle, diameter, 0);
    pushMatrix();
    translate(posX, posY);
    rotate(random(PI*2));
    rotate(radians(angle));
    drawArc(0, 0, randomLength, 0, radians(random(100)));
    popMatrix();
  }
}

void drawArc(int posX, int posY, float d, float start, float end) {
  noStroke();
  for (float i=d; i>0; i--) {
    fill(h, map(i, d, 0, 100, 0), 90);
    arc(posX, posY, i, i, start, end, PIE);
  }
}

void drawCircle(float posX, float posY) {
  color color1= color(h, 100, 9);
  color color2= color(h, 100, 90);
  for (float d = diameter; d > 0; d-=20) {
    color c = lerpColor(color1, color2, d / diameter);
    stroke(c);
    noFill();
    ellipse(posX, posY, d * 0.75, d * 0.75);
  }
}

void mousePressed() {
  actRandomSeed = (int) random(100000);
}

void mouseDragged(){
  actRandomSeed = (int) random(100000);
}

void keyPressed(){
  if(key == '1')diameter = 50;
  if(key == '2')diameter = 150;
  if(key == '3')diameter = 250;
  if(key == '4')diameter = 350;
  if(key == '5')diameter = 450;
  
  //Red
  if(key == '6')h = 2;
  //Orange
  if(key == '7')h = 30;
  //Green
  if(key == '8')h = 130;
  //Blue
  if(key == '9')h = 209;
  //Purple
  if(key == '0')h = 299;
  
  if(key == 's')saveFrame("####.png");
  if(key == BACKSPACE)background(213, 96, 8);
}

Happy coding!

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