/*

insectivore.cfdg

By AK Jun 2013

Variations: any

Original URL:          https://www.contextfreeart.org/gallery/view.php?id=3215
Originally created at: 07.06.2013
Licence:               https://creativecommons.org/licenses/by-sa/3.0/au/deed.en

*/

startshape X Ntheta=60 Nphi=Ntheta/2 CF::Background=[b -.5 h 220 sat .3] CF::Size=[s 4]

shape X {

loop i=Nphi [] {
  phi=(i+.5)*180/Nphi
  rtwist=0..1
  Mtheta=floor(Ntheta/2*sin(phi))
  loop j=Mtheta [] {
    theta=(j+ rtwist)*360/Mtheta
    cell(sin(phi)*cos(theta),
      sin(phi)*sin(theta),
      cos(phi),
      sin(phi))[]
    }
  }
loop i=30 [ y -.02 x .01 r -.5 s 1.01] 
  BUMP(i*.03)[s .15 .3  h 100 b (i*.01) sat .6 x .6 y -1 a -.9]
BUMP(1)[s 6 z -99 a -.90 b -.5 h 220 sat .3]
AK(.3)[x 1.88 y -1.9 s .12 h 240 sat .3 b .4   z 999]
}

shape cell( number xx, number yy, number zz, number xy ) {

BUMP(.8)[s .45 .45 .45 x xx y yy z zz h 80 sat .6]
BUMP(0.2)[s .12 .12 0 x (1.1*xx) y (1.1*yy) z (1.1*zz) b 0 a -.95]
spike(xy,12,0)[[ x (1.1*xx) y (1.1*yy) z (1.1*zz) r atan2(yy,xx) s .08 .08

zz sat 1 h -20..0]]

loop 88 []
  CIRCLE[[x -.2 .. .2 y -.2 .. .2 x xx y yy z zz s .008 .. .015 a -.75 ..

-.85]] // spots

}

shape BUMP(number target_b ){

CIRCLE[z -1]
BUMP(=)[s .98 .98 .95 b .02 target_b a -.01]
}

epsilon=0.02 shape spike(number dir,number stretch,curl)

rule 20{
SPOT[]
spike(=)[[z 1 x (stretch*dir) s  (1-epsilon) (1-1.5*epsilon) (1-epsilon) x

(-stretch*dir) z -1 sat .2 b .1 r (curl*epsilon*20) a (-1*epsilon)]]

}
rule { spike(dir, stretch,-20)[h 10] }
rule { spike(dir, stretch,-5)[] }
rule { spike(dir, stretch,0)[] }
rule { spike(dir, stretch,5)[] }
rule { spike(dir, stretch,20)[h 5] }
rule .2{
  spike(=)[r -25]
  spike(=)[r 25 f 0]
  }

shape SPOT

rule 9 {CIRCLE[]}
rule 1 {CIRCLE[b -.2]}
rule 2 {SPOT[] CIRCLE[a -.5 b 1 s .5 sat -1]}

// —- A signature (FWIW) shape AK(number target_b){loop 2[r -30 s sqrt(1/3) b 1 target_b]TRIANGLE[]}