Curve Animation : Animation « Advanced Graphics « Java

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. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » Advanced Graphics » AnimationScreenshots 
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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.