petite/src/wombat/scheme/libraries/TurtleAPI.java
public static void updateTurtle(String id, String fun, String[] args) {
//		// <DEBUG>
//		System.out.println("live-turtle: " + id + "::" + fun + Arrays.toString(args));
//		// </DEBUG>
		
		// Initialize turtle frame if necessary.
		if (tframe == null) 
			tframe = new TurtleFrame();
		
		// Reset the display when it's closed.
		if (!tframe.isVisible()) {
			for (TurtleData t : LiveTurtles.values())
				t.Live = false;
			LiveLines.clear();
		}
		
		// Revisiblify the frame.
		tframe.setVisible(true);
		
		// Spawn is a special case
		if ("spawn".equals(fun)) {
			LiveTurtles.put(id, new TurtleData(
				Double.parseDouble(args[0]),
				-1.0 * Double.parseDouble(args[1]),
				Double.parseDouble(args[2]),
				"down".equals(args[3]),
				new Color(
					Integer.parseInt(args[4]),
					Integer.parseInt(args[5]),
					Integer.parseInt(args[6])
				)));
		}
			
        // Otherwise, verify that we've already seen that turtle.
		else if (!LiveTurtles.containsKey(id)) {
			throw new IllegalArgumentException("Unable to resume live turtle state (missing ID). Live turtles must be on before the turtle is spawned.");
		}
		
		// Finally, process any other sort of command.
		
		// Move one of the turtles
		else if ("move".equals(fun)) {
			double new_x = Double.parseDouble(args[0]);
			double new_y = -1.0 * Double.parseDouble(args[1]);
			
			TurtleData t = LiveTurtles.get(id);
			
			if (t.Pen) LiveLines.add(new LineData(0, t.X, t.Y, new_x, new_y, t.C));
			t.X = new_x;
			t.Y = new_y;
			t.Live = true;
		}
		
		// Turn one of the turtles
		else if ("turn".equals(fun)) {
			LiveTurtles.get(id).R = Double.parseDouble(args[0]);
			LiveTurtles.get(id).Live = true;
		}
		
		// Update the pen state (up/down)
		else if ("pen".equals(fun)) {
			LiveTurtles.get(id).Pen = "down".equals(args[0]);
			LiveTurtles.get(id).Live = true;
		}
		
		// Update the pen color
		else if ("pen-color".equals(fun)) {
			LiveTurtles.get(id).C = new Color(
				Integer.parseInt(args[0]),
				Integer.parseInt(args[1]),
				Integer.parseInt(args[2])
			);
			LiveTurtles.get(id).Live = true;
		}
		
		// Reset after a block
		else if ("block-reset".equals(fun)) {
			TurtleData t = LiveTurtles.get(id);
			
			t.X = Double.parseDouble(args[0]);
			t.Y = -1.0 * Double.parseDouble(args[1]);
			t.R = Double.parseDouble(args[2]);
			t.Pen = "down".equals(args[3]);
			t.C = new Color(
				Integer.parseInt(args[4]),
				Integer.parseInt(args[5]),
				Integer.parseInt(args[6])
			);
			t.Live = true;
		}
		
		// Move one of the turtles
		else {
			throw new IllegalArgumentException("Unable to record turtle state, unknown function: " + fun);
		}
		
		// Update the display.
		tframe.update(LiveTurtles, LiveLines);
		try { Thread.sleep((int) (1000 * Pause)); } catch(InterruptedException ex) {}
	}
/**
	 * Update a live turtle.
	 * @param val The first part is the turtle id, the rest are parameters.
	 */
Update a live turtle.
@param val The first part is the turtle id, the rest are parameters.
Update a live turtle . @param val The first part is the turtle id the rest are parameters .
public static void updateTurtle(String id, String fun, String[] args) {
		if (tframe == null) 
			tframe = new TurtleFrame();
		if (!tframe.isVisible()) {
			for (TurtleData t : LiveTurtles.values())
				t.Live = false;
			LiveLines.clear();
		}
		tframe.setVisible(true);
		if ("spawn".equals(fun)) {
			LiveTurtles.put(id, new TurtleData(
				Double.parseDouble(args[0]),
				-1.0 * Double.parseDouble(args[1]),
				Double.parseDouble(args[2]),
				"down".equals(args[3]),
				new Color(
					Integer.parseInt(args[4]),
					Integer.parseInt(args[5]),
					Integer.parseInt(args[6])
				)));
		}
		else if (!LiveTurtles.containsKey(id)) {
			throw new IllegalArgumentException("Unable to resume live turtle state (missing ID). Live turtles must be on before the turtle is spawned.");
		}
		else if ("move".equals(fun)) {
			double new_x = Double.parseDouble(args[0]);
			double new_y = -1.0 * Double.parseDouble(args[1]);
			TurtleData t = LiveTurtles.get(id);
			if (t.Pen) LiveLines.add(new LineData(0, t.X, t.Y, new_x, new_y, t.C));
			t.X = new_x;
			t.Y = new_y;
			t.Live = true;
		}
		else if ("turn".equals(fun)) {
			LiveTurtles.get(id).R = Double.parseDouble(args[0]);
			LiveTurtles.get(id).Live = true;
		}
		else if ("pen".equals(fun)) {
			LiveTurtles.get(id).Pen = "down".equals(args[0]);
			LiveTurtles.get(id).Live = true;
		}
		else if ("pen-color".equals(fun)) {
			LiveTurtles.get(id).C = new Color(
				Integer.parseInt(args[0]),
				Integer.parseInt(args[1]),
				Integer.parseInt(args[2])
			);
			LiveTurtles.get(id).Live = true;
		}
		else if ("block-reset".equals(fun)) {
			TurtleData t = LiveTurtles.get(id);
			t.X = Double.parseDouble(args[0]);
			t.Y = -1.0 * Double.parseDouble(args[1]);
			t.R = Double.parseDouble(args[2]);
			t.Pen = "down".equals(args[3]);
			t.C = new Color(
				Integer.parseInt(args[4]),
				Integer.parseInt(args[5]),
				Integer.parseInt(args[6])
			);
			t.Live = true;
		}
		else {
			throw new IllegalArgumentException("Unable to record turtle state, unknown function: " + fun);
		}
		tframe.update(LiveTurtles, LiveLines);
		try { Thread.sleep((int) (1000 * Pause)); } catch(InterruptedException ex) {}
	}
