SOURCE

console 命令行工具 X clear

                    
>
console
var maxFlowers = 400,
  maxAttempts = 50000,
  maxRadius = 80,
  minRadius = 20,
  flowers = [],
  attempts = 0;

function setup() {
  var canvas = createCanvas(windowWidth, windowHeight);
  background("black");
  noLoop();
  createFlowers();
}

function draw() {
  for (var i = 0; i < flowers.length; i++) {
    curFlower = flowers[i];
    push();
    translate(curFlower.x, curFlower.y);
    flower(curFlower.r);
    pop();
  }
}

function createFlowers() {
  while (flowers.length < maxFlowers && attempts < maxAttempts) {
    var newFlower;
    var overlapping = false;
    newFlower = {
      x: Math.random() * windowWidth,
      y: Math.random() * windowHeight,
      r: minRadius
    };
    if (!isColliding(newFlower)) {
      while (!isColliding(newFlower) && newFlower.r < maxRadius) {
        newFlower.r++;
      }
      flowers.push(newFlower);
    }
    attempts++;
  }
}

function isColliding(circ) {
  for (var i = 0; i < flowers.length; i++) {
    var distance = dist(flowers[i].x, flowers[i].y, circ.x, circ.y),
      radius_sum = flowers[i].r + circ.r;
    if (radius_sum > distance) {
      return true;
    }
  }
  return false;
}

function flower(r) {
  noStroke();
  for (i = 0; i <= 2 * PI; i += PI / 4) {
    rotate(i);
    fill("#42B93E");
    beginShape();
    curveVertex(0, 0);
    curveVertex(0, 0);
    curveVertex(-0.26 * r, 0.75 * r);
    curveVertex(0, r);
    curveVertex(0.26 * r, 0.75 * r);
    curveVertex(0, 0);
    curveVertex(0, 0);
    endShape(0, 0);
    if (i == (7 / 4) * PI) {
      fill("#A7FFAB");
    }
  }
  stroke("#7A110C");
  strokeWeight(0.5);
  fill("#E2201E");

  ellipse(0, 0, r * 0.75, r * 0.75);
  noFill();
  stroke("#FF7874");
  strokeWeight(3);
  arc(0, 0, r * 0.6, r * 0.6, 2 * PI, HALF_PI);
}
* {
  margin: 0;
  padding: 0;
}
body {
  overflow: hidden;
}

本项目引用的自定义外部资源