xxxxxxxxxx
/******************
Code by Vamoss
Original code link:
https://www.openprocessing.org/sketch/743017
Author links:
http://vamoss.com.br
http://twitter.com/vamoss
http://github.com/vamoss
******************/
//original painting by artist Ale Maia e Padua
//https://twitter.com/AleMaiaePadua/status/979842525052751872
let img;
let radius;
let center;
const totalPins = 50;
const steps = 200;
const stepsPerFrame = steps * 0.01;
const totalPoints = 20;
let points = [];
function preload() {
img = loadImage("padua.png");
}
function setup() {
createCanvas(img.width, img.height);
center = createVector(width/2, height/2);
radius = min(center.x, center.y);
background(0);
strokeWeight(2);
for(let i = 0; i < totalPoints; i++){
let point = floor(random(totalPins));
points.push({
step: floor(random(steps)),
in: point,
out: floor(point + totalPins/2) % totalPins
});
}
}
function draw() {
points.forEach(point => {
if(point.step > steps){
point.in = point.out;
point.out = floor(point.out + totalPins / 2 + random(-10, 10)) % totalPins;
point.step = 1;
}
let angleIn = point.in/totalPins*TWO_PI;
let angleOut = point.out/totalPins*TWO_PI;
let xIn = cos(angleIn) * radius + center.x;
let yIn = sin(angleIn) * radius + center.y;
let xOut = cos(angleOut) * radius + center.x;
let yOut = sin(angleOut) * radius + center.y;
for(let iniStep = point.step; point.step <= iniStep+stepsPerFrame; point.step++){
let prevX = lerp(xIn, xOut, (point.step-1)/steps);
let prevY = lerp(yIn, yOut, (point.step-1)/steps);
let curX = lerp(xIn, xOut, point.step/steps);
let curY = lerp(yIn, yOut, point.step/steps);
stroke(0);
line(prevX, prevY-1, curX, curY-1);
stroke(img.get(curX, curY));
line(prevX, prevY, curX, curY);
}
});
}