読者です 読者をやめる 読者になる 読者になる

30 min. Processing

毎日30分、Processingで何かを作る

ひだひだのリング

p5.js ランダム
/**
 * frilly ring
 *  
 * @author aadebdeb
 * @date 2017/02/12
 */

var isWire = false;

var nScale = 0.003;
var nOffset1;
var nOffset2;
function mousePressed() {
  isWire = !isWire;
}

function setup() {
  createCanvas(windowWidth, windowHeight);  
  frameRate(30);
  nOffset1 = createVector(random(10000), random(10000));
  nOffset2 = createVector(random(10000), random(10000));
}

function draw() {
  if (isWire) {
    background(0);
    stroke(255);
    noFill();
  } else {
    background(255);
    stroke(0);
    fill(0);
  }
  translate(width / 2, height / 2);
  beginShape(QUAD_STRIP);
  for(var angle = 0; angle <= 360; angle += 2) {
    var radian = radians(angle);
    var v1 = createVector(100 * sin(radian) * nScale, 100 * cos(radian) * nScale);
    var v2 = createVector(300 * sin(radian) * nScale, 300 * cos(radian) * nScale);
    var r1 = map(noise(v1.x + nOffset1.x, v1.y + nOffset1.y, frameCount * 0.01), 0, 1, 100, 250);
    var r2 = map(noise(v2.x + nOffset2.x, v2.y + nOffset2.y, frameCount * 0.01), 0, 1, 100, 250);
    vertex(r1 * sin(radian), r1 * cos(radian));
    vertex(r2 * sin(radian), r2 * cos(radian));
  }
  endShape();
}
f:id:aa_debdeb:20170209203153j:plain