/* built with Studio Sketchpad:
* https://sketchpad.cc
*
* observe the evolution of this sketch:
* https://studio.sketchpad.cc/sp/pad/view/ro.oH-SXV8ZeGm/rev.3
*
* authors:
* Thomas Hooper
* license (unless otherwise specified):
* creative commons attribution-share alike 3.0 license.
* https://creativecommons.org/licenses/by-sa/3.0/
*/
// Image storage
PImage img;
float scaleSize = 100;
float divisor;
float incX = 0;
float incY = 0;
// Basic setup
void setup() {
size(int(scaleSize), int(scaleSize));
frameRate(25);
}
// Gets called at every frame
void draw() {
// Clear/create new image
img = createImage(width, height, RGB);
incX = max(2, incX);
incY = max(2, incY);
divisor = incX*incY;
incX += (float(mouseX-(width/2))/1000000.);
//incX += (float(mouseX-(width/2))/float(width*10));
if (mouseY > height*0.75) {
incY += float(mouseY)-(height*0.75);
} else if (mouseY < height*0.25) {
incY += float(mouseY)-(height*0.25);
}
//incY += (float(mouseY-(height/2))/float(height));
// Loop through every pixel of the image
for(int x = 0; x < width; x++) {
for(int y = 0; y < height; y++) {
PVector w = warpFunction(float(x), float(y));
PVector f = radialFunction(w.x, w.y);
color c = tileFunction(f.x, f.y);
img.pixels[(x*height)+y] = c;
}
}
// Paints the image to the screen
image(img, 0, 0);
}
PVector warpFunction(float x, float y) {
//x = ((scaleSize/2) - x);
//y = ((scaleSize/2) - y);
x = x - mouseY*scaleSize;
y = y - mouseX*scaleSize;
//y = ((scaleSize/2) - y);
PVector vector = new PVector( x, y );
return vector;
}
PVector radialFunction(float x, float y) {
// float T = float(frameCount);
// PVector vector = new PVector( scaleSize*(y/x)*T, x*y );
//PVector vector = new PVector( 1, sqrt(pow(x,2)+pow(y,2)) );
// x = ((scaleSize/2) - x);
// y = ((scaleSize/2) - y);
//PVector vector = new PVector( 0, sqrt(pow(x,4)+pow(y,4)) );
//PVector vector = new PVector( x*x + y*y, sqrt(x*x+y*y) );
PVector vector = new PVector( sqrt(x*x*x*x+y*y*y*y), sqrt(x*x+y*y) );
return vector;
// R^.5 = sqrt(R) = sqrt(sqrt(x^2+y^2))
}
color tileFunction(float x, float y) {
float p = 50;
float p2 = 100;
float z = (float(frameCount) % p) / p;
float z2 = (float(frameCount) % p2) / p2;
float wave = 0.5+sin(z*(PI*2))/2;
float wave2 = 0.5+sin(z2*(PI*2))/2;
//float T = scaleSize / (((wave * wave2)*200)+100);
//float T = scaleSize / 100000;
//float T = scaleSize/2;
//float T = scaleSize / pow(float(frameCount)/2, 2);
//float T = scaleSize / pow(float(frameCount), 2);
float T = scaleSize / divisor;
boolean bTile = ((0%T) > (T/2)) ^ ((y%T) > (T/2));
int intTile = (bTile) ? 255 : 0;
// x = x / 200;
// y = y / 200;
// boolean bTile2 = ((x%T) > (T/2)) ^ ((y%T) > (T/2));
// int intTile2 = (bTile2) ? 255 : 0;
// float r = ((x%T) / T)*255;
// float g = ((y%T) / T)*255;
//
// return color(g, r, intTile2);
return color(intTile);
}