var gB, fullRes, windowRes, droppedImage, droppedImageSizeX, droppedImageSizeY, mainCanvas;
var requiredFrames = 120;
var imageDropped = false;
windowRes = min(windowWidth, windowHeight);
mainCanvas = createCanvas(windowRes, windowRes);
gB = createGraphics(fullRes = 256, fullRes);
gB.translate(fullRes * 0.5, fullRes * 0.5);
textSize(windowRes * 0.05);
text("Drag and drop\nimage here.", windowRes * 0.5, windowRes * 0.5);
var animationProgress = (frameCount / requiredFrames) % 1;
ellipse(windowRes * 0.5, windowRes * 0.5, map(cos(animationProgress * TAU), -1, 1, windowRes * 0.4, windowRes * 0.6));
for (var i = 0; i < 256; i += 1) {
var xPos = random(gB.width);
var yPos = random(gB.height);
var distance = 1 + fullRes * 0.05 * random() * random() * random() * random();
switch (floor(random(5) * random())) {
for (var j = 0; j < distance; j += 1) {
gB.set(xPos + j, yPos, gB.get(xPos, yPos));
for (var j = 0; j < distance; j += 1) {
gB.set(xPos - j, yPos, gB.get(xPos, yPos));
for (var j = 0; j < distance; j += 1) {
gB.set(xPos, yPos + j, gB.get(xPos, yPos));
for (var j = 0; j < distance; j += 1) {
gB.set(xPos, yPos - j, gB.get(xPos, yPos));
for (var j = 0; j < 1 + distance * 0.5; j += 1) {
for (var k = 0; k < 1 + distance * 0.5; k += 1) {
gB.set(xPos + j, yPos + k, gB.get(xPos, yPos));
mainCanvas.drop(function(file) {
droppedImage = loadImage(file.data, function() {
var ratio = droppedImage.width / droppedImage.height;
if (droppedImage.width > droppedImage.height) {
droppedImageSizeX = fullRes;
droppedImageSizeY = fullRes * droppedImage.height / droppedImage.width;
droppedImageSizeY = fullRes;
droppedImageSizeX = fullRes * droppedImage.width / droppedImage.height;
gB.image(droppedImage, 0, 0, droppedImageSizeX, droppedImageSizeY);
saveGif('export', requiredFrames, {
function displayBuffer(buffer) {
image(buffer, windowRes / 2, windowRes / 2, windowRes, windowRes);
function windowResized() {
windowRes = min(windowWidth, windowHeight);
resizeCanvas(windowRes, windowRes);