#VRML V2.0 utf8 Proto Tree3 with Randomness, Evgeny Demidov, 5 Dec 2000 NavigationInfo{ type "EXAMINE" } Background{ skyColor .5 .5 1} PROTO Tree3[ field SFInt32 order 3 field SFVec3f TrunkSc 1 1 1 field SFVec3f BranchSc .5 .5 .5 field SFRotation Rot 1 0 0 1 ]{ DEF ROOT Transform{ scale 4 4 4 translation 0 -4 0 children[]} DEF Polyhedron Script { eventOut MFNode new_f field SFNode ROOT USE ROOT field SFInt32 MaxIt IS order field SFRotation Rot IS Rot field SFVec3f TrunkSc IS TrunkSc field SFVec3f BranchSc IS BranchSc directOutput TRUE url ["javascript: function initialize(){ str = 'DEF L0 Shape{ appearance Appearance{ material Material{ diffuseColor 0 1 0}} '+ 'geometry IndexedFaceSet{ solid FALSE '+ 'coord Coordinate{ point[0 1 0,.4 1.6 .2,.8 2.2 0,.2 1.6 -.2]} '+ 'coordIndex[0 1 2 3]}} '+ 'Transform{ rotation 0 1 0 3.14 translation 0 1 0 children USE L0} '+ 'DEF B0 Shape{ appearance Appearance{ material Material{ emissiveColor .5 .5 0}} '+ 'geometry IndexedLineSet{ coord Coordinate{ point[0 0 0,0 2 0]} '+ 'coordIndex[0 1]}}'; for ( i= 1; i<=MaxIt; i++) str = 'Transform{ translation 0 1 0 children '+ 'DEF s'+i+' Transform{ scale '+BranchSc+' rotation 0 0 1 '+ (MaxIt+1-i)*.5*(Math.random()-.5) +' children[ '+ str + ']} } Transform{ scale .5 .5 .5 children trunk{}} '+ 'DEF g'+i+' Transform{ rotation '+Rot+' translation 0 1 0 children USE s'+i+'} '+ 'Transform{ rotation 0 1 0 2.09 children USE g'+i+'} '+ 'Transform{ rotation 0 1 0 -2.09 children USE g'+i+'}'; new_f = Browser.createVrmlFromString( 'PROTO trunk[]{Transform{ scale '+TrunkSc+' children[ '+ 'Shape{ appearance Appearance{ material Material{ diffuseColor .8 .8 0}} '+ 'geometry IndexedFaceSet{ coord Coordinate{ '+ 'point[.2 0 0,.1 0 -.17,-.1 0 -.17,-.2 0 0,-.1 0 .17,.1 0 .17, '+ '.1 2 0,.05 2 -.09,-.05 2 -.09,-.1 2 0,-.05 2 .09,.05 2 .09]} '+ 'coordIndex[0 1 7 6 -1 1 2 8 7 -1 2 3 9 8 -1 3 4 10 9 -1 4 5 11 10 -1 5 0 6 11] '+ ' creaseAngle 2}}]}} ' + str ); ROOT.addChildren = new_f; } "]} } Tree3{order 5 }