nick34992
4/19/2016 - 3:02 PM

Begin Shape Quads. Using p5.js library.

Begin Shape Quads. Using p5.js library.

var x = 100;
var y = 50;

function setup() {
  // decreased resolution = increased performance
  createCanvas(896, 504);
}

function draw() {
  background(0);
  // locations extend beyond canvas
  for (i = 0; i < 300; i++) {
    trapezoid(random(-50, 950), random(-50, 600));
  }
  // decreased frame rate = increased performance
  frameRate(10);
}

// constructor with axis attributes
function trapezoid(x, y) {
  noStroke();
  // random shades of green
  fill(0, random(255), 0, 100);
  // create quadrangles/trapezoids
  beginShape(QUADS);
  vertex(x -   0, y -   0);
  vertex(x + 100, y -   0);
  vertex(x + 150, y - 150);
  vertex(x -  50, y - 150);
  endShape();
}