001/* Demo for a signal plotter.
002
003 @Copyright (c) 1997-2014 The Regents of the University of California.
004 All rights reserved.
005
006 Permission is hereby granted, without written agreement and without
007 license or royalty fees, to use, copy, modify, and distribute this
008 software and its documentation for any purpose, provided that the
009 above copyright notice and the following two paragraphs appear in all
010 copies of this software.
011
012 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
013 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
014 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
015 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
016 SUCH DAMAGE.
017
018 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
019 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
020 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
021 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
022 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
023 ENHANCEMENTS, OR MODIFICATIONS.
024
025 PT_COPYRIGHT_VERSION_2
026 COPYRIGHTENDKEY
027 */
028package ptolemy.plot.demo;
029
030import ptolemy.plot.Plot;
031import ptolemy.plot.PlotApplet;
032
033///////////////////////////////////////////////////////////////////
034//// PlotDemo
035
036/**
037 Plot a variety of test signals.
038
039 @author Edward A. Lee
040 @version $Id$
041 @since Ptolemy II 0.2
042 @Pt.ProposedRating red (eal)
043 @Pt.AcceptedRating red (cxh)
044 */
045@SuppressWarnings("serial")
046public class PlotDemo extends PlotApplet {
047    ///////////////////////////////////////////////////////////////////
048    ////                         public methods                    ////
049
050    /**
051     * Return a string describing this applet.
052     */
053    @Override
054    public String getAppletInfo() {
055        return "PlotDemo 2.0: Demo of Plot.\n" + "By: Edward A. Lee\n "
056                + "($Id$)";
057    }
058
059    /**
060     * Initialize the applet.  Here we step through an example of what the
061     * the applet can do.
062     */
063    @Override
064    public void init() {
065        super.init();
066
067        Plot plot = (Plot) plot();
068
069        plot.setTitle("Line Plot Demo");
070        plot.setYRange(-4, 4);
071        plot.setXRange(0, 100);
072        plot.setXLabel("time");
073        plot.setYLabel("value");
074        plot.addYTick("-PI", -Math.PI);
075        plot.addYTick("-PI/2", -Math.PI / 2);
076        plot.addYTick("0", 0);
077        plot.addYTick("PI/2", Math.PI / 2);
078        plot.addYTick("PI", Math.PI);
079        plot.setMarksStyle("none");
080        plot.setImpulses(true);
081
082        boolean first = true;
083
084        for (int i = 0; i <= 100; i++) {
085            plot.addPoint(0, i, 5 * Math.cos(Math.PI * i / 20), !first);
086            plot.addPoint(1, i, 4.5 * Math.cos(Math.PI * i / 25), !first);
087            plot.addPoint(2, i, 4 * Math.cos(Math.PI * i / 30), !first);
088            plot.addPoint(3, i, 3.5 * Math.cos(Math.PI * i / 35), !first);
089            plot.addPoint(4, i, 3 * Math.cos(Math.PI * i / 40), !first);
090            plot.addPoint(5, i, 2.5 * Math.cos(Math.PI * i / 45), !first);
091            plot.addPoint(6, i, 2 * Math.cos(Math.PI * i / 50), !first);
092            plot.addPoint(7, i, 1.5 * Math.cos(Math.PI * i / 55), !first);
093            plot.addPoint(8, i, 1 * Math.cos(Math.PI * i / 60), !first);
094            plot.addPoint(9, i, 0.5 * Math.cos(Math.PI * i / 65), !first);
095            first = false;
096        }
097    }
098}