xxxxxxxxxx
const w = 720;
const N = 5;
const span = w/N;
function setup() {
createCanvas(w, w);
colorMode(HSB);
noLoop();
background(20);
for(let i=0;i<N;i++){
let colors = [rand_color(), rand_color()];
for(let j=0;j<N;j++){
push();
translate(span*i, span*j);
_texture = new wa_pattern_textures(span, colors);
_shape = gen_shape(span*0.5, span*0.5, span);
_draw_image = draw_image(span);
image(_draw_image, 0, 0);
pop();
}
}
colorMode(RGB);
//get and grayscale
const rv = 0.2126;
const rg = 0.7152;
const rb = 0.0722;
let ary = [];
for(let i=0;i<w;i++){
ary[i] = [];
for(let j=0;j<w;j++){
c = get(j, i);
ary[i][j] = (red(c)*rv + green(c)*rg + blue(c)*rb);
}
}
//dithering
for(let i=0;i<w;i++){
for(let j=0;j<w;j++){
px = ary[i][j];
newpx = int(px / 255) * 255 ;
qe = px - newpx;
ary[i][j] = newpx;
if(i+1<w){ ary[i+1][j ] += qe * 7/16; }
if(i-1>-1 && j+1<w){ ary[i-1][j+1] += qe * 3/16; }
if(j+1<w){ ary[i ][j+1] += qe * 5/16; }
if(i+1<w && j+1<w){ ary[i+1][j+1] += qe * 1/16; }
}
}
for(let i=0;i<w;i++){
for(let j=0;j<w;j++){
set(j, i, int(ary[i][j]));
}
}
updatePixels();
}
function draw_image(size){
let gp = createGraphics(size, size);
gp.colorMode(HSB);
gp.push();
gp.image(_texture.img, 0, 0);
gp.blendMode(REMOVE);
gp.image(_shape, 0, 0);
gp.pop();
return gp;
}
function gen_shape(x, y, size){
let gp = createGraphics(size, size);
gp.colorMode(HSB);
gp.background(100);
const w = size;
const h = size;
gp.rectMode(CENTER);
gp.push();
gp.blendMode(REMOVE);
gp.fill(100);
gp.strokeWeight(0);
gp.rect(x,y,w, h);
gp.pop();
return gp;
}
function rand_color(){
return color(random(360), random(0,100), random(0,100));
}
class wa_pattern_textures{
constructor(size, colors){
this.size = size;
this.col = colors;
this.img = this.gen_texture();
}
gen_texture(){
let pg = createGraphics(this.size, this.size);
const p = int(random(9));
switch (p) {
case 0: this.ichimatsu_tex(pg);
break;
case 1: this.amime_tex(pg);
break;
case 2: this.shippo_tex(pg);
break;
case 3: this.seigaiha_tex(pg);
break;
case 4: this.uroko_tex(pg);
break;
case 5: this.ichinoji_tex(pg);
break;
case 6: this.bishi_tex(pg);
break;
case 7: this.higaki_tex(pg);
break;
case 8: this.kuginuki_tex(pg);
break;
default: pg.background(random(255));
break;
}
return pg;
}
amime_tex(pg){
pg.colorMode(HSB);
pg.noFill();
pg.background(this.col[0]);
pg.stroke(this.col[1]);
const N = int(random(1,3))*2;
const d=(pg.width/N);
const l = (pg.width/30);
pg.strokeWeight(l);
const pn = int(10*d/10);
for(let j=0;j<N*3/2;j++){
const y = d*(j+1/2)*2/3;
const dx = (j%2 == 1) ? PI : 0 ;
for(let i=0;i<N+1;i++){
const x = d*i;
pg.push();
pg.translate(x, y);
let pos = [];
pos[0] = [0, d/3*cos(dx)];
for(let k=1;k<pn;k++){
pos[1] = [d/pn*k, d/2*2/3*cos(TAU/pn*k + dx)];
pg.line(pos[0], pos[1]);
pos[0] = pos[1];
}
pg.pop();
}
}
}
ichimatsu_tex(pg){
pg.colorMode(HSB);
pg.noStroke();
pg.background(this.col[0]);
pg.fill(this.col[1]);
const N = int(random(2,5)*2);
const d=(pg.width/N);
for(let i=0;i<N+1;i++){
const x = d*i;
for(let j=0;j<N;j+=2){
const y = d*(j+i%2);
pg.push();
pg.translate(x, y);
pg.rect(0, 0, d);
pg.pop();
}
}
}
shippo_tex(pg){
pg.colorMode(HSB);
pg.push();
pg.ellipseMode(CORNER);
pg.noFill();
pg.background(this.col[0]);
pg.stroke(this.col[1]);
const N = int(random(3,7));
const d=(pg.width/N);
const l=int(pg.width/40);
pg.strokeWeight(l);
for(let i=0;i<N+1;i++){
const x = d*i;
for(let j=0;j<N+1;j++){
const y = d*j;
pg.push();
pg.translate(x, y);
pg.circle(0, 0, d);
pg.pop();
pg.push();
pg.translate(x-d*0.5, y-d*0.5);
pg.circle(0, 0, d);
pg.pop();
}
}
pg.pop();
}
seigaiha_tex(pg){
pg.colorMode(HSB);
pg.push();
pg.noStroke();
let c = [];
pg.background(c[0]=this.col[0]);
pg.fill(c[1]=this.col[1]);
const N = int(random(1,3));
const d=(pg.width/N);
for(let j=0;j<N*4+2;j++){
const y = d*j/4;
const dx = (j%2==1) ? d/2 : 0 ;
for(let i=0;i<N+1;i++){
const x = d*i + dx;
pg.push();
pg.translate(x, y);
for(let k=0;k<8;k++){
pg.fill(c[k%2]);
pg.circle(0, 0, d*(1/8*(8-k)));
}
pg.pop();
}
}
pg.pop();
}
uroko_tex(pg){
pg.colorMode(HSB);
pg.push();
pg.noStroke();
pg.background(this.col[0]);
pg.fill(this.col[1]);
const N = int(random(1,4)*2);
const d=(pg.width/N);
const l=int(pg.width/0);
pg.strokeWeight(l);
const point = [];
point[0] = [0, 0];
point[1] = [d/2, d];
point[2] = [d, 0];
for(let i=0;i<N+1;i++){
const x = d*i;
for(let j=0;j<N;j++){
const y = d*j;
const dx = (j%2==0) ? d*0.5 : 0;
pg.push();
pg.translate(x-dx, y);
pg.triangle(point[0], point[1], point[2]);
pg.pop();
}
}
pg.pop();
}
ichinoji_tex(pg){
pg.colorMode(HSB);
pg.push();
pg.noFill();
pg.background(this.col[0]);
pg.stroke(this.col[1]);
const N = int(random(2,6)*2);
const d=(pg.width/N);
const l=int(pg.width/30);
pg.strokeWeight(l);
for(let j=0;j<N;j++){
const y = d*j;
const dx = (j%2 == 1) ? -d : 0 ;
for(let i=0;i<N;i++){
const x = 2*d*i;
pg.push();
pg.translate(x+dx, y);
pg.rect(0, 0, 2*d, d);
pg.pop();
}
}
pg.pop();
}
bishi_tex(pg){
pg.colorMode(HSB);
pg.push();
pg.noFill();
pg.background(this.col[0]);
pg.stroke(this.col[1]);
const N = int(random(3,8));
const d=(pg.width/N);
const l=int(pg.width/30);
pg.strokeWeight(l);
for(let j=0;j<N*3;j++){
const y = d*j*1/3;
const dx = (j%2==1) ? d/2 : 0 ;
for(let i=0;i<N+1;i++){
const x = d*i;
pg.push();
pg.translate(x+dx, y);
pg.scale(1, 2/3);
pg.rotate(PI/4);
pg.rect(0, 0, d/sqrt(2));
pg.pop();
}
}
pg.pop();
}
higaki_tex(pg){
pg.colorMode(HSB);
pg.push();
pg.noFill();
pg.background(this.col[0]);
pg.stroke(this.col[1]);
const N = int(random(3,8));
const d=(pg.width/N);
const l=int(pg.width/30);
pg.strokeWeight(l);
pg.rectMode(CENTER);
for(let i=0;i<N;i++){
for(let j=0;j<N;j++){
const dy = (i%2==0) ? 0 : d/sqrt(2) ;
const pos = [d*i*sqrt(2), d*j*sqrt(2)+dy];
const r = (i%2==0) ? -PI/4 : PI/4;
pg.push();
pg.translate(pos);
pg.rotate(r);
pg.rect(0, 0, d, d*2);
pg.pop();
}
}
pg.pop();
}
kuginuki_tex(pg){
let c = [];
pg.colorMode(HSB);
pg.push();
pg.noStroke();
pg.background(c[0]=this.col[0]);
pg.fill(c[1]=this.col[1]);
const N = int(random(3,8));
const d=(pg.width/N);
pg.rectMode(CENTER);
for(let i=0;i<N;i++){
for(let j=0;j<N;j++){
const pos = [d*(i+0.5), d*(j+0.5)];
pg.push();
pg.translate(pos);
pg.rotate(PI/4);
pg.fill(c[1]);
pg.rect(0, 0, d/sqrt(2));
pg.fill(c[0]);
pg.rect(0, 0, d/sqrt(2)/2);
pg.pop();
}
}
pg.pop();
}
}
//save PNG
function keyPressed() {
save("img_" + month() + day() + hour() + minute() + second() + ".png");
}