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

30 min. Processing

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

重なる円と四角

p5.js 決定論
/**
 * overlayed circles and triangles
 * 
 * @author aadebdeb
 * @date 2017/02/20
 */

var bgColor;
var circleColor;
var triangleColor;

function setup() {
  createCanvas(windowWidth, windowHeight);
  colorMode(HSB, 360, 100, 100);
  frameRate(30);
  noStroke();
  mousePressed();
}

function mousePressed() {
  bgColor = color(random(360), 100, 100);
  circleColor = color(random(360), 100, 100);
  triangleColor = color(random(360), 100, 100);
}


function draw() {
  blendMode(BLEND);
  background(bgColor);
  blendMode(EXCLUSION);
  var r = 70;
  for (var x = -2; x * sqrt(3) / 2 * r <= width + r; x++) {
      var w = x * sqrt(3) / 2 * r;
    for (var y = -2; y * 3 / 2 * r <= height + r; y++) {
      var h = y * 3 / 2 * r;
      h += (x + y) % 2 == 0 ? r / 4: -r / 4;
      fill(circleColor);
      ellipse(w, h, r * 2, r * 2);

      fill(triangleColor);
      beginShape();
      for (var i = 0; i < 3; i++) {
        var angle = TWO_PI / 3 * i + frameCount * 0.02;
        angle += (x + y) % 2 == 0? -HALF_PI: HALF_PI;
        vertex(w + r * cos(angle), h + r * sin(angle));
      }
      endShape(CLOSE);
    }
  }
}
f:id:aa_debdeb:20170216095203j:plain