2: Sierpinski gasket
I like the simplicity of this one. The key line is if ((x & (y-x)) == 0)
.
int patSize = 190;
int xOffset = 30, yOffset = 30;
void settings() { // to use variables within size()
size(patSize+xOffset*2,patSize+yOffset*2);
}
void setup() {
noLoop();
}
void draw() {
stroke(200, 20, 100);
for (int y = 0; y != patSize; ++y) {
for (int x = 0; x != patSize; ++x) {
if ((x & (y-x)) == 0)
point(x + (patSize/2) + xOffset -.5*y, y + yOffset); // -.5*y term rotates
}
}
}