G'MIC exercises

I would like to know how _random_pattern_expr works. What I’m figuring out is how to create a iterative version of it.

All I know is this, it calls itself and the status reflects upon the result of itself. Shouldn’t it set status to one of the if else inside the termination block, then terminates? That’s the part I simply cannot understand.

Here it is:

_random_pattern_expr : skip "${1=0},${2=0}"
  nl:=$2+1
  if (u<$1" && "$2>1)" || "$2>6 # Termination node
    r:=u
    if $r<0.75 u z
    else u [{_round(u([-1,-1],[1,1]),0.1)}]
    fi
  else # Function or operator
    p1,p2:=[$1,$1]+u([0.2,0.2])
    r:=u(27)
    if $r<1 u ccos(${$0\ $p1,$nl})
    elif $r<2 u csin(${$0\ $p1,$nl})
    elif $r<3 u ctan(${$0\ $p1,$nl})
    elif $r<4 u ccosh(${$0\ $p1,$nl})
    elif $r<5 u csinh(${$0\ $p1,$nl})
    elif $r<6 u ctanh(${$0\ $p1,$nl})
    elif $r<7 u cexp(${$0\ $p1,$nl})
    elif $r<8 u clog(${$0\ $p1,$nl})
    elif $r<9 u [cabs(${$0\ $p1,$nl}),0]
    elif $r<10 u [0,cabs(${$0\ $p1,$nl})]
    elif $r<11 u [carg(${$0\ $p1,$nl}),0]
    elif $r<12 u [0,carg(${$0\ $p1,$nl})]
    elif $r<13 u cconj(${$0\ $p1,$nl})
    elif $r<14 u (${$0\ $p1,$nl})+(${$0\ $p2,$nl})
    elif $r<15 u (${$0\ $p1,$nl})-(${$0\ $p2,$nl})
    elif $r<16 u ${$0\ $p1,$nl}**${$0\ $p2,$nl}
    elif $r<17 u ${$0\ $p1,$nl}//${$0\ $p2,$nl}
    elif $r<18 u (${$0\ $p1,$nl})^^0.5
    elif $r<19 u (${$0\ $p1,$nl})^^2
    elif $r<20 u (${$0\ $p1,$nl})^^3
    elif $r<21 u ${$0\ $p1,$nl}*${$0\ $p2,$nl}
    elif $r<22 u ${$0\ $p1,$nl}/(0.01+cabs(${$0\ $p2,$nl}))
    elif $r<23 u abs(${$0\ $p1,$nl})^0.5
    elif $r<24 u (${$0\ $p1,$nl})^2
    elif $r<25 u [(${$0\ $p1,$nl})[0],0]
    elif $r<26 u [0,(${$0\ $p1,$nl})[1]]
    else u (${$0\ $p1,$nl})^3
    fi
  fi
1 Like