memoscan
← all memos

Memo 0xb2088102…0a7e63 on Ethereum

function genExpression(){let e="$";for(p_var=0;e.includes("$");)R.rd()<p_var?(v=vars[floor(vars.length*R.rd())],e=e.replace("$",v)):(f=funcs[floor(funcs.length*R.rd())],e=e.replace("$",f)),p_var+=p_var_inc;return e}function updateExpressions(e){"x"==e?f_string=genExpression():"y"==e?f_string2=genExpression():"z"==e?f_string3=genExpression():"theta"==e?f_string4=genExpression:(f_string=genExpression(),f_string2=genExpression(),f_string3=genExpression(),f_string4=genExpression())}function mapPts(){let out_pts=[];for(let i=0;i<init_pts.length;i++){x=init_pts[i][0],y=init_pts[i][1],z=init_pts[i][2],theta=theta_modulo>1?map(i%theta_modulo,0,theta_modulo-1,-1,1):0;for(let j=0;j<trail_length;j++)nx=eval(f_string),ny=eval(f_string2),nz=eval(f_string3),ntheta=eval(f_string4),x=nx,y=ny,z=nz,theta=ntheta,out_pts.push([x,y,z,theta])}x_min=out_pts[0][0],x_max=out_pts[0][0],y_min=out_pts[0][1],y_max=out_pts[0][1],z_min=out_pts[0][2],z_max=out_pts[0][2],theta_min=out_pts[0][3],theta_max=out_pts[0][3];for(let i=1;i<out_pts.length;i++)out_pts[i][0]<x_min&&(x_min=out_pts[i][0]),out_pts[i][0]>x_max&&(x_max=out_pts[i][0]),out_pts[i][1]<y_min&&(y_min=out_pts[i][1]),out_pts[i][1]>y_max&&(y_max=out_pts[i][1]),out_pts[i][2]<z_min&&(z_min=out_pts[i][2]),out_pts[i][2]>z_max&&(z_max=out_pts[i][2]),out_pts[i][3]<theta_min&&(theta_min=out_pts[i][3]),out_pts[i][3]>theta_max&&(theta_max=out_pts[i][3]);redo=!1,x_min==x_max&&(x_min-=1,x_max+=1,redo=!0),y_min==y_max&&(y_min-=1,y_max+=1,redo=!0),z_min==z_max&&(z_min-=1,z_max+=1,redo=!0),theta_min==theta_max&&(theta_min-=1,theta_max+=1,redo=!0),theta_min==theta_max&&(theta_min-=1,theta_max+=1,redo=!0);for(let i=0;i<out_pts.length;i++)nz=map(z=out_pts[i][2],z_min,z_max,0,1),out_pts[i][2]=nz,theta=map(theta=out_pts[i][3],theta_min,theta_max,0,3*TWO_PI),out_pts[i][3]=theta;return redo?(updateExpressions(),mapPts()):out_pts}function fitPts(e,$=!1){x_min=e[0][0],x_max=e[0][0],y_min=e[0][1],y_max=e[0][1],z_min=e[0][2],z_max=e[0][2];for(let t=1;t<e.length;t++)e[t][0]<x_min&&(x_min=e[t][0]),e[t][0]>x_max&&(x_max=e[t][0]),e[t][1]<y_min&&(y_min=e[t][1]),e[t][1]>y_max&&(y_max=e[t][1]),e[t][2]<z_min&&(z_min=e[t][2]),e[t][2]>z_max&&(z_max=e[t][2]);redo=!1,x_min==x_max&&(x_min-=1,x_max+=1,redo=!0),y_min==y_max&&(y_min-=1,y_max+=1,redo=!0),z_min==z_max&&(z_min-=1,z_max+=1,redo=!0);for(let r=0;r<e.length;r++)x=e[r][0],y=e[r][1],z=e[r][2],theta=e[r][3],layer_num=e[r][4],nx=map(x,x_min,x_max,margin,aspect_ratio-margin),ny=map(y,y_min,y_max,margin,1-margin),e[r]=[nx,ny,z,theta,layer_num];return e.sort((e,$)=>e[2]-$[2]),e}function bufferPts(e,$=1){let t=[];ceil(1/buffer),pt_dict={},pt_index=0;for(let r=0;r<e.length;r++){for(is_valid=!1,skip_pt=!1,x=e[r][0],y=e[r][1],z=e[r][2],theta=e[r][3],layer_num=e[r][4];!is_valid;){local_pts=[],is_valid=!0,grid_x=floor(x/buffer),grid_y=floor(y/buffer);for(let s=grid_x-1;s<grid_x+2;s++)for(let _=grid_y-1;_<grid_y+2;_++)if([s,_]in pt_dict)for(let n=0;n<pt_dict[[s,_]].length;n++)local_pts.push(pt_dict[[s,_]][n]);for(let o=0;o<local_pts.length;o++)len(x,y,x2=local_pts[o][0],y2=local_pts[o][1])<buffer&&($||t[local_pts[o][2]][5]>=max_growth?(dx=x-.5,dy=y-.5,is_valid=!1,x+=buffer*cos(theta),y+=buffer*sin(theta)):(skip_pt=!0,t[local_pts[o][2]][5]++))}t.push([x,y,z,theta,layer_num,1]),!skip_pt&&([grid_x=floor(x/buffer),grid_y=floor(y/buffer)]in pt_dict?pt_dict[[grid_x,grid_y]].push([x,y,pt_index]):pt_dict[[grid_x,grid_y]]=[[x,y,pt_index]],pt_index++)}min_x=margin,max_x=aspect_ratio-margin,min_y=margin,max_y=1-margin;for(let l=0;l<t.length;l++)t[l][0]<min_x&&(min_x=t[l][0]),t[l][0]>max_x&&(max_x=t[l][0]),t[l][1]<min_y&&(min_y=t[l][1]),t[l][1]>max_y&&(max_y=t[l][1]);for(let h=0;h<t.length;h++)t[h][0]=map(t[h][0],min_x,max_x,margin,aspect_ratio-margin),t[h][1]=map(t[h][1],min_y,max_y,margin,1-margin);return t.sort((e,$)=>0*e[0]+$[2]-0*$[0]-e[2]),t}function spreadPts(e,$=!1){col_count=[],row_count=[],layer_count=[];for(let t=0;t<grid_size+1;t++)col_count[t]=0,row_count[t]=0,layer_count[t]=0;for(let r=0;r<e.length;r++)x=e[r][0]/aspect_ratio,y=e[r][1],z=e[r][2],xg=floor(x*grid_size),yg=floor(y*grid_size),zg=floor(z*grid_size),col_count[xg]++,row_count[yg]++,layer_count[zg]++;col_ends=[margin];for(let s=0;s<col_count.length;s++)col_ends[s+1]=col_count[s]/e.length*(aspect_ratio-2*margin)+col_ends[s];row_ends=[margin];for(let _=0;_<row_count.length;_++)row_ends[_+1]=row_count[_]/e.length*(1-2*margin)+row_ends[_];layer_ends=[0];for(let n=0;n<layer_count.length;n++)layer_ends[n+1]=layer_count[n]/e.length+layer_ends[n];let o=[];for(let l=0;l<e.length;l++)x=e[l][0]/aspect_ratio,y=e[l][1],z=e[l][2],xg=floor(x*grid_size),yg=floor(y*grid_size),zg=floor(z*grid_size),nx=map(x,xg/grid_size,(xg+1)/grid_size,col_ends[xg],col_ends[xg+1]),ny=map(y,yg/grid_size,(yg+1)/grid_size,row_ends[yg],row_ends[yg+1]),nz=map(z,zg/grid_size,(zg+1)/grid_size,layer_ends[zg],layer_ends[zg+1]),$?o.push([nx,ny,nz,e[l][3],e[l][4],e[l][5]]):o.push([nx,ny,e[l][2],e[l][3],e[l][4],e[l][5]]);return o}function spreadPtsSimple(e,$=!1){col_count=[],row_count=[],layer_count=[];for(let t=0;t<grid_size+1;t++)col_count[t]=0,row_count[t]=0,layer_count[t]=0;for(let r=0;r<e.length;r++)x=e[r][0]/aspect_ratio,y=e[r][1],z=e[r][2],xg=floor(x*grid_size),yg=floor(y*grid_size),zg=floor(z*grid_size),col_count[xg]++,row_count[yg]++,layer_count[zg]++;col_ends=[0],non_zero_cols=0;for(let s=0;s<col_count.length;s++)col_count[s]>0?(col_ends[s+1]=col_ends[s]+1,non_zero_cols++):col_ends[s+1]=col_ends[s];row_ends=[0],non_zero_rows=0;for(let _=0;_<row_count.length;_++)row_count[_]>0?(row_ends[_+1]=row_ends[_]+1,non_zero_rows++):row_ends[_+1]=row_ends[_];layer_ends=[0];for(let n=0;n<layer_count.length;n++);let o=[];for(let l=0;l<e.length;l++)x=e[l][0]/aspect_ratio,y=e[l][1],z=e[l][2],xg=floor(x*grid_size),yg=floor(y*grid_size),zg=floor(z*grid_size),col1=map(col_ends[xg],0,non_zero_cols,margin,aspect_ratio-margin),col2=map(col_ends[xg+1],0,non_zero_cols,margin,aspect_ratio-margin),nx=map(x,xg/grid_size,(xg+1)/grid_size,col1,col2),row1=map(row_ends[yg],0,non_zero_rows,margin,1-margin),row2=map(row_ends[yg+1],0,non_zero_rows,margin,1-margin),o.push([nx,ny=map(y,yg/grid_size,(yg+1)/grid_size,row1,row2),e[l][2],e[l][3],e[l][4],e[l][5]]);return o}function on_segment(e,$,t,r,s,_){return!!(t<=max(e,s)&&t>=min(e,s)&&r<=max($,_)&&r>=min($,_))}function orient(e,$,t,r,s,_){let n=(r-$)*(s-t)-(t-e)*(_-r);return n>0?1:n<0?2:0}function intersect(e,$,t,r,s,_,n,o){return(e!=s||$!=_)&&(e!=n||$!=o)&&(t!=s||r!=_)&&(t!=n||r!=o)&&(o1=orient(e,$,t,r,s,_),o2=orient(e,$,t,r,n,o),o3=orient(s,_,n,o,e,$),o4=orient(s,_,n,o,t,r),!!(o1!=o2&&o3!=o4||0==o1&&on_segment(e,$,s,_,t,r)||0==o2&&on_segment(e,$,n,o,t,r)||0==o3&&on_segment(s,_,e,$,n,o)||0==o4&&on_segment(s,_,t,r,n,o)))}function intersect_pt(e,$,t,r,s,_,n,o){let l=t-e,h=r-$,u=n-s,g=o-_,d;return[(d=0==u?(s-e)/(t-e):(_-$+(e-s)*g/u)/(h-l*g/u))*l+e,d*h+$]}function polyArea(e){area=0,multiplier=1;for(let $=0;$<e.length;$++){x1=e[$][0],y1=e[$][1],x2=e[($+1)%e.length][0],y2=e[($+1)%e.length][1],intersect_pt_list=[];for(let t=0;t<e.length;t++)t!=$&&(x3=e[t][0],y3=e[t][1],intersect(x1,y1,x2,y2,x3,y3,x4=e[(t+1)%e.length][0],y4=e[(t+1)%e.length][1])&&intersect_pt_list.push(intersect_pt(x1,y1,x2,y2,x3,y3,x4,y4)));if(intersect_pt_list.length>0){intersect_pt_list.push([x1,y1]),intersect_pt_list.push([x2,y2]);for(let r=0;r<intersect_pt_list.length;r++)intersect_pt_list[r].push(len(x1,y1,intersect_pt_list[r][0],intersect_pt_list[r][1]));intersect_pt_list.sort((e,$)=>e[2]-$[2]);for(let s=0;s<intersect_pt_list.length-1;s++)area+=(intersect_pt_list[s][0]*intersect_pt_list[s+1][1]-intersect_pt_list[s+1][0]*intersect_pt_list[s][1])/2*multiplier,multiplier*=-1;multiplier*=-1}else area+=(x1*y2-x2*y1)/2*multiplier}return abs(area)}function sqabs(e){return Math.sign(e)*sqrt(abs(e))}function ease(e){return 2/(1+exp(-e))-1}function bulge(e){return 3*exp(-2*e*e)*e}function ratio(e,$){return atan(e/(0==$?1e-6:$))}function nabs(e){return-abs(e)}function len(e,$,t,r){return sqrt(sq(t-e)+sq(r-$))}function mousePressed(){looping=!looping}function draw(){for(this_iter=0;draw_iter<draw_times.length&&time>draw_times[draw_iter][10]&&this_iter<1e4;){x1=draw_times[draw_iter][0],y1=draw_times[draw_iter][1],z=draw_times[draw_iter][2],theta=draw_times[draw_iter][3],x=draw_times[draw_iter][4],y=draw_times[draw_iter][5],z2=draw_times[draw_iter][6],theta2=draw_times[draw_iter][7],size_scale=draw_times[draw_iter][8],c_rand=draw_times[draw_iter][9],layer_num=draw_times[draw_iter][11],tri_brush?(x2=x1+1/sqrt(2)*rescale*map(z,1,0,2*min_size,2*max_size)*(cos(theta)+.5*cos(theta+PI/2)),y2=y1+1/sqrt(2)*rescale*map(z,1,0,2*min_size,2*max_size)*(sin(theta)+.5*sin(theta+PI/2)),x3=x1+1/sqrt(2)*rescale*map(z,1,0,2*min_size,2*max_size)*(cos(theta)+.5*cos(theta-PI/2)),y3=y1+1/sqrt(2)*rescale*map(z,1,0,2*min_size,2*max_size)*(sin(theta)+.5*sin(theta-PI/2))):(x2=x1+rescale*map(z,1,0,min_size,max_size)*cos(theta),y2=y1+rescale*map(z,1,0,min_size,max_size)*sin(theta),x3=x1+rescale*map(z,1,0,min_size,max_size)*cos(theta+PI),y3=y1+rescale*map(z,1,0,min_size,max_size)*sin(theta+PI),x4=x1+rescale*map(z,1,0,min_size,max_size)*.5*cos(theta+PI/2),y4=y1+rescale*map(z,1,0,min_size,max_size)*.5*sin(theta+PI/2),x5=x1+rescale*map(z,1,0,min_size,max_size)*.5*cos(theta-PI/2),y5=y1+rescale*map(z,1,0,min_size,max_size)*.5*sin(theta-PI/2)),tri_brush?(cx1=lerp(x1,x2,x),cy1=lerp(y1,y2,x),cx2=lerp(x1,x3,x),cy2=lerp(y1,y3,x),cx3=lerp(cx1,cx2,y),cy3=lerp(cy1,cy2,y)):(cx1=lerp(x2,x4,x),cy1=lerp(y2,y4,x),cx2=lerp(x5,x3,x),cy2=lerp(y5,y3,x),cx3=lerp(cx1,cx2,y),cy3=lerp(cy1,cy2,y)),dx1=x1-aspect_ratio/2,dy1=y1-.5,dx=x-.5,dy=y-.5,fill(p[c_rand]),beginShape();for(let e=0;e<poly_pts.length;e++)vertex((px=cx3+poly_pts[e][2]*cos(poly_pts[e][3]+theta2)*.02*poly_scale*sqrt(size_scale))*unit,(py=cy3+poly_pts[e][2]*sin(poly_pts[e][3]+theta2)*.02*poly_scale*sqrt(size_scale))*unit);endShape(),draw_iter++,this_iter++}if(time+=8e-4,draw_iter>=draw_times.length&&looping){msecs=new Date().getTime()%1e4;for(let $=0;$<msecs;$++)R.rd();draw_iter=0,time=0;for(let t=0;t<draw_offsets.length;t++)draw_offsets[t]+=.2*R.rd()-.2*R.rd(),draw_offsets[t]*=.9;for(let r=0;r<color_offsets.length;r++)color_offsets[r]+=(.2*R.rd()-.2*R.rd()+1)%1;draw_times=[];for(let s=0;s<brush_pts.length;s++){x1=brush_pts[s][0],y1=brush_pts[s][1],z=brush_pts[s][2],theta=brush_pts[s][3],layer_num=brush_pts[s][4],c_rand2=brush_pts[s][6];for(let _=0;_<stroke_pts[layer_num].length;_++)x=stroke_pts[layer_num][_][0],y=stroke_pts[layer_num][_][1],z2=stroke_pts[layer_num][_][2],theta2=stroke_pts[layer_num][_][3],size_scale=stroke_pts[layer_num][_][5],c_rand=(color_rand=R.rd())<.5?floor(p.length*((c1_mult*(z+z2)+9+c1_offset+map(layer_num,0,num_layers,0,1)+.2*R.rd()-.2*R.rd()+color_offsets[layer_num])%1)):floor(p.length*((c2_mult*c_rand2+9+c2_offset+.1*R.rd()-.1*R.rd())%1)),draw_time=(3*z+map(tan(map(z2,0,1,-PI/4,PI/4)),-1,1,0,1))/4+1e-4*_+draw_offsets[layer_num]-min(draw_offsets),draw_times.push([x1,y1,z,theta,x,y,z2,theta2,size_scale,c_rand,draw_time,layer_num])}draw_times.sort((e,$)=>e[10]-$[10])}}