Last active
April 6, 2017 04:28
-
-
Save jkwok91/5cd01da42913729b39295c5ea9c94af5 to your computer and use it in GitHub Desktop.
yep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var polygons = []; | |
var unitSlider, unit; | |
function setup() { | |
createCanvas(500, 500); | |
unitSlider = createSlider(10, 100, 50); | |
unit = 0; | |
} | |
function draw() { | |
background(0); | |
if (unitSlider.value() != unit) { | |
createPolys(); | |
} | |
polygons.map(function(p) { | |
p.show(); | |
}); | |
} | |
function createPolys() { | |
unit = unitSlider.value(); | |
var c1, c2, c3; | |
c1 = color(200, 30, 250); | |
c2 = color(200, 230, 50); | |
c3 = color(20, 230, 250); | |
var purple = color(200, 30, 200); | |
var alt = false; | |
for (var j = 0; j < height + unit/2; j += unit) { | |
for (var i = 0; i < width + unit/2; i += 2*unit) { | |
var x = i; | |
if (alt) { | |
x -= unit; | |
} | |
var p = new Polygon(c1); | |
p.addVertex(x, j); | |
p.addVertex(x + unit, j - unit/2); | |
p.addVertex(x + unit*2, j); | |
p.addVertex(x + unit, j + unit/2); | |
polygons.push(p); | |
var pL = new Polygon(c2); | |
pL.addVertex(x, j); | |
pL.addVertex(x + unit, j + unit/2); | |
pL.addVertex(x + unit, j + unit); | |
pL.addVertex(x, j + unit/2); | |
polygons.push(pL); | |
var pR = new Polygon(c3); | |
pR.addVertex(x + unit, j + unit/2); | |
pR.addVertex(x + unit*2, j); | |
pR.addVertex(x + unit*2, j + unit/2); | |
pR.addVertex(x + unit, j + unit); | |
polygons.push(pR); | |
} | |
alt = !alt; | |
} | |
} | |
function Polygon(c) { | |
this.vertices = []; | |
this.color = c; | |
this.addVertex = function(x, y) { | |
this.vertices.push(createVector(x, y)); | |
}; | |
this.show = function() { | |
fill(this.color); | |
stroke(255); | |
quad( | |
this.vertices[0].x, | |
this.vertices[0].y, | |
this.vertices[1].x, | |
this.vertices[1].y, | |
this.vertices[2].x, | |
this.vertices[2].y, | |
this.vertices[3].x, | |
this.vertices[3].y | |
); | |
}; | |
} |
Author
jkwok91
commented
Apr 5, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment