Skip to content

Instantly share code, notes, and snippets.

@shioken
Last active April 4, 2020 07:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shioken/3283073c2593e9f0906bbeaa1e41d5e4 to your computer and use it in GitHub Desktop.
Save shioken/3283073c2593e9f0906bbeaa1e41d5e4 to your computer and use it in GitHub Desktop.
Processingで七宝つなぎ
int size;
void setup() {
size(800, 600);
size = width / 16;
noLoop();
}
void draw() {
background(0);
PGraphics graphics = drawPattern();
drawGradient();
blendMode(LIGHTEST);
image(graphics, 0, 0);
save("shippou_tsunagi.png");
}
void drawGradient() {
// Draw Gradient
int steps = (width + size - 1) / size;
colorMode(HSB, 360, 100, 100);
float h = 119.0;
float a_h = (60 + 360 - h) / (steps / 2);
for (int xc = 0; xc <= steps / 2; xc++) {
fill(color(h, 100, 80));
noStroke();
int cx = xc * size;
for (int yc = 0; yc <= (height + size -1) / size; yc++) {
if ((xc % 2) + (yc % 2) == 1) {
int cy = yc * size;
drawShape(cx, cy);
drawShape(width - cx, cy);
}
}
h += a_h;
while (h > 360) h -= 360;
}
}
void drawShape(int cx, int cy) {
beginShape();
vertex(cx, cy - size);
vertex(cx + size, cy);
vertex(cx, cy + size);
vertex(cx - size, cy);
endShape(CLOSE);
}
PGraphics drawPattern() {
PGraphics graphics = createGraphics(width, height);
graphics.beginDraw();
graphics.background(255);
graphics.noStroke();
graphics.blendMode(DIFFERENCE);
int x_index = 0;
for (int x = 0; x < width + size; x+= size) {
int y_index = 0;
for (int y = 0; y < height + size; y+= size) {
if ((x_index % 2) + (y_index % 2) == 1) {
graphics.circle(x, y, size * 2);
}
y_index++;
}
x_index++;
}
graphics.blendMode(BLEND);
graphics.noFill();
graphics.stroke(255);
graphics.strokeWeight(2);
for (int x = 0; x < width; x += size) {
graphics.line(x, 0, x, height);
}
for (int y = 0; y < height; y += size) {
graphics.line(0, y, width, y);
}
graphics.endDraw();
return graphics;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment