Playing with random image partitions of rectangular blocks

Here is one of my tonight experiment.
Not sure how far I should go with it, so I share the script, maybe you’ll get better ideas than me for improving the effect!

It basically generates an animation like this:

ezgif.com-gif-maker (2)

Here is the script (requires G’MIC 3.1) :

foo :
  sp portrait7,800

  # Generate random block partition.
  1,1,1,5
  eval "
    push_block(x0,y0,x1,y1) = (
      area = (abs(x1 - x0) + 1)*(abs(y1 - y0) + 1);
      da_push([ x0,y0,x1,y1,area ]);
    );

    push_block(0,0,w#0 - 1,h#0 - 1);
    repeat (160,
      siz = da_size();
      ind = run('+z. 0,0,0,4,0,{h-2},0,4 u {argmax(crop())} rm.');
      P = I[ind];
      dx = abs(P[2] - P[0]) + 1;
      dy = abs(P[3] - P[1]) + 1;
      da_remove(ind);

      r = u(0.1,0.9);
      dy>dx?( # Horizontal split
        y = round(lerp(P[1],P[3],r));
        push_block(P[0],P[1],P[2],y - 1);
        push_block(P[0],y,P[2],P[3]);
      ):( # Vertical split
        x = round(lerp(P[0],P[2],r));
        push_block(P[0],P[1],x - 1,P[3]);
        push_block(x,P[1],P[2],P[3]);
      );
    );
    resize(#-1,1,da_size(),1,4,0)"

  # Generate animation frames.
  nbf=40
  repeat $nbf {
    l:=$>/($nbf-1)
    fact:=lerp(5,1,$l^0.4)
    ang:=lerp(180,0,$l^0.4)*pi/180
    opac:=lerp(0,1,$l)

    {0,[w,h,1,4]}
    xc,yc={0,[w,h]/2}
    repeat h#1 {
      x0,y0,x1,y1={I[#1,$>]}
      +z[0] $x0,$y0,$x1,$y1 to_rgba.
      frame_round. 10,10,0,0,0,0,0,0
      x0,y0:="[$xc,$yc] + $fact*rot($ang)*([$x0,$y0] - [$xc,$yc])"
      x1,y1:="[$xc,$yc] + $fact*rot($ang)*([$x1,$y1] - [$xc,$yc])"
      j.. .,$x0,$y0 rm.
    }

    drop_shadow. 3,3,5,0,0
    +luminance[0] to_rgb.
    rv[-2,-1] blend[-2,-1] alpha,$opac
    w.
  }
  k[2--1]
  r2dx 50% .x10 +rv
  o anim.gif,10
~~~
2 Likes

Brainstorm:

  1. Address top and left border/offset.
  2. Explore animation ramping.
  3. Explore different types of animation (e.g., rows of tiles filling in from opposite directions).
  4. Transition between different images.
  5. More (irregular) shapes.
1 Like

If you want hard mode:

  1. Transition sample image into threads à la G'MIC Challenge: Create image from photographs with a single line - #49 by samj. :smiling_imp: Kind of like skeleton but into a tsp format.

As in 1 pixel thick lines? That’s feasible actually. A little modification to my rep_rrd is all I need to do to do something like this.