2424
2525from opensimplex import OpenSimplex
2626
27- #- ---------------------------------------------------------------------------
27+ # ---------------------------------------------------------------------------
2828
2929class OSN ():
30- min = - 1
31- max = 1
30+ min = - 1
31+ max = 1
3232
33- def __init__ (self ,seed ,diameter ):
33+ def __init__ (self , seed , diameter ):
3434 self .tmp = OpenSimplex (seed )
3535 self .d = diameter
3636 self .x = 0
3737 self .y = 0
3838
39- def get_val (self ,angle ):
40- self .xoff = valmap (np .cos (angle ), - 1 , 1 , self .x , self .x + self .d );
41- self .yoff = valmap (np .sin (angle ), - 1 , 1 , self .y , self .y + self .d );
39+ def get_val (self , angle ):
40+ self .xoff = valmap (np .cos (angle ), - 1 , 1 , self .x , self .x + self .d )
41+ self .yoff = valmap (np .sin (angle ), - 1 , 1 , self .y , self .y + self .d )
4242 return self .tmp .noise2d (self .xoff ,self .yoff )
4343
4444def circularloop (nf , d , seed ):
@@ -59,7 +59,7 @@ def circularloop(nf, d, seed):
5959
6060 current_pos = 0.0
6161 step = 1. / nf
62-
62+
6363 while (current_pos < 1.0 ):
6464 zs .append (circular_interpolation (r , latents , current_pos ))
6565 current_pos += step
@@ -87,12 +87,30 @@ def num_range(s: str) -> List[int]:
8787 vals = s .split (',' )
8888 return [int (x ) for x in vals ]
8989
90- def line_interpolate (zs , steps ):
90+ def line_interpolate (zs , steps , easing ):
9191 out = []
9292 for i in range (len (zs )- 1 ):
9393 for index in range (steps ):
94- fraction = index / float (steps )
95- out .append (zs [i + 1 ]* fraction + zs [i ]* (1 - fraction ))
94+ t = index / float (steps )
95+
96+ if (easing == 'linear' ):
97+ out .append (zs [i + 1 ]* t + zs [i ]* (1 - t ))
98+ elif (easing == 'easeInOutQuad' ):
99+ if (t < 0.5 ):
100+ fr = 2 * t * t
101+ else :
102+ fr = (- 2 * t * t ) + (4 * t ) - 1
103+ out .append (zs [i + 1 ]* fr + zs [i ]* (1 - fr ))
104+ elif (easing == 'bounceEaseOut' ):
105+ if (t < 4 / 11 ):
106+ fr = 121 * t * t / 16
107+ elif (t < 8 / 11 ):
108+ fr = (363 / 40.0 * t * t ) - (99 / 10.0 * t ) + 17 / 5.0
109+ elif t < 9 / 0 :
110+ fr = (4356 / 361.0 * t * t ) - (35442 / 1805.0 * t ) + 16061 / 1805.0
111+ else :
112+ fr = (54 / 5.0 * t * t ) - (513 / 25.0 * t ) + 268 / 25.0
113+ out .append (zs [i + 1 ]* fr + zs [i ]* (1 - fr ))
96114 return out
97115
98116def noiseloop (nf , d , seed ):
@@ -127,7 +145,7 @@ def images(G,device,inputs,space,truncation_psi,label,noise_mode,outdir):
127145 img = (img .permute (0 , 2 , 3 , 1 ) * 127.5 + 128 ).clamp (0 , 255 ).to (torch .uint8 )
128146 PIL .Image .fromarray (img [0 ].cpu ().numpy (), 'RGB' ).save (f'{ outdir } /frame{ idx :04d} .png' )
129147
130- def interpolate (G ,device ,projected_w ,seeds ,random_seed ,space ,truncation_psi ,label ,frames ,noise_mode ,outdir ,interpolation ,diameter ):
148+ def interpolate (G ,device ,projected_w ,seeds ,random_seed ,space ,truncation_psi ,label ,frames ,noise_mode ,outdir ,interpolation ,easing , diameter ):
131149 if (interpolation == 'noiseloop' or interpolation == 'circularloop' ):
132150 if seeds is not None :
133151 print (f'Warning: interpolation type: "{ interpolation } " doesn’t support set seeds.' )
@@ -149,7 +167,7 @@ def interpolate(G,device,projected_w,seeds,random_seed,space,truncation_psi,labe
149167
150168 # get interpolation points
151169 if (interpolation == 'linear' ):
152- points = line_interpolate (points ,frames )
170+ points = line_interpolate (points ,frames , easing )
153171 elif (interpolation == 'slerp' ):
154172 if (space == 'w' ):
155173 print (f'Slerp currently isn’t supported in w space. Working on it!' )
@@ -238,6 +256,9 @@ def zs_to_ws(G,device,label,truncation_psi,zs):
238256@click .option ('--fps' , type = int , help = 'framerate for video' , default = 24 , show_default = True )
239257@click .option ('--increment' , type = float , help = 'truncation increment value' , default = 0.01 , show_default = True )
240258@click .option ('--interpolation' , type = click .Choice (['linear' , 'slerp' , 'noiseloop' , 'circularloop' ]), default = 'linear' , help = 'interpolation type' , required = True )
259+ @click .option ('--easing' ,
260+ type = click .Choice (['linear' , 'easeInOutQuad' , 'bounceEaseOut' ]),
261+ default = 'linear' , help = 'easing method' , required = True )
241262@click .option ('--network' , 'network_pkl' , help = 'Network pickle filename' , required = True )
242263@click .option ('--noise-mode' , help = 'Noise mode' , type = click .Choice (['const' , 'random' , 'none' ]), default = 'const' , show_default = True )
243264@click .option ('--outdir' , help = 'Where to save the output images' , type = str , required = True , metavar = 'DIR' )
@@ -252,6 +273,7 @@ def zs_to_ws(G,device,label,truncation_psi,zs):
252273
253274def generate_images (
254275 ctx : click .Context ,
276+ easing : str ,
255277 interpolation : str ,
256278 increment : Optional [float ],
257279 network_pkl : str ,
@@ -352,7 +374,7 @@ def generate_images(
352374 vidname = f'{ process } -{ interpolation } -{ diameter } dia-seed_{ random_seed } -{ fps } fps'
353375
354376
355- interpolate (G ,device ,projected_w ,seeds ,random_seed ,space ,truncation_psi ,label ,frames ,noise_mode ,dirpath ,interpolation ,diameter )
377+ interpolate (G ,device ,projected_w ,seeds ,random_seed ,space ,truncation_psi ,label ,frames ,noise_mode ,dirpath ,interpolation ,easing , diameter )
356378
357379 # convert to video
358380 cmd = f'ffmpeg -y -r { fps } -i { dirpath } /frame%04d.png -vcodec libx264 -pix_fmt yuv420p { outdir } /{ vidname } .mp4'
0 commit comments