xxxxxxxxxx
149
let allpaths;
let trajs = [];
let timept;
function setup() {
createCanvas(600, 800);
for (let path of pathdata) {
centroids.push(centroid(path));
areas.push(area(path));
}
allpaths = [pathdata];
for (let idx = 0; idx < 600; ++idx) {
let prevpaths = allpaths[allpaths.length - 1];
let npaths = [];
for (let jdx = 0; jdx < prevpaths.length; ++jdx) {
npaths.push(getNewPath(prevpaths, jdx,map(idx,0,500,0.01,0.9)));
}
allpaths.push(npaths);
}
randomTrajectories();
timept = 0;
}
function randomTrajectories()
{
trajs = [];
for (let idx = 0; idx < pathdata.length; ++idx ) {
const d = random(500);
const ang = random(TWO_PI );
const rang = random(-2*TWO_PI,2*TWO_PI);
trajs.push( [d*cos(ang), d*sin(ang), rang]);
}
}
function centroid(pts) {
let xc = 0;
let yc = 0;
for (let p of pts) {
xc += p[0];
yc += p[1];
}
return [xc / pts.length, yc / pts.length];
}
function area(pts) {
let total = 0.0;
for (let idx = 0; idx < pts.length; ++idx) {
const a = pts[idx];
const b = pts[(idx + 1) % pts.length];
total += a[0] * b[1] - a[1] * b[0];
}
return 0.5 * abs(total);
}
function movePoly(pts, dx, dy) {
for (let p of pts) {
p[0] += dx;
p[1] += dy;
}
}
function scalePoly(pts, a) {
for (let p of pts) {
p[0] *= a;
p[1] *= a;
}
}
function mcf(pts, amount) {
let npts = [];
for (let idx = 0; idx < pts.length; ++idx) {
const a = pts[(idx + pts.length - 1) % pts.length];
const b = pts[idx];
const c = pts[(idx + 1) % pts.length];
const m = [0.5 * (a[0] + c[0]), 0.5 * (a[1] + c[1])];
npts.push([lerp(b[0], m[0], amount), lerp(b[1], m[1], amount)]);
}
return npts;
}
function getNewPath(paths, idx, amount) {
let path = paths[idx];
path = mcf(path, amount);
const c = centroid(path);
const a = area(path);
movePoly(path, -c[0], -c[1]);
scalePoly(path, areas[idx] / a);
movePoly(path, centroids[idx][0], centroids[idx][1]);
return path;
}
function draw() {
background(255);
noStroke();
fill(0);
const l = allpaths.length;
if( timept == allpaths.length + 100 ) {
timept = 0;
randomTrajectories();
}
const fc = min( timept, allpaths.length - 1 );
const t = ease( fc / allpaths.length );
const paths = allpaths[l - 1 - fc];
for (let idx = 0; idx < paths.length; ++idx ) {
const path = paths[idx];
push();
translate( lerp(trajs[idx][0],0,t), lerp(trajs[idx][1],0,t) );
translate( centroids[idx][0], -centroids[idx][1] );
rotate( lerp( trajs[idx][2], 0, t ) );
translate( -centroids[idx][0], centroids[idx][1] );
beginShape();
for (let p of path) {
vertex(p[0], -p[1]);
}
endShape(CLOSE);
pop();
}
++timept;
}
function ease( t )
{
return t * t * (3.0 - 2.0 * t);
}
function keyPressed() {
console.log(frameCount);
}
const centroids = [];
const areas = [];
const pathdata = [[[207.871, -431.691], [206.602, -431.422], [202.695, -431.113], [197.863, -430.973], [193.23, -430.223], [189.664, -428.609], [188.668, -427.832], [187.176, -427.699], [182.555, -428.977], [176.23, -431.648], [169.902, -433.113], [164.934, -431.684], [163.781, -430.648], [161.684, -429.805], [155.918, -425.977], [149.348, -419.211], [144.496, -411.148], [141.805, -402.602], [141.707, -394.371], [144.633, -387.262], [151.023, -382.082], [158.711, -379.801], [161.313, -379.633], [163.367, -379.957], [169.766, -379.535], [178.0, -377.746], [186.047, -376.117], [192.07, -376.023], [193.945, -376.508], [197.414, -378.059], [208.766, -380.629], [224.563, -381.676], [240.668, -381.617], [252.504, -381.949], [256.402, -382.434], [258.348, -381.617], [264.629, -380.223], [272.977, -379.832], [281.309, -380.391], [289.488, -381.051], [297.371, -380.945], [304.824, -379.223], [311.711, -375.02], [316.637, -369.543], [317.891, -367.484], [318.797, -369.004], [322.488, -372.988], [328.301, -376.82], [335.004, -379.461], [342.293, -381.395], [349.844, -383.105], [357.348, -385.078], [364.484, -387.801], [369.465, -390.59], [370.945, -391.754], [373.473, -393.055], [382.301, -394.555], [394.266, -393.148], [406.301, -389.641], [414.945, -386.863], [417.875, -386.125], [419.844, -384.949], [426.664, -382.945], [437.0, -382.133], [447.297, -383.324], [453.934, -385.18], [455.973, -386.164], [455.992, -387.523], [454.766, -391.621], [451.672, -395.531], [447.762, -398.402], [444.113, -400.742], [441.801, -403.07], [441.895, -405.895], [445.469, -409.727], [451.5, -413.852], [453.598, -415.078], [453.836, -415.746], [453.941, -417.984], [452.492, -419.254], [449.734, -419.391], [446.16, -418.902], [442.254, -418.293], [438.5, -418.07], [435.391, -418.742], [433.68, -420.199], [433.418, -420.816], [432.281, -421.672], [429.199, -424.664], [426.539, -428.383], [424.867, -431.965], [423.621, -435.406], [422.227, -438.703], [420.125, -441.859], [416.75, -444.867], [412.887, -447.129], [411.531, -447.727], [410.488, -448.891], [405.719, -450.918], [399.203, -450.844], [392.582, -450.688], [387.598, -452.508], [386.445, -453.637], [385.395, -453.895], [381.938, -453.449], [377.387, -451.766], [372.691, -450.27], [368.855, -450.234], [367.734, -450.648], [365.57, -449.582], [359.465, -445.625], [353.348, -440.262], [348.438, -434.844], [343.77, -429.648], [338.398, -424.961], [331.363, -421.066], [321.711, -418.242], [311.805, -416.926], [308.492, -416.777], [307.258, -416.551], [303.332, -417.102], [300.34, -419.898], [298.754, -424.297], [297.82, -429.438], [296.773, -434.453], [294.859, -438.477], [291.316, -440.648], [286.785, -440.512], [285.391, -440.098], [284.02, -439.574], [279.512, -439.043], [275.34, -440.773], [272.059, -444.598], [268.852, -449.816], [264.891, -455.734], [259.367, -461.66], [251.453, -466.898], [243.188, -470.109], [240.34, -470.754], [239.723, -470.695], [237.914, -470.082], [236.43, -468.789], [236.508, -467.18], [238.145, -465.828], [238.77, -465.563], [239.82, -465.242], [242.777, -463.633], [245.367, -460.949], [246.617, -457.828], [246.605, -454.586], [245.414, -451.543], [243.121, -449.012], [239.801, -447.313], [236.598, -446.738], [235.539, -446.77], [234.328, -446.953], [230.684, -447.367], [224.77, -447.762], [218.531, -447.695], [212.691, -446.918], [207.98, -445.18], [205.121, -442.23], [204.84, -437.816], [206.906, -433.074], [207.871, -431.691]], [[250.57, -216.465], [249.629, -215.797], [246.938, -213.629], [242.844, -210.043], [238.348, -205.867], [233.516, -201.277], [228.402, -196.438], [223.074, -191.527], [217.586, -186.711], [212.0, -182.156], [206.383, -178.039], [200.785, -174.523], [195.277, -171.789], [189.918, -169.996], [184.766, -169.316], [179.879, -169.926], [175.324, -171.992], [172.063, -174.641], [171.164, -175.684], [169.512, -175.527], [164.402, -176.695], [157.492, -180.438], [150.672, -186.113], [144.176, -192.914], [138.254, -200.035], [133.145, -206.676], [129.086, -212.035], [127.086, -214.566], [126.32, -215.305], [126.031, -216.457], [124.785, -219.82], [122.332, -225.188], [119.191, -231.051], [115.586, -237.063], [111.742, -242.879], [107.891, -248.152], [104.258, -252.531], [101.926, -254.957], [101.07, -255.668], [100.422, -254.953], [99.332, -252.043], [98.6797, -246.121], [99.3203, -238.016], [101.473, -227.844], [105.348, -215.719], [111.16, -201.766], [119.129, -186.098], [126.746, -173.063], [129.469, -168.836], [132.422, -164.238], [142.93, -151.512], [159.48, -135.676], [178.16, -121.457], [197.992, -108.98], [218.012, -98.3711], [237.246, -89.7539], [254.727, -83.2539], [265.75, -79.8828], [269.484, -79.0039], [272.895, -78.1953], [283.469, -77.1914], [298.82, -77.6172], [314.844, -79.8164], [330.84, -83.3164], [346.117, -87.6445], [359.977, -92.3359], [371.73, -96.918], [378.477, -99.8516], [380.684, -100.926], [382.656, -101.883], [388.445, -105.043], [396.949, -110.164], [405.969, -116.109], [415.273, -122.707], [424.645, -129.777], [433.852, -137.145], [442.672, -144.633], [448.855, -150.172], [450.875, -152.07], [452.852, -153.926], [458.621, -159.676], [466.148, -167.883], [473.363, -176.797], [480.152, -186.543], [486.418, -197.23], [492.059, -208.973], [496.969, -221.895], [500.176, -232.516], [501.051, -236.105], [501.969, -239.883], [503.824, -251.449], [505.055, -267.199], [504.996, -282.602], [503.902, -296.895], [502.023, -309.324], [499.613, -319.141], [496.926, -325.582], [494.895, -327.898], [494.219, -327.898], [494.016, -327.898], [493.41, -326.48], [493.441, -322.449], [494.012, -316.125], [494.828, -307.828], [495.605, -297.883], [496.039, -286.613], [495.848, -274.34], [494.73, -261.387], [492.398, -248.078], [488.555, -234.73], [482.91, -221.676], [475.172, -209.227], [465.043, -197.715], [452.234, -187.457], [436.453, -178.777], [422.266, -173.34], [417.406, -172.004], [416.285, -171.914], [412.855, -172.434], [406.57, -174.234], [399.016, -177.336], [390.66, -181.656], [381.973, -187.121], [373.43, -193.648], [365.496, -201.164], [360.188, -207.367], [358.645, -209.59], [357.773, -210.84], [354.797, -214.34], [349.891, -219.016], [344.0, -223.441], [337.207, -227.438], [329.594, -230.824], [321.242, -233.418], [312.234, -235.043], [305.043, -235.555], [302.652, -235.52], [299.035, -235.461], [288.207, -234.195], [275.516, -230.656], [263.367, -224.785], [253.68, -218.668], [250.57, -216.465]], [[155.355, -620.547], [157.398, -623.719], [163.133, -633.492], [168.848, -644.297], [173.469, -653.457], [177.965, -661.465], [183.316, -668.816], [190.492, -676.012], [200.465, -683.543], [210.703, -689.941], [214.211, -691.91], [216.324, -692.602], [225.559, -697.922], [233.203, -705.121], [234.527, -706.75], [236.383, -708.676], [242.805, -713.641], [252.07, -718.434], [262.027, -721.266], [272.387, -722.27], [282.855, -721.578], [293.145, -719.32], [302.957, -715.637], [309.848, -712.063], [312.004, -710.656], [314.625, -710.98], [322.406, -712.707], [332.949, -715.738], [343.535, -718.926], [351.41, -720.961], [354.07, -721.449], [355.973, -721.691], [361.734, -722.125], [369.496, -722.832], [377.023, -724.457], [382.422, -726.797], [383.988, -727.91], [384.633, -729.398], [384.105, -734.953], [378.953, -741.262], [369.922, -746.75], [358.383, -751.344], [345.727, -754.961], [333.332, -757.52], [322.582, -758.945], [316.773, -759.297], [314.859, -759.16], [311.313, -759.277], [300.641, -758.762], [286.754, -756.691], [273.25, -753.074], [260.172, -748.031], [247.578, -741.684], [235.516, -734.156], [224.035, -725.563], [213.188, -716.031], [203.027, -705.68], [193.602, -694.633], [184.965, -683.012], [177.164, -670.938], [170.25, -658.531], [164.277, -645.918], [159.297, -633.215], [156.219, -623.746], [155.355, -620.547]], [[209.977, -655.84], [210.918, -654.125], [213.617, -648.91], [218.02, -640.418], [223.109, -631.191], [228.816, -622.059], [235.063, -613.844], [241.777, -607.379], [248.883, -603.488], [254.543, -602.656], [256.309, -603.004], [259.023, -603.813], [272.625, -604.676], [286.145, -602.461], [288.82, -601.734], [291.918, -601.383], [301.355, -601.582], [313.773, -602.82], [326.246, -603.672], [335.852, -603.082], [338.938, -602.371], [340.043, -602.207], [343.441, -602.223], [348.258, -602.832], [353.246, -603.844], [358.258, -604.906], [363.148, -605.664], [367.77, -605.77], [371.977, -604.871], [374.852, -603.324], [375.629, -602.613], [376.543, -601.73], [380.004, -599.836], [386.379, -597.43], [392.875, -596.313], [396.742, -596.734], [397.613, -597.414], [397.875, -598.52], [399.234, -601.711], [402.105, -607.746], [405.488, -614.77], [408.656, -622.035], [410.887, -628.793], [411.441, -634.293], [409.602, -637.789], [405.828, -638.688], [404.633, -638.535], [402.871, -637.363], [397.645, -633.773], [392.305, -629.969], [388.336, -627.031], [385.457, -624.867], [383.391, -623.391], [381.867, -622.508], [380.598, -622.137], [379.316, -622.176], [377.734, -622.543], [375.586, -623.148], [372.586, -623.898], [368.461, -624.707], [362.934, -625.48], [355.723, -626.133], [346.555, -626.57], [338.004, -626.715], [335.156, -626.707], [333.098, -627.293], [326.707, -628.305], [318.152, -628.598], [309.551, -628.027], [300.965, -627.039], [292.441, -626.074], [284.047, -625.578], [275.84, -625.992], [269.801, -627.121], [267.875, -627.762], [267.406, -628.301], [265.504, -629.488], [263.102, -629.645], [260.684, -628.773], [258.27, -627.422], [255.875, -626.129], [253.527, -625.449], [251.238, -625.922], [249.453, -627.469], [249.031, -628.098], [248.434, -628.766], [246.867, -630.977], [244.75, -634.602], [242.66, -638.773], [240.582, -643.305], [238.492, -648.004], [236.379, -652.676], [234.223, -657.133], [232.008, -661.18], [229.711, -664.625], [227.32, -667.277], [224.816, -668.949], [222.18, -669.445], [219.395, -668.574], [216.445, -666.141], [213.309, -661.961], [210.73, -657.406], [209.977, -655.84]], [[332.711, -679.09], [329.098, -677.898], [317.613, -676.309], [303.078, -677.133], [288.629, -679.91], [277.516, -682.348], [273.785, -683.016], [271.27, -682.805], [263.77, -681.723], [256.191, -679.707], [251.082, -676.938], [248.461, -673.395], [248.359, -669.055], [250.801, -663.898], [255.813, -657.895], [261.445, -652.652], [263.426, -651.031], [264.703, -649.996], [269.672, -648.285], [276.508, -648.469], [283.508, -650.121], [288.535, -651.469], [290.238, -651.781], [295.066, -652.074], [319.496, -651.652], [344.0, -650.566], [348.871, -650.531], [349.898, -650.613], [352.84, -652.738], [354.605, -657.41], [355.172, -662.957], [355.371, -666.598], [355.563, -667.793], [355.422, -668.52], [354.359, -670.59], [352.152, -672.664], [349.203, -674.18], [345.777, -675.305], [342.148, -676.191], [338.582, -677.008], [335.348, -677.922], [333.324, -678.723], [332.711, -679.09]], [[319.414, -587.32], [317.438, -587.18], [311.574, -585.977], [307.297, -583.484], [305.645, -580.02], [305.695, -575.742], [306.512, -570.828], [307.172, -565.445], [306.742, -559.766], [305.133, -555.258], [304.293, -553.957], [303.594, -552.828], [300.18, -550.262], [294.262, -548.063], [287.707, -546.996], [283.195, -546.699], [281.695, -546.688], [280.848, -546.836], [278.156, -546.41], [274.438, -544.707], [270.953, -542.0], [268.121, -538.723], [266.363, -535.313], [266.094, -532.195], [267.738, -529.805], [270.699, -528.672], [271.715, -528.574], [275.238, -528.773], [285.719, -531.184], [299.59, -535.563], [313.758, -538.953], [325.055, -539.332], [328.648, -538.602], [329.715, -538.477], [332.953, -538.418], [335.684, -539.02], [337.203, -540.301], [337.875, -542.16], [338.063, -544.496], [338.137, -547.211], [338.457, -550.203], [339.074, -552.613], [339.395, -553.371], [340.668, -554.313], [343.684, -558.242], [344.93, -563.711], [343.688, -569.395], [340.504, -574.898], [335.93, -579.832], [330.523, -583.805], [324.832, -586.434], [320.762, -587.348], [319.414, -587.32]], [[370.832, -493.348], [371.754, -493.488], [374.375, -494.855], [378.805, -498.254], [383.902, -503.25], [389.445, -509.555], [395.215, -516.875], [400.988, -524.93], [406.551, -533.426], [411.68, -542.07], [416.156, -550.578], [419.758, -558.66], [422.266, -566.023], [423.457, -572.387], [423.117, -577.449], [421.023, -580.934], [416.957, -582.543], [412.207, -582.344], [410.695, -581.992], [409.488, -580.539], [406.566, -575.598], [402.215, -567.016], [397.539, -557.488], [392.449, -548.266], [386.848, -540.598], [380.633, -535.734], [373.715, -534.922], [367.594, -537.934], [365.996, -539.418], [365.688, -539.898], [364.785, -541.359], [363.445, -543.082], [361.715, -544.219], [359.914, -544.492], [359.344, -544.41], [358.805, -544.285], [357.23, -543.734], [355.766, -542.848], [354.898, -541.785], [354.563, -540.586], [354.703, -539.281], [355.254, -537.914], [356.164, -536.516], [357.371, -535.125], [358.813, -533.773], [360.438, -532.504], [362.176, -531.352], [363.977, -530.348], [365.777, -529.531], [367.523, -528.941], [369.148, -528.609], [370.238, -528.543], [370.598, -528.578], [372.094, -528.383], [376.453, -526.781], [378.848, -523.66], [378.68, -519.504], [376.844, -514.602], [374.242, -509.246], [371.773, -503.723], [370.336, -498.328], [370.406, -494.477], [370.832, -493.348]], [[266.379, -512.418], [264.977, -514.152], [261.289, -519.777], [255.805, -529.137], [249.93, -539.566], [243.664, -550.137], [237.012, -559.914], [229.969, -567.965], [222.543, -573.363], [216.664, -575.246], [214.734, -575.176], [214.043, -573.988], [213.379, -569.609], [214.469, -562.727], [217.469, -555.063], [221.84, -547.148], [227.051, -539.523], [232.559, -532.723], [237.828, -527.281], [241.117, -524.48], [242.328, -523.734], [243.059, -523.363], [245.047, -521.82], [248.156, -518.953], [251.5, -515.684], [254.922, -512.555], [258.277, -510.113], [261.402, -508.914], [264.156, -509.496], [266.012, -511.602], [266.379, -512.418]], [[167.324, -535.469], [166.586, -535.594], [164.414, -536.16], [161.23, -537.113], [157.961, -538.035], [154.801, -538.637], [151.941, -538.629], [149.57, -537.723], [147.875, -535.629], [147.121, -532.961], [147.059, -532.063], [147.012, -531.0], [146.805, -527.816], [146.543, -522.555], [146.539, -516.938], [147.063, -511.637], [148.371, -507.313], [150.738, -504.633], [154.43, -504.258], [158.52, -506.027], [159.715, -506.863], [160.379, -507.68], [162.461, -510.059], [166.207, -514.391], [170.195, -519.344], [173.672, -524.406], [175.879, -529.063], [176.059, -532.801], [173.457, -535.109], [168.832, -535.613], [167.324, -535.469]], [[122.301, -247.977], [122.484, -249.012], [122.777, -252.168], [123.199, -258.898], [123.547, -267.719], [123.809, -278.18], [123.961, -289.84], [123.988, -302.246], [123.871, -314.953], [123.594, -327.512], [123.141, -339.48], [122.492, -350.41], [121.629, -359.848], [120.539, -367.355], [119.195, -372.477], [117.59, -374.773], [115.699, -373.793], [113.934, -370.305], [113.512, -369.09], [111.684, -365.492], [107.242, -354.18], [103.875, -340.852], [102.219, -328.285], [101.387, -318.816], [101.074, -315.664], [100.898, -313.922], [100.348, -308.703], [99.5586, -300.965], [98.8398, -292.762], [98.332, -284.398], [98.1641, -276.195], [98.4727, -268.465], [99.3945, -261.516], [100.504, -257.07], [101.07, -255.668], [101.578, -254.402], [103.473, -250.75], [106.363, -246.535], [109.535, -243.238], [112.777, -241.07], [115.883, -240.25], [118.645, -240.984], [120.852, -243.488], [122.094, -246.824], [122.301, -247.977]], [[119.852, -410.793], [119.992, -412.477], [119.992, -417.578], [119.137, -421.82], [117.492, -424.238], [115.277, -425.551], [112.691, -426.477], [109.949, -427.734], [107.258, -430.047], [105.293, -433.051], [104.832, -434.133], [104.324, -435.016], [102.535, -437.523], [100.398, -439.582], [98.4805, -440.445], [96.8359, -440.266], [95.5234, -439.195], [94.6055, -437.379], [94.1367, -434.961], [94.1797, -432.098], [94.7891, -428.93], [96.0234, -425.613], [97.9414, -422.289], [100.605, -419.109], [104.066, -416.219], [108.391, -413.773], [113.633, -411.914], [118.285, -410.957], [119.852, -410.793]], [[499.145, -431.203], [499.121, -430.852], [499.059, -429.793], [498.977, -428.137], [498.922, -426.297], [498.902, -424.34], [498.941, -422.336], [499.051, -420.348], [499.254, -418.453], [499.559, -416.711], [499.988, -415.191], [500.559, -413.961], [501.285, -413.09], [502.188, -412.645], [503.277, -412.691], [504.578, -413.301], [506.102, -414.539], [507.453, -415.965], [507.867, -416.473], [508.359, -417.344], [509.488, -420.168], [510.414, -424.125], [510.73, -428.207], [510.527, -432.277], [509.887, -436.199], [508.902, -439.844], [507.66, -443.07], [506.242, -445.75], [504.738, -447.742], [503.238, -448.918], [501.824, -449.137], [500.59, -448.266], [499.613, -446.172], [498.992, -442.719], [498.805, -437.773], [499.004, -432.84], [499.145, -431.203]], [[81.8516, -388.063], [82.1133, -387.121], [83.4219, -384.441], [85.5352, -382.117], [87.9375, -381.008], [90.3594, -381.016], [92.543, -382.051], [94.2266, -384.027], [95.1484, -386.855], [95.2031, -389.566], [95.0508, -390.441], [94.8555, -391.355], [93.9023, -394.031], [92.3906, -396.234], [90.625, -397.188], [88.7148, -397.027], [86.7695, -395.898], [84.9023, -393.934], [83.2266, -391.277], [82.1328, -388.883], [81.8516, -388.063]], [[513.289, -390.715], [512.383, -389.848], [510.117, -386.785], [509.363, -383.27], [511.023, -379.992], [514.008, -377.461], [515.109, -376.793], [514.945, -378.031], [514.207, -383.688], [513.457, -389.43], [513.289, -390.715]]]