| /*
Butterfly demo
Copyright (c)
2002 Mirabilis Design Inc.
All rights reserved.
This source file, its machine readable form, and any representation
of the material contained herein are owned by Mirabilis Design.
These materials are proprietary and confidential and may not be
re-
produced in any form without the prior written permission of Mirabilis
Design.
MIRABILIS_COPYRIGHT_VERSION_1
COPYRIGHTENDKEY
@ProposedRating
Yellow (sa@mirabilisdesign.com)
@AcceptedRating Red (reviewmoderator@mirabilisdesign.com)
*/
package demo.signal_processing.Butterfly;
import VisualSim.actor.TypedCompositeActor;
import VisualSim.actor.TypedIOPort;
import VisualSim.actor.TypedIORelation;
import VisualSim.actor.lib.Expression;
import VisualSim.actor.lib.Ramp;
import VisualSim.actor.lib.conversions.PolarToCartesian;
import VisualSim.actor.lib.gui.XYPlotter;
import VisualSim.simulators.sdf.kernel.SDFDirector;
import VisualSim.kernel.util.IllegalActionException;
import VisualSim.kernel.util.NameDuplicationException;
import VisualSim.kernel.util.Workspace;
import VisualSim.plot.Plot;
import VisualSim.plot.PlotFrame;
//////////////////////////////////////////////////////////////////////////
//// Butterfly
/**
This class defines a VisualSim model that traces an elaborate curve
called the butterfly curve.
It was described by T. Fay, <i>American Mathematical Monthly</i>,
96(5),
May, 1989. Although users will usually prefer to define models using
MoML, this class illustrates how to define a model in Java.
@author Tony
Romas and Shankar Aiyar
@version $Id: Butterfly.java,v 1.26 2002/02/21 18:47:12 tr Exp $
@since VisualSim 0.4
*/
public class Butterfly extends TypedCompositeActor {
public Butterfly(Workspace
workspace)
throws IllegalActionException, NameDuplicationException {
super(workspace);
setName("Butterfly");
// Create the
director, and set the number of iterations to execute.
SDFDirector director = new SDFDirector(this, "director");
director.iterations.setExpression("2400");
setDirector(director);
// Create the
actors, and set their parameters.
// First, the source, which counts up from 0.0 in steps of pi/100.
Ramp ramp = new Ramp(this, "Ramp");
ramp.step.setExpression("PI/100.0");
// Next, the
expression, for which we have to create an input port.
Expression expression = new Expression(this, "Expression");
TypedIOPort expInput = new TypedIOPort(expression, "ramp");
expInput.setInput(true);
expression.expression.setExpression("-2.0*cos(4.0*ramp) + "
+ "exp(cos(ramp)) + (sin(ramp/12.0) * (sin(ramp/12.0))^4)");
// Next, a
conversion to use the ramp as an angle specifier,
// and the output of the expression as the vector length.
PolarToCartesian polarToCartesian =
new PolarToCartesian(this, "Polar to Cartesian");
// Finally,
the plotter.
XYPlotter xyPlotter = new XYPlotter(this, "xyPlotter");
xyPlotter.plot = new Plot();
xyPlotter.plot.setGrid(false);
xyPlotter.plot.setXRange(-3, 4);
xyPlotter.plot.setYRange(-4, 4);
// Make the
connections.
// The ports are public members of these classes.
// The first connection is a three way connection, so we have
// to create a relation and then link to it.
TypedIORelation node = (TypedIORelation) newRelation("node");
ramp.output.link(node);
expInput.link(node);
polarToCartesian.angle.link(node);
// The rest
of the connections are point-to-point, so we can use
// the connect() method.
connect(expression.output, polarToCartesian.magnitude);
connect(polarToCartesian.x, xyPlotter.inputX);
connect(polarToCartesian.y, xyPlotter.inputY);
}
} |