home *** CD-ROM | disk | FTP | other *** search
Java Source | 1999-04-04 | 2.4 KB | 98 lines |
- /*
- * @(#)PizzaSag.java 1.0 1999/04/03
- *
- * Copyright (c) 1999, David Griffiths. All Rights Reserved.
- *
- * This software is the proprietary information of David Griffiths.
- * This source code may not be published or redistributed without the
- * express permission of the author.
- *
- * THE AUTHOR MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY
- * OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
- * PURPOSE, OR NON-INFRINGEMENT. THE AUTHOR SHALL NOT BE LIABLE FOR ANY DAMAGES
- * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
- * THIS SOFTWARE OR ITS DERIVATIVES.
- *
- */
-
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.Color;
- import java.lang.Math;
- import java.awt.*;
-
- public class PizzaSag extends java.applet.Applet implements Runnable {
- Image origImg, backImg;
- int w1, h1;
- Thread thrPizzaSag;
-
- public void start () {
- if (thrPizzaSag == null) {
- thrPizzaSag = new Thread (this);
- thrPizzaSag.start ();
- }
- }
-
- public void stop () {
- if (thrPizzaSag != null) {
- thrPizzaSag.stop ();
- thrPizzaSag = null;
- }
- }
-
- public void run () {
- loadImage ();
- int a, b, temp;
- backImg = createImage (w1, h1);
- Graphics backG = backImg.getGraphics();
- backG.setColor(Color.white);
- backG.drawImage(origImg, 0, 0, this);
- while (thrPizzaSag != null) {
- a = (int)(Math.random() * (double)w1);
- b = (int)(Math.random() * (double)w1);
- if (b < a) {
- temp = a;
- a = b;
- b = temp;
- }
- droop (backG, a, b);
- try {
- Thread.sleep (50);
- }
- catch (InterruptedException e) {}
- repaint ();
- }
- }
-
- public void loadImage () {
- MediaTracker tracker = new MediaTracker(this);
- String nextImage = getParameter ("image");
- origImg = getImage (getDocumentBase(), nextImage);
-
- tracker.addImage(origImg, 0);
-
- try {
- tracker.waitForID(0);
- }
- catch(InterruptedException e) {}
-
- w1 = origImg.getWidth (this);
- h1 = origImg.getHeight (this);
- }
-
- public void droop(Graphics g, int a, int b) {
- g.copyArea (a, 0, b - a, h1, 0, 1);
- g.drawLine (a, 0, b, 0);
- }
-
- public void update (Graphics g) {
- paint (g);
- }
-
- public void paint (Graphics g) {
- if (backImg != null)
- g.drawImage (backImg, 0, 0, this);
- }
- }
-