Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #@gui Cubism: fx_jr_cubism_preview
- #@gui : sep = separator()
- #@gui : 0. Recompute = button()
- #@gui : 1. Threshold=float(2,0,15)
- #@gui : 2. Smoothness=float(1,0,500)
- #@gui : 3. Offset Amplitude=float(10,0,100)
- #@gui : 4. Anti-Aliasing=bool(1)
- fx_jr_cubism:
- repeat $! l[$>]
- ww={w}
- hh={h}
- aa=$4
- amp={$3*norm(w,h)*0.01}
- +b. $2 segment_watershed. $1
- f. ">begin(srand();rand=u(100,200));srand(i*rand);u"
- repeat {s}
- sh. $> *. {u(1,2)} rm.
- done
- to_gray.
- label.
- initsize={1+iM#1}
- $initsize,5,1,1
- vsize={$initsize*2}
- eval ${-math_lib}"
- coordinates_per_val=vector"$vsize"(0);
- count_per_val=vector"$initsize"(0);
- for(px=0,px<w#1,px++,
- for(py=0,py<h#1,py++,
- pos=i(#1,px,py);
- coordinates_per_val[pos*2]+=px;
- coordinates_per_val[pos*2+1]+=py;
- count_per_val[pos]++;
- );
- );
- for(n=0,n<"$initsize",n++,
- coordinates_per_val[n*2]/=count_per_val[n];
- coordinates_per_val[n*2+1]/=count_per_val[n];
- I(n,0)=coordinates_per_val[n*2];
- I(n,1)=coordinates_per_val[n*2+1];
- );
- "
- repeat {3}
- row={$>+2}
- sh. $row,$row,0,0 f. ">begin(randm=u(100+y,200+y);randa=u(1,3));srand((x+(randa))*randm);u"
- if {$>==2} n. 0,{2*pi} else n. 0,$amp fi
- rm.
- done
- $ww,$hh,1,2
- f. "val=vector2(0);
- I(#1)!=J(#1,1)?(val[0]+=1);
- I(#1)!=J(#1,0,1)?(val[1]+=1);
- I(#1)!=J(#1,-1)?(val[0]-=1);
- I(#1)!=J(#1,0,-1)?(val[1]-=1);
- val"
- *. 255
- +smooth. 10,0,1,1,5,15,0
- -.. .
- rm.
- /. 510
- f[0] "begin(const spec=s;
- cubism(id,xx,yy)=(
- params=crop(#2,id,0,0,0,1,5,1,1);
- xro=params[0];
- yro=params[1];
- xoff=params[2];
- yoff=params[3];
- ang=params[4];
- sang=sin(ang);
- cang=cos(ang);
- vx=xx-xro-xoff;
- vy=yy-yro-yoff;
- I(vx*cang+vy*sang+xoff+xro,vy*cang-vx*sang+yoff+yro,0,1,3)));
- xs=i(#-1,x,y,0,0);
- ys=i(#-1,x,y,0,1);
- ("$aa"&&xs!=0&&ys!=0)?(
- idlist=vector(#4,-1);
- freqlist=vector(#4,0);
- idnum=0;
- xdir=sign(xs);ydir=sign(ys);
- xo=abs(xs);yo=abs(ys);
- gridmult=[(1-xo)*(1-yo),xo*(1-yo),(1-xo)*yo,xo*yo];
- for(py=0,py<2,py++,
- for(px=0,px<2,px++,
- curr=i(#1,x+xdir*px,y+ydir*py,0,0,1);
- pos=find(idlist,curr);
- pos==-1?(idnum+=1;pos=find(idlist,-1);idlist[pos]=curr);
- freqlist[pos]+=gridmult[py*2+px];
- );
- );
- val=vector(#spec,0);
- for(n=0,n<idnum,n++,
- val+=cubism(idlist[n],x,y)*freqlist[n]);
- val):(cubism(i(#1,x,y,0,0,1),x,y))
- "
- rm[^0]
- endl done
- fx_jr_cubism_preview:
- fx_jr_cubism ${2-5}
Add Comment
Please, Sign In to add comment