0x06dc474f…f7cesent to0xa319c382…7f9c·#14,161,637·view on Etherscan
function calculateFeatures(e){function t(e){let t=function(e,t){null==t&&(t=e,e=0);return function(e,t){const r=10**t;return Math.floor(e*r)/r}(c()*(t-e)+e,5)}(e.map(([e,t])=>e).reduce((e,t)=>e+t));for(let[r,o]of e){if(r>=t)return o;t-=r}}function r(e,t){return null==t&&(t=e,e=0),Math.floor(c()*(t-e))+e}const{tokenId:o,hash:n}=e;console.log(n);let l=parseInt(n.slice(0,16),16),s=parseInt(n.slice(16,32),16),i=parseInt(n.slice(32,48),16),a=parseInt(n.slice(48,64),16);function c(){var e=s<<9,t=5*l;return a^=s,s^=i^=l,l^=a,i^=e,a=a<<11|a>>>21,((t=9*(t<<7|t>>>25))>>>0)/4294967296}const u=t([[1,"A"],[1,"B"],[1,"C"],[1,"D"]]),_=t([[1,"Blush"],[1,"Meadow"],[1,"Gold"],[1,"Contra"]]),d=t([[1,"Sparse"],[1,"Moderate"],[1,"Packed"]]),f=(p=.87,x=c(),x<p);var p;const h={Rule:u,Steps:r(7,22),Fullness:d,Colors:_,Curves:f,Breaks:t([[1,!1],[3,!0]])};return console.log("features =",JSON.stringify(h)),h}console.log("Made by Lars Wander https://larswander.com"),console.log("Licensed under CC BY-NC-SA 4.0");const MAX_CHAOS=6;function randperm(e){const t=[...e],r=[];for(;t.length>0;){const[e]=t.splice(Math.floor(random(t.length)),1);r.push(e)}return r}function randchoice(e){return e[randint(e.length)]}function randint(e,t){return null==t&&(t=e,e=0),Math.floor(random(e,t))}function randfloat(e,t){return null==t&&(t=e,e=0),trunc(random()*(t-e)+e,5)}function randbool(e){return random()<e}const H=Math.sqrt(3)*(2/3),W=1;function hex_safe_coords(e,t){let[r,o]=t;return[(r+e.steps_y)%e.steps_y,(o+e.steps_x)%e.steps_x]}function hex_neighbors(e,t){let[r,o]=t;return o%2==0?[hex_safe_coords(e,[r,o+1]),hex_safe_coords(e,[r+1,o]),hex_safe_coords(e,[r,o-1]),hex_safe_coords(e,[r-1,o-1]),hex_safe_coords(e,[r-1,o]),hex_safe_coords(e,[r-1,o+1])]:[hex_safe_coords(e,[r+1,o+1]),hex_safe_coords(e,[r+1,o]),hex_safe_coords(e,[r+1,o-1]),hex_safe_coords(e,[r,o-1]),hex_safe_coords(e,[r-1,o]),hex_safe_coords(e,[r,o+1])]}function hex_coords_to_point(e,t){let[r,o]=t;return[o*W*e.cell_size,(r*H+.5*H*(o%2==0?0:1))*e.cell_size]}function hex_grid(e,t,r){let o=Math.floor(e/r)-1,n=Math.floor(t/r/H),l=[];for(let e=0;e<n;e++){let e=[];for(let t=0;t<o;t++)e.push(!1);l.push(e)}return{width:e,height:t,cell_size:r,steps_x:o,steps_y:n,grid:l,neighbors:hex_neighbors,dirs:6,coords_to_point:hex_coords_to_point,safe_coords:hex_safe_coords}}function grid_occupied(e,t){let[r,o]=e.safe_coords(e,t);return e.grid[r][o]}function grid_occupy(e,t){let[r,o]=e.safe_coords(e,t);e.grid[r][o]=!0}function grid_bigstep(e,t){let[r,o]=e,[n,l]=t;return Math.abs(r-n)+Math.abs(o-l)>2}function circle_walker_before_step(e,t){}function circle_walker_after_step(e,t){}function circle_walker_update_dir(e,t){t.dir+=1,t.dir%=e.dirs}function circle_walker(e,t){return{coords:e,layer:t,dir:t,before_step:circle_walker_before_step,after_step:circle_walker_after_step,update_dir:circle_walker_update_dir,alive:!0,history:[[e]]}}function onedir_walker_before_step(e,t){t.dir=t.onedir}function onedir_walker_after_step(e,t){}function onedir_walker_update_dir(e,t){t.dir+=1,t.dir%=e.dirs}function onedir_walker(e,t){return{coords:e,layer:t,dir:t,onedir:t,before_step:onedir_walker_before_step,after_step:onedir_walker_after_step,update_dir:onedir_walker_update_dir,alive:!0,history:[[e]]}}function cycle_walker_before_step(e,t){t.dir=Math.floor(t.cycle)}function cycle_walker_after_step(e,t){t.cycle-=.333,t.cycle+=e.dirs,t.cycle%=e.dirs}function cycle_walker_update_dir(e,t){t.dir+=1,t.dir%=e.dirs}function cycle_walker(e,t){return{coords:e,layer:t,dir:t,cycle:t,cycle_amount:randfloat(.05,.3),before_step:cycle_walker_before_step,after_step:cycle_walker_after_step,update_dir:cycle_walker_update_dir,alive:!0,history:[[e]]}}function flip_walker_before_step(e,t){t.dir==t.first_dir?t.rotate*=-1:t.update_dir(e,t)}function flip_walker_after_step(e,t){}function flip_walker_update_dir(e,t){t.dir+=t.rotate,t.dir+=e.dirs,t.dir%=e.dirs}function flip_walker(e,t){return{coords:e,layer:t,dir:t,rotate:1,first_dir:t,before_step:flip_walker_before_step,after_step:flip_walker_after_step,update_dir:flip_walker_update_dir,alive:!0,history:[[e]]}}function push_line(e){e.history.push([])}function push_point(e,t){e.history[e.history.length-1].push(t)}function finalize_walker(e){e.alive=!1,push_point(e,e.coords)}function step_walker(e,t){if(!t.alive)return;let r=t.dir,o=t.coords,n=e.neighbors(e,o);t.before_step(e,t);let l=!1;for(let r=0;r<e.dirs;r++){let r=n[t.dir];if(null!=r&&!grid_occupied(e,r)){l=!0,t.coords=r;break}t.update_dir(e,t)}l?(grid_bigstep(o,t.coords)?(push_point(t,o),push_line(t),push_point(t,t.coords)):r!==t.dir&&push_point(t,o),t.after_step(e,t)):finalize_walker(t)}function safe_cycle(e){return randint(e)}function attempt(e,t,r,o){let n=[];const l=()=>safe_cycle(e.steps_y),s=()=>safe_cycle(e.steps_x);let i=l(),a=s(),c=randint(i),u=randint(a),_=Math.ceil(t/(o?2:1)),d=randperm([1,2,3]);d.push(d[0]+3),d.push(d[1]+3),d.push(d[2]+3);let f=0,p=new Set,h=0;const y=()=>{let e=l();for(;e===i;)e=l();a=i,i=e};for(let o=0;o<t;o++){if(f=d[o%d.length],f%=e.dirs,c+=i,u+=a,_>0&&(o+1)%_==0){c+=l(),u+=s(),y()}c+=e.steps_y,c%=e.steps_y,u+=e.steps_x;let t=[c,u%=e.steps_x],w=`${c},${u}`;if(p.has(w)){if((h+=1)>MAX_CHAOS)return;c+=l(),u+=s(),t=[c%=e.steps_y,u%=e.steps_x],w=`${c},${u}`}p.add(w),n.push(r(t,f))}return console.log("disruptions:",h),n}function regular_walkers(e,t,r,o){let n=attempt(e,t,r,o);for(;null==n;)n=attempt(e,t,r,o);return n}function mul(e,t){let[r,o]=e;return[r*t,o*t]}function rot(e,t){let[r,o]=e,n=Math.sin(t),l=Math.cos(t);return[r*l+o*n,r*-n+o*l]}function add(e,t){let[r,o]=e,[n,l]=t;return[r+n,o+l]}function dist_between(e,t){let[r,o]=e,[n,l]=t;return Math.sqrt((r-n)**2+(o-l)**2)}function line_length(e){let t=0;for(let r=0;r<e.length-1;r++)t+=dist_between(e[r],e[r+1]);return t}function lerp_t(e,t,r){let[o,n]=e,[l,s]=t;return add(mul(e,1-r),mul(t,r))}function lerp_d(e,t,r){let o=dist_between(e,t);return 0===o?e:lerp_t(e,t,r/o)}function qbezier(e,t,r){let o=0,n=[],l=dist_between(e,t),s=l>0?1/l:.1;function i(o){let n=1-o;return add(add(mul(e,n*n),mul(t,2*n*o)),mul(r,o*o))}for(n.push(i(o));o<1;)o=Math.min(1,o+s),n.push(i(o));return n}function to_lines(e,t){let r=[];for(let o of t.history){let t=[];for(let r of o){let o=e.coords_to_point(e,r);t.push(o)}0!==t.length&&r.push(t)}return r}function curve_style(e){return function(t){let r=[];r.push(t[0]);for(let o=0;o<t.length-2;o++){let n=t[o],l=t[o+1],s=t[o+2];n=lerp_d(l,n,Math.min(e,dist_between(n,l)/2)),s=lerp_d(l,s,Math.min(e,dist_between(s,l)/2)),Array.prototype.push.apply(r,qbezier(n,l,s))}return r.push(t[t.length-1]),r}}function apply_style(e,t){let r=[];for(let o of e){let e=[];for(let r of o){let o=[];for(let e of r)o.push(t(e));e.push(o)}r.push(e)}return r}function trunc(e,t){let r=10**t;return Math.floor(e*r)/r}function to_svg(e,t){let r=!0,o=[];for(const n of t){let t=document.createElementNS(e,"polyline"),l="";if(1===n.length||2===n.length&&n[0][0]===n[1][0]&&n[0][1]===n[1][1]){const[e,t]=n[0],r=.3,o=8;for(let n=0;n<o;n++){const s=n/o*Math.PI*2,[i,a]=rot([r,0],s);l+=`${trunc(e+i,4)},${trunc(t+a,4)} `}}else for(let[e,t]of n)l+=`${trunc(e,4)},${trunc(t,4)} `;t.setAttribute("points",l),t.setAttribute("class",r?"refill":"no-refill"),o.push(t),r=!1}return o}function parallel(e,t,r){for(let r of t)grid_occupied(e,r.coords)?(r.alive=!1,r.history.length=0):grid_occupy(e,r.coords);for(let o=0;o<r;o++)for(let r of t)r.alive&&(step_walker(e,r),grid_occupy(e,r.coords));for(let e of t)e.alive&&finalize_walker(e)}function walker_factory(e){switch(e){case"A":return circle_walker;case"B":return onedir_walker;case"C":return cycle_walker;case"D":return flip_walker;default:throw`Illegal type ${e}`}}const BACKGROUND="rgb(255,254,254)",COLORS={Meadow:{lines:[{color:"#059e82",name:"viridian"},{color:"#70b03a",name:"sap-green"},{color:"#ff007f",name:"rose"}]},Blush:{lines:[{color:"#003153",name:"prussian-blue"},{color:"#ff007f",name:"rose"},{color:"#00a9ae",name:"cobalt-turquoise"}]},Contra:{lines:[{color:"#880088",name:"quinacridone-violet"},{color:"#de9726",name:"gold-ochre"},{color:"#00a9ae",name:"cobalt-turquoise"}]},Gold:{lines:[{color:"#ff007f",name:"rose"},{color:"#00a9ae",name:"cobalt-turquoise"},{color:"#de9726",name:"gold-ochre"}]}};function layer_(e,t){return e.lines[t%e.lines.length]}function layer_color(e,t){return layer_(e,t).color}function layer_light(e,t){return t>=e.lines.length}function layer_name(e,t){return`${layer_(e,t).name}${layer_light(e,t)?"-faint":""}`}const FULLNESS={Sparse:.75,Moderate:.95,Packed:1.3};function setup(){noCanvas(),noLoop();let e=1200,t="http://www.w3.org/2000/svg",r=document.createElementNS(t,"svg"),o=parseInt(tokenData.hash.slice(0,16),16);randomSeed(o),r.setAttribute("width","100vw"),r.setAttribute("height","100vh"),r.setAttribute("viewBox","0 0 900 "+e);let n=document.createElementNS(t,"path");n.setAttribute("d","M 100 100 M 800 1100"),r.appendChild(n);var l=new URL(window.location.href);let s=calculateFeatures(tokenData),{Rule:i,Steps:a,Fullness:c,Colors:u,Curves:_,Breaks:d}=s;const f=COLORS[u];r.setAttribute("style",`background-color:${BACKGROUND};`);let p=hex_grid(700,1e3,7.2),h=p.dirs,y=Math.ceil(p.steps_x*p.steps_y*FULLNESS[c]/a)+1,w=walker_factory(i);var g=l.searchParams.get("count");y=Math.min(y,null!=g?parseInt(g):y),console.log("line count:",y);let k=regular_walkers(p,y,w,d);var m=l.searchParams.get("steps");parallel(p,k,Math.min(null!=m?parseInt(m):a,a));let b=[];for(let e=0;e<h;e++)b.push([]);for(walker of k){const e=to_lines(p,walker);0!==e.length&&b[walker.layer].push(e)}if(_){b=apply_style(b,curve_style(18))}let x=document.createElementNS(t,"g");x.setAttribute("transform","translate(100,100)");for(let e=0;e<h;e++){let r=b[e],o=document.createElementNS(t,"g");const n=e,l=layer_name(f,n),s=layer_color(f,n),i=layer_light(f,n)?.25:.7;o.setAttribute("class",l),o.setAttribute("id",l),o.setAttribute("style",`fill:none;stroke-width:3.2;stroke-linejoin:round;stroke-linecap:round;stroke-opacity:${i};stroke:${s}`);for(let e of r)for(const r of to_svg(t,e))o.appendChild(r);x.appendChild(o)}r.appendChild(x),document.body.appendChild(r)}