/***************************************************************/ // ''Genetic'' Growth Model record Cell = { cpt1, cpt2 } ;; record FGP = Cell + { cpt1 != 0 } ;; record SGP = Cell + { cpt1 = 0, cpt2 != 0 } ;; record Empty = { ~cpt1, ~cpt2 } ;; fun NextFGP (c:FGP) = c + { cpt1 = c.cpt1-1 } ;; fun NextSGP (c:SGP) = c + { cpt2 = c.cpt2-1 } ;; seed := { cpt1 = 5, cpt2 = 2 } ;; // Spacial specification v1 := new_vertex() ;; v2 := new_vertex() ;; v3 := new_vertex() ;; v4 := new_vertex() ;; e12 := new_edge(v1, v2) ;; e23 := new_edge(v2, v3) ;; e34 := new_edge(v3, v4) ;; e41 := new_edge(v4, v1) ;; f := new_acell(2, (e12,e23,e34,e41), seq:()) ;; init := { x = 32., y = 41. } * v1 + { x = 31., y = 45. } * v2 + { x = 33., y = 46. } * v3 + { x = 34., y = 43. } * v4 + `Basal * e12 + `Lateral * e23 + `Apical * e34 + `Lateral * e41 + seed * f ;; // Output fun outputChain[colorVertex,colorEdge,colorFace](ofile,ch) = ( ofile << " { \n"; iter_indexed((\c.\v.( switch (dimension(c)) case 0: ( let coul = colorVertex(v) in ofile << " { " << v.x << " " << v.y << " " << coul.r << " " << coul.g << " " << coul.b << " } \n" ) case 1: ( let coul = colorEdge(v) and lf = faces(c) in ofile << " [ " << (ch.(lf.(0))).x << " " << (ch.(lf.(0))).y << " " << (ch.(lf.(1))).x << " " << (ch.(lf.(1))).y << " " << coul.r << " " << coul.g << " " << coul.b << " ] \n" ) case 2: ( let coul = colorFace(v) and lf = icells(c,0) in ofile << " ( " << size(lf) << " " ; iter((\v.( ofile << (ch.(v)).x << " " << (ch.(v)).y << " " )), lf); ofile << coul.r << " " << coul.g << " " << coul.b << " ) \n" ) endswitch )),ch); ofile << " } \n"; ch ) ;; fun colorVertex(v) = BLACK ;; fun colorEdge(e) = ( switch (e) case `Basal: BLACK case `Apical: GREEN default: RED endswitch ) ;; fun colorFace(c) = ( if c.cpt1 != 0 then GRAY(c.cpt1 / 10.0) else GRAY(0.5 - c.cpt2 / 6.0) fi ) ;; //outputChain[colorVertex=colorVertex,colorEdge=colorEdge,colorFace=colorFace]("/tmp/toto", init) ;; //!quit ;; // Some Mechanics trans <2> Barycenter = { f => ( let g = icellsfold( (\v,acc.( { x = acc.x + v.x, y = acc.y + v.y, n = acc.n + 1.0 } )), { x = 0.0, y = 0.0, n = 0.0 }, f, 0 ) in f + { x = g.x/g.n, y = g.y/g.n } ) } ;; trans <0,1> MecaVertex[k=1.0,L0=5.0,dt=0.1] = { v => ( let Fspring = neighborsfold( (\v',acc.( let d = sqrt((v'.x - v.x)*(v'.x - v.x) + (v'.y - v.y)*(v'.y - v.y)) in let f = k * (d - L0) / d in { x = acc.x + f*(v'.x-v.x), y = acc.y + f*(v'.y-v.y) } )), { x = 0.0, y = 0.0 }, v ) in let Ftot = icellsfold( (\g,acc.( let d = sqrt((g.x - v.x)*(g.x - v.x) + (g.y - v.y)*(g.y - v.y)) in let f = k * (d - sqrt(2.0)/2.0*L0) / d in { x = acc.x + f*(g.x-v.x), y = acc.y + f*(g.y-v.y) } )), Fspring, v, 2 ) in v + { x = v.x + dt*Ftot.x, y = v.y + dt*Ftot.y } ) } ;; fun Meca(ch) = MecaVertex(Barycenter(ch)) ;; /* Meca[iter=100, interlude=outputChain[colorVertex=colorVertex, colorEdge=colorEdge, colorFace=colorFace ]("/tmp/toto") ](init) ;; !quit ;; */ // ''Genetic'' Rules patch Rules = { ~v1 < e12 < ~f:[dim=2, FGP(f)] > e12 > ~v2 when (e12 == `Apical) => ( letcell v3(0) and v4(0) and e23(1, (^v2, v3)) and e34(1, (v3, v4)) and e41(1, (v4, ^v1)) and nf(2, (^e12,e23,e34,e41)) in ( v2 + { x = v2.x + (v2.x-f.x) * 0.05, y = v2.y + (v2.y-f.y) * 0.05 } ) * v3 + ( v1 + { x = v1.x + (v1.x-f.x) * 0.05, y = v1.y + (v1.y-f.y) * 0.05 } ) * v4 + `Internal * ^e12 + `Lateral * e23 + `Apical * e34 + `Lateral * e41 + (NextFGP(f)) * nf end ); ~v1 < e12 < ~f:[dim=2, SGP(f)] > e12 > ~v2 when (e12 == `Lateral) => ( letcell v3(0) and v4(0) and e23(1, (^v2, v3)) and e34(1, (v3, v4)) and e41(1, (v4, ^v1)) and nf(2, (^e12,e23,e34,e41)) in ( v2 + { x = v2.x + (v2.x-f.x) * 0.05, y = v2.y + (v2.y-f.y) * 0.05 } ) * v3 + ( v1 + { x = v1.x + (v1.x-f.x) * 0.05, y = v1.y + (v1.y-f.y) * 0.05 } ) * v4 + `Internal * ^e12 + `Basal * e23 + `Lateral * e34 + `Basal * e41 + (NextSGP(f)) * nf end ); } ;; // Main Program ofile := "tshaped.jbv" ;; fun evolve(ch) = ( Rules(Meca[ iter=100, interlude=outputChain[colorVertex=colorVertex, colorEdge=colorEdge, colorFace=colorFace](ofile) ](ch)) ) ;; evolve[ iter=10, prelude=outputChain[colorVertex=colorVertex, colorEdge=colorEdge, colorFace=colorFace ](ofile), postlude=outputChain[colorVertex=colorVertex, colorEdge=colorEdge, colorFace=colorFace ](ofile) ](init) ; 0;;