Curve Animation : Animation « Advanced Graphics « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JavaFX
25.JDK 6
26.JDK 7
27.JNDI LDAP
28.JPA
29.JSP
30.JSTL
31.Language Basics
32.Network Protocol
33.PDF RTF
34.Reflection
35.Regular Expressions
36.Scripting
37.Security
38.Servlets
39.Spring
40.Swing Components
41.Swing JFC
42.SWT JFace Eclipse
43.Threads
44.Tiny Application
45.Velocity
46.Web Services SOA
47.XML
Java » Advanced Graphics » Animation 




Curve Animation
Curve Animation

import java.awt.*;
import java.applet.*;
import graph.*;
/*************************************************************************
**
**    Applet example0
**                                              Version 1.0   January 1996
**
**************************************************************************
**    Copyright (C) 1996 Leigh Brookshaw
**
**    This program is free software; you can redistribute it and/or modify
**    it under the terms of the GNU General Public License as published by
**    the Free Software Foundation; either version 2 of the License, or
**    (at your option) any later version.
**
**    This program is distributed in the hope that it will be useful,
**    but WITHOUT ANY WARRANTY; without even the implied warranty of
**    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
**    GNU General Public License for more details.
**
**    You should have received a copy of the GNU General Public License
**    along with this program; if not, write to the Free Software
**    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**************************************************************************
**
**
*************************************************************************/

public class example0 extends Applet implements Runnable {

      Graph2D graph;
      DataSet data;
      double max;
      double min;
      int steps;
      Thread thread;

      public void init() {
        int i;
        int j;

        graph = new Graph2D();

        setLayoutnew BorderLayout() );
        add("Center", graph);

        graph.framecolor = new Color(0,0,0);
        graph.borderTop = 0;
        graph.borderBottom = 1;
        graph.borderLeft = 0;
        graph.borderRight = 1;
        graph.setGraphBackground(new Color(50,50,200));

        max = 15*Math.PI;
        min = Math.PI;

        steps = 20;

        thread = new Thread(this);
        thread.start();

      }

      public void run() {
          DataSet data = null;
          int count = 1;
          int direction = 1;
          double range;
          Color c = new Color(255,255,0);
          
          while(true) {

              graph.detachDataSet(data);
              data = null;

              if(count >= steps direction = -1;
              else
              if(count <= )     direction = 1;

              count += direction;

              range = min + (max-min)*count/steps;

//              System.out.println("Range="+range);

              data = sinx(range);

//              data.xmax =  max;
//              data.xmin = -max;
              data.ymax = 1.0;
              data.linecolor = c;              

              graph.repaint(75);

              try thread.sleep(150)}
              catch(Exception e) { }

          }

      }



      public DataSet sinx(double range) {
            int i, j;
            int np = 100;
            double data[] new double[2*np];
            double x, y;

            

            for(i=j=0; i<np; i++,j+=2) {
                x = (i-np/2)*range/(np/2);
                ifx == 0.0 )  y = 1.0;
                else           y = Math.sin(x)/x;
                data[j]   = x;
                data[j+1= y;
            }
            
            return graph.loadDataSet(data,np);


      }
      public static void main(String[] a){
         javax.swing.JFrame f = new javax.swing.JFrame();
         Applet app = new example0();
         app.init();
         
         f.getContentPane().add (app);

         f.pack();
         f.setSize (new Dimension (500500));
         f.setVisible(true);
      }
}

           
       














Graph-CurveAnimation.zip( 183 k)
Related examples in the same category
1.Animated Graphics
2.Simple animation techniqueSimple animation technique
3.Custom move interaction, Switching interactions, Update world extent geometry and Scroll handlingCustom move interaction, Switching interactions, Update world extent geometry and Scroll handling
4.Scroll HandlingScroll Handling
5.ClockClock
6.Moving Button
7.Moving Button Container
8.Smooth Moves
9.Background Animation
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.