n <input type='number' id='n_frames' value=1
style='width:160px; font-size:120%; color:#363636;
background-color:silver; text-align:center;'/>
m <input type='number' id='m_frames' value=15
style='width:160px; font-size:120%; color:#363636;
background-color:silver; text-align:center;'/>
run =>>> <input type='button' onclick='draw_curves();' value='update'
style='width:160px; font-size:120%; color:#363636;
background-color:silver; text-align:center;'/><br/><br/>
<svg id='d301' style='background-color:silver;'/>
colors=['#3636ff','#ff3636','#ff36ff',
'#ffff36','#36ff36','#36ffff'];
function subpoint(a,b,m) {
return [Math.floor(m/2)*(a[0]+b[0])/m,
Math.floor(m/2)*(a[1]+b[1])/m]};
function subdivpoly(poly,m,iterations=1) {
var [p1,p2,p3]=poly,points=[];
var centroid=d3.polygonCentroid(poly);
if (iterations===0) {points.push(centroid);}
else {var subset1=[p1,subpoint(p1,p3,m),p2],
subset2=[p2,subpoint(p1,p3,m),p3];
points.push(...subdivpoly(subset1,m,iterations-1));
points.push(...subdivpoly(subset2,m,iterations-1));}
function recursive_curve(len,m,iterations) {
var contour1=[[0,len],[0,0],[len,0]],
contour2=[[len,0],[len,len],[0,len]];
var half1=subdivpoly(contour1,m,iterations),
half2=subdivpoly(contour2,m,iterations);
return [...half1,...half2];};
var m=parseInt(document.getElementById('m_frames').value);
var n=parseInt(document.getElementById('n_frames').value);
var svg=d3.select('#d301').attr('width',s).attr('height',s);
svg.selectAll('path').remove();
svg.selectAll('.curve').data(colors).join('path')
.attr('d',(_,i)=>line(recursive_curve(s,m,i+n))+'z')
.style('fill',d=>d).style('fill-opacity',.02)
.style('stroke',d=>d).style('stroke-width',2); };