this will work as an application or an applet. its really cool.


Code:
import java.awt.*;
import java.util.*;

/**
 * Example6Applet
 *
 *based on Example6Applet from http://www.javaworld.com/javaworld/jw-03-1996/jw-03-animation.html
 *
 *
 *originally by Arthur van Hoff
 *modified by Thomas Dickerson
 */
public class SineAnimation extends java.applet.Applet implements Runnable {
   int frame;
   int delay;
   Thread animator;
   Random r;
   Dimension offDimension;
   Image offImage;
   Graphics offGraphics;
   boolean isApp;
   int fps;

   public SineAnimation(int i){fps = i; isApp = true;}
   public SineAnimation(){super(); isApp = false;}

   public void init() {
      if(!isApp){
         String str = getParameter("fps");
         fps = (str != null) ? Integer.parseInt(str) : 10;
      }
      delay = (fps > 0) ? (1000 / fps) : 100;
      r = new Random((new Date()).getTime());
   }

   public void start() {
      animator = new Thread(this);
      animator.start();
   }

   public void run() {
      long tm = System.currentTimeMillis();
      while (Thread.currentThread() == animator) {
         repaint();
         try {
            tm += delay;
            Thread.sleep(Math.max(0, tm - System.currentTimeMillis()));
         } catch (InterruptedException e) {
            break;
         }
         frame++;
      }
   }

   public void stop() {
      animator = null;
      offImage = null;
      offGraphics = null;
   }

   public void update(Graphics g) {
      Dimension d = getSize();

      if ((offGraphics == null) || (d.width != offDimension.width) || (d.height != offDimension.height)) {
         offDimension = d;
         offImage = createImage(d.width, d.height);
         offGraphics = offImage.getGraphics();
      }
      offGraphics.setColor(new Color((frame + 90)%256,(frame + 180)%256,(frame)%256));
      offGraphics.fillRect(0, 0, d.width, d.height);

      paintFrame(offGraphics);
      g.drawImage(offImage, 0, 0, null);
   }

   public void paint(Graphics g) {
      if (offImage != null) {
         g.drawImage(offImage, 0, 0, null);
      }
   }


   public void paintFrame(Graphics g) {
      Dimension d = getSize();
      int h = d.height / 2;
      for (int x = 0 ; x < d.width ; x++) {
         int y1 = (int)((1.0 + Math.sin((x - frame) * 0.04)) * h);
         int y2 = (int)((1.0 + Math.sin((x + frame) * 0.04)) * h);
         int height = getSize().height;
         int width = getSize().width;
         int col = (int)(256d * (Math.abs((double)y1-(double)y2)/(double)height));
         int col2 = (int)(frame+(256d*(double)x/(double)width))%256;
         int col3 = (col2 + frame/7) % 256;
         g.setColor(new Color(col2,col,col3));
         g.drawLine(x, y1, x, y2);
         g.setColor(Color.WHITE);
      }
   }

   public static void main(String args[]){
      Frame mwindow = new Frame();
      mwindow.setUndecorated(true);
      mwindow.setLayout(null);
      mwindow.setBounds(50,50,600,60);
      SineAnimation mySineAnimation = new SineAnimation(10);
      mwindow.add(mySineAnimation);
      mySineAnimation.setBounds(0,0,600,60);
      mwindow.setVisible(true);
      mySineAnimation.init();
      mySineAnimation.start();
   }
}
Care to give it a title and description that explain what it is? Wink It appears to animate the creation of a sine wave...
yes please, for those of use who do not happen to know Java/Javasript.
its eye candy.

however for those of you who dont know how to compile java I shall set up a demo page.

http://rancidmoose.5gigs.com/signature/sine.php?fps=10
Ooooh, very nice! I assume you can customize the moving background image being masked?
I could. Im not using a background image though ^^
Oh? Then that's just rectangles being drawn at variable coordinates? Very nice!
^^ its just lines being drawn at variable coordinates.

ps, did you notice the ?fps=10 at the end of the url? ^^
I did notice that... /me figured out how to write 10^100 in the url... Evil or Very Mad
o rly? 10e100 or something like that?

ps, if you want to use the applet on your own site, please give credit. the code is as follows:


Code:
<applet codebase="http://rancidmoose.5gigs.com/signature/" code="SineAnimation.class" archive="Sine.jar" width="500" height="50"><param name="fps" value="10"></applet>



height and width and fps are all adjustable and it will still work. try to keep a 10:1 ratio on the width:height though.
Awesome. What do you think of the name I came up with for it? ^_^
you are much better at being topic descriptive than I am.
Heh, I do my best. It comes with my penchant for naming and logoing projects.
KermMartian wrote:
Heh, I do my best. It comes with my penchant for naming and logoing projects.


yeah, too bad you aren't as good at coding and completing said projects... Evil or Very Mad
Finishing, I agree. Coding, I'm afraid I must disagree.
I did 10e100 and got applet crashed, lol. Its kinda cool to put a number like 1000 into the fps, it goes REALLY fast, but i doubt 1000 fps (it may generate them, but the monitor does not display them).
KermMartian wrote:
Finishing, I agree. Coding, I'm afraid I must disagree.


By coding I didn't mean quality, I mean quanity.
Harq wrote:
I did 10e100 and got applet crashed, 0x5. Its kinda cool to put a number like 1000 into the fps, it goes REALLY fast, but I doubt 1000 fps (it may generate them, but the monitor does not display them).


its all about delay length. of course once the delays are shorter than the time it takes to render you no longer notice the change in speed. And this takes into account how long it took to render last time along with the requested fps to calculator how long to delay.
LOL! Kerm! You added a filter to change all occurences of lol into lol!
it wasn't Kerm....
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement