Skip to content

Instantly share code, notes, and snippets.

@KrabCode
Created January 26, 2024 08:00
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 KrabCode/bec8fb0095e7a9934360996c03b657f2 to your computer and use it in GitHub Desktop.
Save KrabCode/bec8fb0095e7a9934360996c03b657f2 to your computer and use it in GitHub Desktop.
float prevX = 400;
float prevY = 400;
float dir = 0;
float off;
int imgSize = 120;
PImage img;
float bgColor = 30;
void setup(){
fullScreen(P2D);
background(bgColor);
img = getRandomImage();
}
void mousePressed(){
imgSize = floor(random(80, 120));
img = getRandomImage();
off = randomOffset();
}
PImage getRandomImage(){
if(random(1) < 0.2){
return loadImage("pleadthink.png");
}
return loadImage("https://picsum.photos/"+imgSize+"/"+imgSize+".jpg");
}
float randomOffset(){
return random(1000);
}
void draw(){
float t = frameCount * 0.003; // multiplier constant sets the speed of the simulation
float range = width;
float x = -range*0.5+range*(noise(t+off)); // find x using noise
float y = -range*0.5+range*(noise(t+5123.456+off)); // find y in the same way but with an offset so that the result is not the same as for x
float theta = atan2(y - prevY, x - prevX); // angle between previous and current position
dir = lerp(dir, theta, 0.01); // smoothed angle
prevX = x; // remember the now old values for x and y in a global variable
prevY = y;
fade();
blendMode(BLEND);
translate(width*0.5, height*0.5);
int mirrors = 6;
for(int i = 0; i < mirrors; i++){
float mAngle = map(i, 0, mirrors, 0, TAU);
// draw the thing using 2D transformations to achieve a nice centered rotation
pushMatrix();
rotate(mAngle);
translate(x,y);
rotate(dir);
imageMode(CENTER);
if(img.width != imgSize){
scale(2);
}
image(img, 0, 0);
popMatrix();
}
}
void fade(){
if(frameCount % 30 == 0){
blendMode(SUBTRACT);
noStroke();
fill(1);
rect(0,0,width,height);
}
blendMode(LIGHTEST);
fill(bgColor);
rect(0,0,width,height);
}
@KrabCode
Copy link
Author

pleadthink

@KrabCode
Copy link
Author

Screenshot_20240125-194203

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment