Note: This is an HTML facsimile of the actual Java code. To see the code itself in its most current version, you can look at WobblyCirclePlugIn.java in the directory \Hyperwire\kinetix\hyperc1\userPlugIns\.

package kinetix.hyperc1.userPlugIns;

/********************************************************************************\
**                                                                              **
**  (C) Copyright 1997 by Autodesk, Inc.                                        **
**                                                                              **
**  This program is copyrighted by Autodesk, Inc. and is licensed to you under  **
**  the following conditions.  You may not distribute or publish the source     **
**  code of this program in any form.  You may incorporate this code in object  **
**  form in derivative works provided such derivative works are (i.) are de-    **
**  signed and intended to work solely with Autodesk, Inc. products, and (ii.)  **
**  contain Autodesk's copyright notice "(C) Copyright 1997 by Autodesk, Inc."  **
**                                                                              **
**  AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.  AUTODESK SPE-  **
**  CIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR  **
**  A PARTICULAR USE.  AUTODESK, INC.  DOES NOT WARRANT THAT THE OPERATION OF   **
**  THE PROGRAM WILL BE UNINTERRUPTED OR ERROR FREE.                            **
**                                                                              **
\********************************************************************************/

/**************************************************************************
WobblyCirclePlugIn:  Sub-class of Hyperwire object example

Author:  Amalgamated YoYoDyne PlugIns, Inc.(Hyperwire demonstration file)

Version:  1.0

**************************************************************************/

import kinetix.hyperc1.runtime.*;
import java.applet.Applet;
import java.awt.Rectangle;

/*** The Object class ***/
public class WobblyCirclePlugIn extends CirclePlugIn	
	{
	private long Time, Speed;
	private int Wobble, Occilation;
	private Rectangle originalRect;

	public void piEventAppletInit(Applet theApplet)	throws HwException
		{
		originalRect = piGetVisualRunService().siGetAbsRect();
		piGetVisualRunService().siPlugInWantsTicks(true);
		}

	/* in case of dragable object, update state and redraw */
	public Rectangle piEventDragTranslate(int xOffset, int yOffset) throws HwException
		{
		originalRect.x += xOffset;
		originalRect.y += yOffset;

		Rectangle update = originalRect;
		update.width += java.lang.Math.abs(xOffset) + Occilation;
		update.height += java.lang.Math.abs(yOffset) + Occilation;

		return update;
		}

	public void piEventRefreshDaemonTick(long timeNow, RefreshDaemon worldMover ) throws HwException
	      {
		if ( timeNow > (Time + Speed) )
			{
			Time = timeNow;
			Rectangle oldRect = ((VisualRunService) mRunService).siGetAbsRect();
			Rectangle newRect = oldRect;

			switch ((int)(java.lang.Math.random()*4))
				{
				case 0:
					newRect.x += (int)(java.lang.Math.random()*Occilation) + 1;
					break;
				case 1:
					newRect.x -= (int)(java.lang.Math.random()*Occilation) + 1;
					break;
				case 2:
					newRect.y += (int)(java.lang.Math.random()*Occilation) + 1;
					break;
				case 3:
					newRect.y -= (int)(java.lang.Math.random()*Occilation) + 1;
					break;
				}

			if ( newRect.x > (originalRect.x + Wobble) ) newRect.x = originalRect.x;
			if ( newRect.x < (originalRect.x - Wobble) ) newRect.x = originalRect.x;
			if ( newRect.y > (originalRect.y + Wobble) ) newRect.y = originalRect.y;
			if ( newRect.y < (originalRect.y - Wobble) ) newRect.y = originalRect.y;

			piGetVisualRunService().siSetAbsRect(newRect);
 			worldMover.invalidateRect( newRect.x-Occilation, newRect.y-Occilation, newRect.width+(2*Occilation), newRect.height+(2*Occilation) );
			}
		}

	/* Properties interface */
	public void fiSetSpeed( long Speed )
		{
		this.Speed = Speed;
		}

	public void fiSetWobble( int Wobble )
		{
		this.Wobble = Wobble;
		}

	public void fiSetOccilation( int Occilation)
		{
		this.Occilation = Occilation;
		}

	/* Wire Interface */
	public void wiSetSpeed( long Speed )
		{
		this.Speed = Speed;
		}

	public long wiGetSpeed()
		{
		return Speed;
		}

	}