shift tiling
@author
int cellNum = 10;
int tempSize = 25;
int rectSize = 2;
void setup(){
size(500, 500);
mousePressed();
}
void mousePressed(){
int[][][] templates = new int[tempSize][tempSize][2];
for(int w = 0; w < tempSize; w++){
for(int h = 0; h < tempSize; h++){
templates[w][h][0] = w;
templates[w][h][1] = h;
}
}
for(int i = 0; i < 5; i++){
int shift1 = int(random(tempSize));
int shift2 = int(random(tempSize));
if(shift1 > shift2){
int s = shift1;
shift1 = shift2;
shift2 = s;
}
int shiftNum = (int(random(10)) + 1) * (random(1) < 0.5 ? -1: 1);
if(random(1) < 0.5){
for(int w = 0; w < tempSize; w++){
for(int h = 0; h < tempSize; h++){
if((shift1 <= templates[w][h][0] && templates[w][h][0] <= shift2) ||
(tempSize + shift1 <= templates[w][h][0] && templates[w][h][0] <= tempSize + shift2) ||
(-tempSize + shift1 <= templates[w][h][0] && templates[w][h][0] <= -tempSize + shift2)){
templates[w][h][1] += shiftNum;
}
}
}
} else {
for(int w = 0; w < tempSize; w++){
for(int h = 0; h < tempSize; h++){
if((shift1 <= templates[w][h][1] && templates[w][h][1] <= shift2) ||
(tempSize + shift1 <= templates[w][h][1] && templates[w][h][1] <= tempSize + shift2) ||
(-tempSize + shift1 <= templates[w][h][1] && templates[w][h][1] <= -tempSize + shift2)){
templates[w][h][0] += shiftNum;
}
}
}
}
}
background(255);
noStroke();
color c1 = color(random(255), random(255), random(255));
color c2 = color(random(255), random(255), random(255));
for(int x = -1; x < cellNum + 1; x++){
for(int y = -1; y < cellNum + 1; y++){
if((x + y) % 2 == 0){
fill(c1);
} else {
fill(c2);
}
pushMatrix();
translate(x * tempSize * rectSize, y * tempSize * rectSize);
for(int w = 0; w < tempSize; w++){
for(int h = 0; h < tempSize; h++){
rect(templates[w][h][0] * rectSize, templates[w][h][1] * rectSize, rectSize, rectSize);
}
}
popMatrix();
}
}
}
void draw(){
}