Skip to content

Instantly share code, notes, and snippets.

@nick3499
Created April 19, 2016 15:02
Show Gist options
  • Select an option

  • Save nick3499/5ea2ee976997c8b9a928b17ecfd40e75 to your computer and use it in GitHub Desktop.

Select an option

Save nick3499/5ea2ee976997c8b9a928b17ecfd40e75 to your computer and use it in GitHub Desktop.
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();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment