/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://studio.sketchpad.cc/sp/pad/view/ro.3J-VrcnOLD9/rev.3887
*
* authors:
*
* Andy Miccolis
*
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
// SIZE
int h = 40; // Triangle size
float s = (h/6); // Circle size
// COLOR
background (0); // Background color
colorMode( HSB, 360, 100, 100, 100 ); // Set color mode to HSB
color c3 = color(0, 0, 100, 100); // Circle color
color c4 = color(0, 0, 100, 100); // Triangle stroke color
int hue1 = random(360); // Random hue for up-pointing triangles
int hue2 = random(360); // Random hue for down-pointing triangles
void setup() {
size(600, 600); // Canvas size (Integers only, please.)
smooth(); // Smooth edges
strokeWeight(0); // Stroke weight
stroke(c4); // Stroke color
}
void draw() {
// Draw the up-pointing triangles
for (float x = 0; x < (width / h); x++) {
for (float y = 0; y < (height / h); y++) {
// Random color
fill(hue1, random(100), random(80), 100);
// Check for even-ness
if( (y % 2) == 0) {
// Draw trianges for even rows
beginShape(POLYGON);
vertex((x * h)+ (h/2), y * h);
vertex(x * h, (y+1) * h);
vertex((x+1) * h, (y+1) * h);
endShape(CLOSE);
}
else {
// Draw triangles for odd rows
triangle((x * h), y * h, (x * h) - (h/2), ((y+1) * h), ((x+1) * h) - (h/2), (y+1) * h) - (h/2);
}
}
}
// Draw the down-pointing triangles
for (float x2 = 0; x2 < (width / h); x2++) {
for (float y2 = 0; y2 < (height / h); y2++) {
// Random color
fill( hue2, random(100), random(80), 100 );
// Check for even-ness
if( (y2 % 2) == 0) {
// Draw triangles for even rows
triangle((x2 * h) - (h/2), y2 * h, (x2 * h) + (h/2), y2 * h, x2 * h , (y2+1) * h);
}
else {
// Draw triangles for odd rows
triangle((x2 * h), y2 * h, (x2+1) * h, y2 * h, (x2 * h) + (h/2) , (y2+1) * h);
}
}
}
// Draw circles at intersections
for (float x3 = 0; x3 < (width / h); x3++) {
for (float y3 = 0; y3 < (height / h); y3++) {
//Circle color
fill(c3);
//Check for even-ness
if( (y3 % 2) == 0) {
// Draw circles for even rows
ellipse((x3 * h) - (h/2), y3 * h, s, s);
}
else {
// Draw circles for odd rows
ellipse((x3 * h) , y3 * h, s, s);
}
}
}
// End loop when rows hit the bottom of the canvas
if (y >= (height / h) ) {
noLoop();
}
else {
}
}