import java.io.*; import java.util.*; import java.lang.Math.*; public class Swarm { public Swarm() { int radius = 20; int actors = 50; try { // output file FileOutputStream file = new FileOutputStream( "swarm.inc" ); BufferedOutputStream buf = new BufferedOutputStream( file ); PrintStream out = new PrintStream( buf ); // initialize positions Random R = new Random( 0 ); vector3D initial[] = new vector3D[actors+3]; for( int i = 0; i < actors; i++ ) { double x = ( R.nextDouble() - 0.5 ) * ( radius * 2 ); double y = ( R.nextDouble() - 0.5 ) * ( radius ); double z = ( R.nextDouble() - 0.5 ) * ( radius * 2 ); initial[i] = new vector3D( x, y, z ); System.out.println( "initial[" + i + "] = " + initial[i] ); } // duplicate first three points at end initial[actors] = initial[0]; initial[actors+1] = initial[1]; initial[actors+2] = initial[2]; // compute each actor's path Vector path = new Vector(); for( int i = 0; i < actors; i++ ) { // use 3 points spline3D spline = new spline3D(); vector3D local[] = new vector3D[4]; local[0] = initial[i]; local[1] = initial[i+1]; local[2] = initial[i+2]; local[3] = initial[i+3]; Vector result = spline.generate( local ); System.out.println( "adding " + result.size() + " steps" ); for( Enumeration e = result.elements(); e.hasMoreElements(); ) path.addElement( e.nextElement() ); } // how many? int count = path.size(); System.out.println( "path is " + count + " steps" ); // general information System.out.println( "WRITING..." ); out.println( "// GENERATED SWARM FILE" ); out.println( "" ); out.println( "#declare actors = " + actors + ";" ); out.println( "#declare points = " + count + ";" ); out.println( "" ); out.println( "#declare position = array[" + count + "][3]" ); out.println( "{" ); for( Enumeration e = path.elements(); e.hasMoreElements(); ) { vector3D point = (vector3D) e.nextElement(); out.println( " { " + point.x + ", \t" + point.y + ", \t" + point.z + " }," ); } out.println( "}" ); out.flush(); out.close(); System.out.println( "...DONE" ); } catch( Exception ex ) { System.out.println( ex.getMessage() ); ex.printStackTrace(); } } public static void main( String[] args ) { Swarm f = new Swarm(); } }