Hello World with 3d VRML
What is it
This model is a very simple example of how to write and run a Xholon application. Several xholon objects cooperate to write the words Hello and World a specified number of times.
This variation of Hello World also creates a 3d VRML file. VRML files are organized as trees, and it is quite straight-forward to write out a VRML tree from a Xholon composite structure tree.
How to use it
- Run the Java application through the Xhn GUI (org.primordion.xholon.app.Xhn.java), and select File --> Open --> HelloWorld --> HelloWorld_Vrml_xhn.xml.
- Expand the Controller node in the tree.
- Press the Start node.
- You should see a display of all the parameters that are set in the HelloWorld_xhn.xml file, followed by the words "Hello World" displayed five times in the console window, plus confirmation that a VRML file has been written (see below).
Hello World ! Hello World ! Hello World ! Hello World ! Hello World ! writing VRML file ...
Things to notice
Take a look at the HelloWorld_Vrml_xhn.xml configuration file in the config/HelloWorld folder. The UseVrml parameter is set to true.
After running the application, look at the Xholon/3d folder. Note the root.wrl file that has been created there. You can open it in any text editor. This file can be read by a variety of VRML tools, and displayed in 3d.
Things to try
If you have a VRML tool installed on your computer, open root.wrl using that tool. You will see a red sphere representing Hello, and a green sphere for World. Each sphere is labeled with the name of the xholon object (hello_1 and world_2).
Extending the model
If you know VRML, you can make various changes to VrmlWriterHelloWorld.java. The radius of the Hello sphere is currently 5 in the describeXholon() function. You could instead make the radius dependent on how many time steps have taken place, as shown below:
//v.write( 5 ); v.write( XholonTime.getTimeStep() );
Look at the few lines of code in AppHelloWorld_Vrml.java that begin with "if (useVrml)". This creates an instance of VrmlWriterHelloWorld, and calls its writeAsVrml() function, passing in the root xholon node in the composite structure tree.
writeWrlFile(IXholon xhNode) in VrmlWriterHelloWorld writes header information at the top of the VRML file, and then calls showStructure() in its superclass, which in turn recursively calls describeXholon(Writer out, IXholon xhNode).
Credits and references
For more information on VRML, see Wikipedia