public void animate(float[] pts, float[] deltas, int index, int limit) {
   float newpt = pts[index] + deltas[index];
   if (newpt <= 0) {
     newpt = -newpt;
     deltas[index] = (float) (Math.random() * 3.0 + 2.0);
   } else if (newpt >= (float) limit) {
     newpt = 2.0f * limit - newpt;
     deltas[index] = -(float) (Math.random() * 3.0 + 2.0);
   }
   pts[index] = newpt;
 }
Exemple #2
0
  public void randomColor() {
    Pixel[][] pixels = this.getPixels2D();
    for (Pixel[] row : pixels) {
      for (Pixel currentPixel : row) {
        int randomRed, randomBlue, randomGreen;
        randomRed = (int) (Math.random() * 256);
        randomBlue = (int) (Math.random() * 256);
        randomGreen = (int) (Math.random() * 256);

        currentPixel.setBlue(randomBlue);
        currentPixel.setRed(randomRed);
        currentPixel.setGreen(randomGreen);
      }
    }
  }
 public void start() {
   Dimension size = getSize();
   for (int i = 0; i < animpts.length; i += 2) {
     animpts[i + 0] = (float) (Math.random() * size.width);
     animpts[i + 1] = (float) (Math.random() * size.height);
     deltas[i + 0] = (float) (Math.random() * 4.0 + 2.0);
     deltas[i + 1] = (float) (Math.random() * 4.0 + 2.0);
     if (animpts[i + 0] > size.width / 6.0f) {
       deltas[i + 0] = -deltas[i + 0];
     }
     if (animpts[i + 1] > size.height / 6.0f) {
       deltas[i + 1] = -deltas[i + 1];
     }
   }
   anim = new Thread(this);
   anim.setPriority(Thread.MIN_PRIORITY);
   anim.start();
 }