<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.0//EN" "https://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 =' https://www.web3d.org/specifications/x3d-3.0.xsd ' >
<head>
<component level='1name='Scripting'/>
<meta name='titlecontent='flowers2.x3d'/>
<meta name='creatorcontent='John Carlson'/>
<meta name='transcribercontent='John Carlson'/>
<meta name='createdcontent='23 January 2005'/>
<meta name='modifiedcontent='21 March 2018'/>
<meta name='descriptioncontent='2 random mathematical roses in spherical dimensions. rho = a + b * cos(c * theta) * cos(d * phi)'/>
<meta name='identifiercontent=' https://coderextreme.net/X3DJSONLD/src/main/data/flowers2.x3d '/>
<meta name='generatorcontent='manually written'/>
<meta name='licensecontent=' https://www.web3d.org/x3d/content/examples/license.html '/>
</head>
<!--

Index for ProtoDeclare definition: orbit

Index for DEF nodes: Clock, Orbit, OrbitCoordinates, OrbitPath, OrbitScript, OrbitTransform and Event Graph ROUTE Table
-->
<Scene>
<NavigationInfo/>
<Viewpoint description='Two mathematical orbitalsposition='0 0 50'/>
<Group>
<DirectionalLight direction='1 1 1'/>
<ProtoDeclare name='orbit'>
<ProtoInterface>
<field name='translationtype='SFVec3fvalue='-8 0 0accessType='inputOutput'/>
<field name='diffuseColortype='SFColorvalue='1 0.5 0accessType='inputOutput'/>
<field name='specularColortype='SFColorvalue='1 0.5 0accessType='inputOutput'/>
<field name='transparencytype='SFFloatvalue='0.75accessType='inputOutput'/>
</ProtoInterface>
<ProtoBody>
<Group>
<!-- ROUTE information for Clock node:  [from fraction_changed to OrbitScript.set_fraction ] [from fraction_changed to OrbitPath.set_fraction ] -->
<TimeSensor DEF='ClockcycleInterval='16loop='true'/>

<!-- ROUTE information for OrbitPath node:  [from Clock.fraction_changed to set_fraction ] [from value_changed to OrbitTransform.rotation ] -->
<OrientationInterpolator DEF='OrbitPathkey='0.0 0.50 1.0keyValue='1.0 0.0 0.0 0.0 1.0 0.0 0.0 3.14 1.0 0.0 0.0 6.28'/>

<!-- ROUTE information for OrbitTransform node:  [from OrbitPath.value_changed to rotation ] -->
<Transform DEF='OrbitTransform'>
<IS>
<connect nodeField='translationprotoField='translation'/>
</IS>
<Shape>
<Appearance>
<Material>
<IS>
<connect nodeField='diffuseColorprotoField='diffuseColor'/>
<connect nodeField='specularColorprotoField='specularColor'/>
<connect nodeField='transparencyprotoField='transparency'/>
</IS>
</Material>
</Appearance>
<!-- <IndexedFaceSet DEF="Orbit"
creaseAngle="0"> <Coordinate DEF="OrbitCoordinates"/> </IndexedFaceSet> here!!! -->