public static void updateTurtle ( String id , String fun , String [ ] args ) { if ( tframe == null ) tframe = new TurtleFrame ( ) ; if ( ! tframe . isVisible ( ) ) { for ( TurtleData t : LiveTurtles . values ( ) ) t . Live = false ; LiveLines . clear ( ) ; } tframe . setVisible ( true ) ; if ( "spawn" . equals ( fun ) ) { LiveTurtles . put ( id , new TurtleData ( Double . parseDouble ( args [ 0 ] ) , - 1.0 * Double . parseDouble ( args [ 1 ] ) , Double . parseDouble ( args [ 2 ] ) , "down" . equals ( args [ 3 ] ) , new Color ( Integer . parseInt ( args [ 4 ] ) , Integer . parseInt ( args [ 5 ] ) , Integer . parseInt ( args [ 6 ] ) ) ) ) ; } else if ( ! LiveTurtles . containsKey ( id ) ) { throw new IllegalArgumentException ( "Unable to resume live turtle state (missing ID). Live turtles must be on before the turtle is spawned." ) ; } else if ( "move" . equals ( fun ) ) { double new_x = Double . parseDouble ( args [ 0 ] ) ; double new_y = - 1.0 * Double . parseDouble ( args [ 1 ] ) ; TurtleData t = LiveTurtles . get ( id ) ; if ( t . Pen ) LiveLines . add ( new LineData ( 0 , t . X , t . Y , new_x , new_y , t . C ) ) ; t . X = new_x ; t . Y = new_y ; t . Live = true ; } else if ( "turn" . equals ( fun ) ) { LiveTurtles . get ( id ) . R = Double . parseDouble ( args [ 0 ] ) ; LiveTurtles . get ( id ) . Live = true ; } else if ( "pen" . equals ( fun ) ) { LiveTurtles . get ( id ) . Pen = "down" . equals ( args [ 0 ] ) ; LiveTurtles . get ( id ) . Live = true ; } else if ( "pen-color" . equals ( fun ) ) { LiveTurtles . get ( id ) . C = new Color ( Integer . parseInt ( args [ 0 ] ) , Integer . parseInt ( args [ 1 ] ) , Integer . parseInt ( args [ 2 ] ) ) ; LiveTurtles . get ( id ) . Live = true ; } else if ( "block-reset" . equals ( fun ) ) { TurtleData t = LiveTurtles . get ( id ) ; t . X = Double . parseDouble ( args [ 0 ] ) ; t . Y = - 1.0 * Double . parseDouble ( args [ 1 ] ) ; t . R = Double . parseDouble ( args [ 2 ] ) ; t . Pen = "down" . equals ( args [ 3 ] ) ; t . C = new Color ( Integer . parseInt ( args [ 4 ] ) , Integer . parseInt ( args [ 5 ] ) , Integer . parseInt ( args [ 6 ] ) ) ; t . Live = true ; } else { throw new IllegalArgumentException ( "Unable to record turtle state, unknown function: " + fun ) ; } tframe . update ( LiveTurtles , LiveLines ) ; try { Thread . sleep ( ( int ) ( 1000 * Pause ) ) ; } catch ( InterruptedException ex ) { } }
Update a live turtle.
Update a live turtle .
//		// <DEBUG> //		System.out.println("live-turtle: " + id + "::" + fun + Arrays.toString(args)); //		// </DEBUG> // Initialize turtle frame if necessary. // Reset the display when it's closed. // Revisiblify the frame. // Spawn is a special case // Otherwise, verify that we've already seen that turtle. // Finally, process any other sort of command. // Move one of the turtles // Turn one of the turtles // Update the pen state (up/down) // Update the pen color // Reset after a block // Move one of the turtles // Update the display.