つよくなりたいなあ

地に足をつけず世界を生きぬくブログです

181010

/*
 * 2018/10/10
 * invisible wind.
 */
import processing.pdf.*;

boolean savePDF = false;

int octaves = 4;
float falloff = 0.75;

color arcColor = color(100, 0, 75, 100);

float tileSize = 30;
int gridResolutionX, gridResolutionY;
boolean debugMode = true;


void setup() {
  size(800, 800);
  colorMode(HSB, 360, 100, 100);
  gridResolutionX = round(width/tileSize);
  gridResolutionY = round(height/tileSize);
  smooth();
}

void draw() {
  background(360);

  noiseDetail(octaves, falloff);
  float noiseXRange = mouseX/100.0;
  float noiseYRange = mouseY/100.0;

  for (int gY = 0; gY <= gridResolutionY; gY++) {
    for (int gX = 0; gX <= gridResolutionY; gX++) {
      float posX = tileSize*gX;
      float posY = tileSize*gY;

      // get noise value
      float noiseX = map(gX, 0, gridResolutionX, 0, noiseXRange);
      float noiseY = map(gY, 0, gridResolutionY, 0, noiseYRange);
      float noiseValue = noise(noiseX, noiseY);
      float angle = noiseValue * TWO_PI;

      pushMatrix();
      translate(posX, posY);

      if (debugMode) {
        noStroke();
        ellipseMode(CENTER);
        fill(noiseValue*360);
        ellipse(0, 0, tileSize*0.25, tileSize*0.25);
      }
      //arc
      noFill();
      strokeCap(SQUARE);
      strokeWeight(1);
      stroke(arcColor);
      arc(0, 0, tileSize*0.5, tileSize*0.5, 0, angle);
      popMatrix();
    }
  }
  if (savePDF) {
    savePDF = false;
    endRecord();
  }
}

void keyReleased() {
  if (key=='s') saveFrame("wind-###.png");
  if (key == 'p') savePDF = true;
}

void keyPressed() {
  if (keyCode == UP) falloff += 0.05;
  if (keyCode == DOWN) falloff -= 0.05;
  if (falloff > 1.0) falloff = 1.0;
  if (falloff < 0.0) falloff = 0.0;

  if (keyCode == LEFT) octaves--;
  if (keyCode == RIGHT) octaves++;
  if (octaves < 0) octaves = 0;
}

f:id:heyassy:20181011001848p:plain