#VRML V2.0 utf8 ## ##:@+ bouncing ball (5) ##@ proto bounce PROTO bounce [ exposedField SFFloat accel 0.1 ]{ Transform { children [ Transform { translation 0 -10 0 children [ Shape { geometry Box { size 5 0.2 5 } appearance Appearance { material DEF GROUND Material { diffuseColor 1 0 0 } } } ]} ##@ object DEF OBJECT Transform { scale 0.5 0.5 0.5 children [ Shape { geometry Sphere { radius 1 } appearance Appearance { material DEF MATERIAL Material { diffuseColor 1 0 0 } } } ] } ] } ##@ sensor DEF TIME TimeSensor { loop TRUE cycleInterval 5 } # ##@ script DEF SCRIPT Script { directOutput TRUE field SFFloat accel IS accel field SFTime tick 0 field SFNode object USE OBJECT field SFNode material USE MATERIAL field SFNode ground USE GROUND field SFFloat position 0 field SFFloat color 0.5 field SFInt32 sign 1 field SFFloat speed 1 eventIn SFFloat set_fraction url "javascript: ##@ fraction function set_fraction(value) { if (tick == 0) { tick = value; position = 0; color = 0.5; } while (tick < value) { update(value); tick = tick + 0.05; } tick = value; } ##@ update function update(value) { position += 0.01 * sign * speed; color = value; speed = speed * ( 1 - sign * accel); object.translation.y = position; material.diffuseColor = new SFColor(1,color,color); if (speed < 0.1 ) sign = -1; if (position < -9) { effect(value); sign = 1; } } ##@ effect function effect(value) { ground.diffuseColor = new SFColor(1,color,color); } " }# ##@ routing ROUTE TIME.fraction_changed TO SCRIPT.set_fraction } ##@ bounce instances Transform { translation -12 0 0 children [ bounce { accel 0.1 } ] } Transform { translation 0 0 0 children [ bounce { accel 0.2 } ] } Transform { translation 12 0 0 children [ bounce { accel 0.3 } ] } Transform { translation -6 0 -10 children [ bounce { accel 0.4 } ] } Transform { translation 6 0 -10 children [ bounce { accel 0.5 } ] } ##@ environment DirectionalLight { direction 0 -1 -1 } Viewpoint { position 0 0 30 } Background { skyColor 0.2 0.2 0.4 } ##