<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.0//EN" "http://www.web3d.org/specifications/x3d-3.0.dtd">
<X3D profile='Immersive' version='3.0' xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation='http://www.web3d.org/specifications/x3d-3.0.xsd'>
  <head>
    <meta content='Figure30.4ScriptSpiralingBallTrace.x3d' name='title'/>
    <meta content='Figure 30.4, The VRML 2.0 Sourcebook, Copyright [1997] By Andrea L. Ames, David R. Nadeau, and John L. Moreland' name='creator'/>
    <meta content='http://www.wiley.com/legacy/compbooks/vrml2sbk/ch30/30fig04.htm' name='reference'/>
    <meta content='Don Brutzman' name='translator'/>
    <meta content='2 September 2000' name='created'/>
    <meta content='11 January 2014' name='modified'/>
    <meta content='A spiraling red sphere and a custom interpolation script.' name='description'/>
    <meta content='http://www.web3d.org/x3d/content/examples/Vrml2Sourcebook/Chapter30-Scripts/Figure30.4ScriptSpiralingBallTrace.x3d' name='identifier'/>
    <meta content='X3D-Edit 3.3, https://savage.nps.edu/X3D-Edit' name='generator'/>
    <meta content='../../license.html' name='license'/>
  </head>
  <Scene>
    <Viewpoint description='spiraling ball' orientation='1 0 0 -0.3' position='0 3 8'/>
    <Viewpoint description='view from above' orientation='1 0 0 -1.57' position='0 6 0'/>
    <Viewpoint description='side view' orientation='0 1 0 1.57' position='6 1 0'/>
    <!-- Background nodes are usually best placed at the top of the scene since they have global effect and are bindable nodes. -->
    <Background groundAngle='1.309 1.570796' groundColor='0 0.1 0.3 0.3 0.3 0.6 0.4 0.4 0.6' skyAngle='1.309 1.571' skyColor='1 0 0.8 0.5 0 0.8 0 0 0.8'/>
    <Group>
      <Transform translation='0 -0.005 0'>
        <Shape>
          <Box size='2 0.01 4'/>
          <Appearance>
            <Material diffuseColor='0.7 0.7 0.7'/>
          </Appearance>
        </Shape>
      </Transform>
      <Transform translation='0 1.1 0'>
        <Transform DEF='BallTransform'>
          <Shape>
            <Appearance>
              <Material diffuseColor='1 0.3 0.3'/>
            </Appearance>
            <Sphere radius='0.1'/>
          </Shape>
        </Transform>
      </Transform>
      <TimeSensor DEF='Clock' cycleInterval='10' loop='true'/>
      <Script DEF='Mover'>
        <field accessType='inputOnly' name='set_fraction' type='SFFloat'/>
        <field accessType='outputOnly' name='value_changed' type='SFVec3f'/>
        <field accessType='initializeOnly' name='radius' type='SFFloat' value='1'/>
        <field accessType='initializeOnly' name='turns' type='SFFloat' value='4'/>
        <![CDATA[
ecmascript:

function set_fraction ( fraction, eventTime ) {
	value_changed[0] = radius * Math.sin( turns * fraction * 6.28 ); // x
	value_changed[1] = radius * Math.cos( turns * fraction * 6.28 ); // y
	value_changed[2] = turns * (fraction - 0.5);                     // z
}
]]>
      </Script>
      <Script DEF='Debug'>
        <field accessType='initializeOnly' name='label' type='SFString' value='fraction'/>
        <field accessType='inputOnly' name='set_float' type='SFFloat'/>
        <field accessType='outputOnly' name='string_changed' type='MFString'/>
        <![CDATA[
ecmascript:

function initalize( )
{
	string_changed[0] = label + ':';
}
function set_float( value, timestamp )
{
	string_changed[0] = label + ': ' + Math.round (value * 100) / 100;
}
]]>
      </Script>
      <Transform translation='0 0.5 0'>
        <Billboard axisOfRotation='0 0 0'>
          <Shape>
            <Text DEF='Message'>
              <FontStyle justify='"MIDDLE" "MIDDLE"' size='0.3'/>
            </Text>
            <Appearance>
              <Material diffuseColor='0 0 0' emissiveColor='0 1 1'/>
            </Appearance>
          </Shape>
        </Billboard>
      </Transform>
      <Transform rotation='1 0 0 1.57079' translation='0 1.1 0'>
        <Shape>
          <Appearance>
            <Material diffuseColor='0.5 0 0' transparency='0.7'/>
          </Appearance>
          <Cylinder height='4'/>
        </Shape>
      </Transform>
    </Group>
    <ROUTE fromField='fraction_changed' fromNode='Clock' toField='set_fraction' toNode='Mover'/>
    <ROUTE fromField='value_changed' fromNode='Mover' toField='set_translation' toNode='BallTransform'/>
    <ROUTE fromField='fraction_changed' fromNode='Clock' toField='set_float' toNode='Debug'/>
    <ROUTE fromField='string_changed' fromNode='Debug' toField='set_string' toNode='Message'/>
  </Scene>
</X3D>