<!-- ROUTE information for Orbit node:  [from OrbitScript.coordIndexes to set_coordIndex ] -->
<IndexedFaceSet DEF='Orbitccw='falseconvex='falsecoordIndex='0 1 2 -1'>
<!-- ROUTE information for OrbitCoordinates node:  [from OrbitScript.coordinates to point ] -->
<Coordinate DEF='OrbitCoordinatespoint='0 0 1 0 1 0 1 0 0'/>
</IndexedFaceSet>
</Shape>
</Transform>
<field name='set_fractiontype='SFFloataccessType='inputOnly'/>
<field name='coordinatestype='MFVec3faccessType='outputOnly'/>
<field name='coordIndexestype='MFInt32accessType='outputOnly'/>
<field name='etype='SFFloatvalue='5accessType='inputOutput'/>
<field name='ftype='SFFloatvalue='5accessType='inputOutput'/>
<field name='gtype='SFFloatvalue='5accessType='inputOutput'/>
<field name='htype='SFFloatvalue='5accessType='inputOutput'/>
<field name='resolutiontype='SFInt32value='50accessType='inputOutput'/>
<![CDATA[
			
			ecmascript:

			var e = 5;
			var f = 5;
			var g = 5;
			var h = 5;
			var resolution = 100;

			function initialize() {
			     generateCoordinates();
			     var localci = [];
			     for (var i = 0; i < resolution-1; i++) {
				for (var j = 0; j < resolution-1; j++) {
				     localci.push(i*resolution+j);
				     localci.push(i*resolution+j+1);
				     localci.push((i+1)*resolution+j+1);
				     localci.push((i+1)*resolution+j);
				     localci.push(-1);
				}
			    }
			    coordIndexes = new MFInt32(localci);
			}

			function generateCoordinates() {
			     var theta = 0.0;
			     var phi = 0.0;
			     var delta = (2 * 3.141592653) / (resolution-1);
			     var localc = [];
			     for (var i = 0; i < resolution; i++) {
				for (var j = 0; j < resolution; j++) {
					var rho = e + f * Math.cos(g * theta) * Math.cos(h * phi);
					localc.push(new SFVec3f(
						rho * Math.cos(phi) * Math.cos(theta),
						rho * Math.cos(phi) * Math.sin(theta),
						rho * Math.sin(phi)
					));
					theta += delta;
				}
				phi += delta;
			     }
			     
			     coordinates = new MFVec3f(localc);
			}

			function set_fraction(fraction, eventTime) {
				var choice = Math.floor(Math.random() * 4);
				switch (choice) {
				case 0:
					e += Math.floor(Math.random() * 2) * 2 - 1;
					break;
				case 1:
					f += Math.floor(Math.random() * 2) * 2 - 1;
					break;
				case 2:
					g += Math.floor(Math.random() * 2) * 2 - 1;
					break;
				case 3:
					h += Math.floor(Math.random() * 2) * 2 - 1;
					break;
				}
				if (e < 1) {
					f = 10;
				}
				if (f < 1) {
					f = 10;
				}
				if (g < 1) {
					g = 4;
				}
				if (h < 1) {
					h = 4;
				}
				generateCoordinates();
			}
			      
]]>
</Script>
< ROUTE  fromNode=' OrbitScript' fromField='coordIndexes' toNode=' Orbit' toField='set_coordIndex'/>
< ROUTE  fromNode=' OrbitScript' fromField='coordinates' toNode=' OrbitCoordinates' toField='point'/>
< ROUTE  fromNode=' Clock' fromField='fraction_changed' toNode=' OrbitScript' toField='set_fraction'/>
< ROUTE  fromNode=' OrbitPath' fromField='value_changed' toNode=' OrbitTransform' toField='rotation'/>
< ROUTE  fromNode=' Clock' fromField='fraction_changed' toNode=' OrbitPath' toField='set_fraction'/>
</Group>
</ProtoBody>
</ProtoDeclare>
<ProtoInstance name='orbit'>
<fieldValue name='translationvalue='-8 0 0'/>
<fieldValue name='diffuseColorvalue='1 0.5 0'/>
<fieldValue name='specularColorvalue='1 0.5 0'/>
<fieldValue name='transparencyvalue='0.75'/>
</ProtoInstance>
<ProtoInstance name='orbit'>
<fieldValue name='translationvalue='8 0 0'/>
<fieldValue name='diffuseColorvalue='0 0.5 1'/>
<fieldValue name='specularColorvalue='0 0.5 1'/>
<fieldValue name='transparencyvalue='0.5'/>
</ProtoInstance>
</Group>
</Scene>
</X3D>
<!--

Index for ProtoDeclare definition: orbit

Index for DEF nodes: Clock, Orbit, OrbitCoordinates, OrbitPath, OrbitScript, OrbitTransform and Event Graph ROUTE Table
-->

Event Graph ROUTE Table entries with 5 ROUTE connections total, showing event model relationships for this scene.

Clock
TimeSensor
fraction_changed
SFFloat

ROUTE
event to
 
OrbitScript
Script
set_fraction
SFFloat
then OrbitScript
Script
coordinates
MFVec3f

ROUTE
event to
 
OrbitCoordinates
Coordinate
point
MFVec3f
  then OrbitScript
Script
coordIndexes
MFInt32

ROUTE
event to
 
Orbit
IndexedFaceSet
set_coordIndex
MFInt32
Clock
TimeSensor
fraction_changed
SFFloat

ROUTE
event to
 
OrbitPath
OrientationInterpolator
set_fraction
SFFloat
then OrbitPath
OrientationInterpolator
value_changed
SFRotation

ROUTE
event to
 
OrbitTransform
Transform
rotation
SFRotation


ProtoInstance

(No ROUTE connection found for this node)


ProtoInstance

(No ROUTE connection found for this node)


-->

<!-- Color legend: X3D terminology <X3dNode DEF='idName' field='value'/> matches XML terminology <XmlElement DEF='idName' attribute='value'/>
(Light-blue background: event-based behavior node or statement) (Grey background inside box: inserted documentation) (Magenta background: X3D Extensibility)
    <ProtoInstance name='ProtoName'> <field name='fieldName'/> </ProtoInstance> -->

<!-- For additional help information about X3D scenes, please see X3D Tooltips, X3D Resources, and X3D Scene Authoring Hints. -->