// 'Difference Between Neighbours'
int CellSize = 17;
int CellsAcross = 30;
int CellsDown = 30;
int BrushSize = 2;
int BrushStrength = 35;
int Calm = 130;
float[] CellVal = new float[CellsAcross*CellsDown]; int CellIndex = 0;
void setup() {
colorMode(HSB, 100);
size(560,560)
noStroke();
}
void draw() {
fill(0,0,0);
rect (0,0,50+CellsAcross * CellSize,50+ CellsDown * CellSize);
for (int i = 0; i < CellsAcross; i++) {
for (int j = 0; j < CellsDown; j++) {
CellIndex = (CellIndex+1)%(CellsAcross*CellsDown);
int klimp = round(((CellVal[CellIndex])*2.1)%100);
int nifna = round(((CellVal[CellIndex])*2.2)%100);
int blugg = round(((CellVal[CellIndex])*2.4)%100);
int below = (CellIndex+1)%(CellsAcross*CellsDown);
int above = (CellIndex+(CellsAcross*CellsDown)-1)%(CellsAcross*CellsDown);
int left = (CellIndex+(CellsAcross*CellsDown)-CellsDown)%(CellsAcross*CellsDown);
int right = (CellIndex+CellsDown)%(CellsAcross*CellsDown);
int aboveright = ((CellIndex-1) + CellsDown +(CellsAcross*CellsDown))%(CellsAcross*CellsDown);
int aboveleft = ((CellIndex-1) - CellsDown +(CellsAcross*CellsDown))%(CellsAcross*CellsDown);
int belowright = ((CellIndex+1) + CellsDown +(CellsAcross*CellsDown))%(CellsAcross*CellsDown);
int belowleft = ((CellIndex+1) - CellsDown +(CellsAcross*CellsDown))%(CellsAcross*CellsDown);
float CellVectorX = (CellVal[right]-CellVal[left]);
float CellVectorY = (CellVal[above]-CellVal[below]);
drawCell(i+2, j+2, klimp, nifna, blugg, CellVectorX, CellVectorY);
float NeighbourMix = pow((CellVal[left]*CellVal[right]*CellVal[above]*CellVal[below]*CellVal[belowleft]*CellVal[belowright]*CellVal[aboveleft]*CellVal[aboveright]),0.125);
CellVal[CellIndex] = ((((sqrt(1*CellVal[CellIndex]))*(sqrt(NeighbourMix*1)))/1)+0.5)%Calm;
}
}
}
void drawCell(int x, int y, int klimpyness, int nifnacity, int bluggification, float VectorX, float VectorY) {
fill(klimpyness,80,100);
quad( x*CellSize+CellSize*0.7*(VectorX/pow((sq(VectorX)+sq(VectorY)),0.35)),
y*CellSize+CellSize*0.7*(VectorY/pow((sq(VectorX)+sq(VectorY)),0.35)),
x*CellSize+CellSize*0.2*(VectorY/pow((sq(VectorX)+sq(VectorY)),0.5)),
y*CellSize-CellSize*0.2*(VectorX/pow((sq(VectorX)+sq(VectorY)),0.5)),
x*CellSize-CellSize*0*(VectorX/pow((sq(VectorX)+sq(VectorY)),0.7)),
y*CellSize-CellSize*0*(VectorY/pow((sq(VectorX)+sq(VectorY)),0.7)),
x*CellSize-CellSize*0.2*(VectorY/pow((sq(VectorX)+sq(VectorY)),0.5)),
y*CellSize+CellSize*0.2*(VectorX/pow((sq(VectorX)+sq(VectorY)),0.5))
);
}
void mouseDragged() {
for (int i = 1-BrushSize; i < BrushSize; i++) {
for (int j = 1-BrushSize; j < BrushSize; j++) {
if (mouseButton == LEFT) {
drawCell(mouseX / CellSize + i, mouseY / CellSize + j, 100, 100,100,0,0);
CellVal[getCellIndex (mouseX/CellSize + i,mouseY/CellSize + j)] = 100;
}
else if (mouseButton == RIGHT) {
drawCell(mouseX / CellSize + i, mouseY / CellSize + j, 100, 0,0,0,0);
CellVal[getCellIndex (mouseX/CellSize + i,mouseY/CellSize + j)] = 0;
}
}
}
}
public int getCellIndex(int x, int y) {
return abs(constrain(((x%CellsAcross) * CellsDown + (y%CellsDown)),0,(CellsAcross*CellsDown)));
}