예제 #1
1
  /*
   * sets the colormap to Rainbow
   */
  private void setColorModelRainbow() {
    // Copy in the default colors
    for (int i = 0; i < tableSize; i++) {
      cm_red[i] = puke_red[i];
      cm_green[i] = puke_green[i];
      cm_blue[i] = puke_blue[i];
    }

    // Set rainbow for attribute colors
    float maxHue = 0.8f;
    float hue = 0;
    float delta = maxHue / attrSize;
    int rainbowColor;
    for (int i = startColor; i <= endColor; ++i, hue += delta) {
      rainbowColor = Color.HSBtoRGB(hue, 1.0f, 1.0f);
      cm_red[i] = (byte) ((rainbowColor >> 16) & 0xff);
      cm_green[i] = (byte) ((rainbowColor >> 8) & 0xff);
      cm_blue[i] = (byte) ((rainbowColor >> 0) & 0xff);
    }

    colorModel = new IndexColorModel(8, tableSize, cm_red, cm_green, cm_blue);
  }
예제 #2
0
  /**
   * Sets the selected color of this panel.
   *
   * <p>If this panel is in RED, GREEN, or BLUE mode, then this method converts these values to RGB
   * coordinates and calls <code>setRGB</code>.
   *
   * <p>This method may regenerate the graphic if necessary.
   *
   * @param h the hue value of the selected color.
   * @param s the saturation value of the selected color.
   * @param b the brightness value of the selected color.
   */
  public void setHSB(float h, float s, float b) {
    if (Float.isInfinite(h) || Float.isNaN(h))
      throw new IllegalArgumentException("The hue value (" + h + ") is not a valid number.");
    // hue is cyclic, so it can be any value:
    while (h < 0) h++;
    while (h > 1) h--;

    if (s < 0 || s > 1)
      throw new IllegalArgumentException("The saturation value (" + s + ") must be between [0,1]");
    if (b < 0 || b > 1)
      throw new IllegalArgumentException("The brightness value (" + b + ") must be between [0,1]");

    if (hue != h || sat != s || bri != b) {
      if (mode == ColorPicker.HUE || mode == ColorPicker.BRI || mode == ColorPicker.SAT) {
        float lastHue = hue;
        float lastBri = bri;
        float lastSat = sat;
        hue = h;
        sat = s;
        bri = b;
        if (mode == ColorPicker.HUE) {
          if (lastHue != hue) {
            regenerateImage();
          }
        } else if (mode == ColorPicker.SAT) {
          if (lastSat != sat) {
            regenerateImage();
          }
        } else if (mode == ColorPicker.BRI) {
          if (lastBri != bri) {
            regenerateImage();
          }
        }
      } else {

        Color c = new Color(Color.HSBtoRGB(h, s, b));
        setRGB(c.getRed(), c.getGreen(), c.getBlue());
        return;
      }

      Color c = new Color(Color.HSBtoRGB(hue, sat, bri));
      red = c.getRed();
      green = c.getGreen();
      blue = c.getBlue();

      regeneratePoint();
      repaint();
      fireChangeListeners();
    }
  }
  private Color getThreadBlockColor(BumpThread bt) {
    if (bt == null) return Color.BLACK;

    synchronized (thread_colors) {
      Color c = thread_colors.get(bt);
      if (c == null) {
        double v;
        int ct = thread_colors.size();
        if (ct == 0) v = 0;
        else if (ct == 1) v = 1;
        else {
          v = 0.5;
          int p0 = ct - 1;
          int p1 = 1;
          for (int p = p0; p > 1; p /= 2) {
            v /= 2.0;
            p0 -= p1;
            p1 *= 2;
          }
          if ((p0 & 1) == 0) p0 = 2 * p1 - p0 + 1;
          v = v * p0;
        }
        float h = (float) (v * 0.8);
        float s = 0.7f;
        float b = 1.0f;
        int rgb = Color.HSBtoRGB(h, s, b);
        rgb |= 0xc0000000;
        c = new Color(rgb, true);
        thread_colors.put(bt, c);
      }
      return c;
    }
  }
예제 #4
0
 private Color changeColor() {
   // Commands to change the colors of the two Yin Yangs randomly
   // to some other color
   return new Color(
       Color.HSBtoRGB(
           randomNumber.nextFloat(), randomNumber.nextFloat(), randomNumber.nextFloat()));
 }
예제 #5
0
  @NotNull
  public static Icon colorize(@NotNull final Icon source, @NotNull Color color, boolean keepGray) {
    float[] base = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null);

    final BufferedImage image =
        UIUtil.createImage(source.getIconWidth(), source.getIconHeight(), Transparency.TRANSLUCENT);
    final Graphics2D g = image.createGraphics();
    source.paintIcon(null, g, 0, 0);
    g.dispose();

    final BufferedImage img =
        UIUtil.createImage(source.getIconWidth(), source.getIconHeight(), Transparency.TRANSLUCENT);
    int[] rgba = new int[4];
    float[] hsb = new float[3];
    for (int y = 0; y < image.getRaster().getHeight(); y++) {
      for (int x = 0; x < image.getRaster().getWidth(); x++) {
        image.getRaster().getPixel(x, y, rgba);
        if (rgba[3] != 0) {
          Color.RGBtoHSB(rgba[0], rgba[1], rgba[2], hsb);
          int rgb = Color.HSBtoRGB(base[0], base[1] * (keepGray ? hsb[1] : 1f), base[2] * hsb[2]);
          img.getRaster()
              .setPixel(x, y, new int[] {rgb >> 16 & 0xff, rgb >> 8 & 0xff, rgb & 0xff, rgba[3]});
        }
      }
    }

    return createImageIcon(img);
  }
예제 #6
0
 public static Color brightnessAdjust(Color original, float brightness) {
   float[] hsb = getHSB(original);
   hsb[2] = brightness;
   if (hsb[2] < 0.0f) hsb[2] = 0.0f;
   else if (hsb[2] > 1.0f) hsb[2] = 1.0f;
   int newRGB = Color.HSBtoRGB(hsb[0], hsb[1], hsb[2]);
   return new Color(newRGB);
 }
예제 #7
0
 public static Color saturationAdjust(Color original, float saturation) {
   float[] hsb = getHSB(original);
   hsb[1] = saturation;
   if (hsb[1] < 0.0f) hsb[1] = 0.0f;
   else if (hsb[1] > 1.0f) hsb[1] = 1.0f;
   int newRGB = Color.HSBtoRGB(hsb[0], hsb[1], 1.0f);
   return new Color(newRGB);
 }
예제 #8
0
 public void generateColorWheel() {
   for (int index = 0; index < myPixels.length; index++) {
     if (myAlphas[index] != 0) {
       myPixels[index] =
           myAlphas[index]
               | 0xffffff & Color.HSBtoRGB(myHues[index], mySat[index], myBrightness);
     }
   }
   newPixels();
 }
예제 #9
0
  @Nullable
  private Color gatherRGB() {
    try {
      final int r = Integer.parseInt(myRed.getText());
      final int g = Integer.parseInt(myGreen.getText());
      final int b = Integer.parseInt(myBlue.getText());

      //noinspection UseJBColor
      return isRGBMode()
          ? new Color(r, g, b)
          : new Color(Color.HSBtoRGB(((float) r) / 360f, ((float) g) / 100f, ((float) b) / 100f));
    } catch (Exception ignore) {
    }
    return null;
  }
 @SubscribeEvent
 public void onClientRender(TickEvent.RenderTickEvent event) {
   if (event.phase == TickEvent.Phase.END) {
     Minecraft mc = Minecraft.getMinecraft();
     ScaledResolution res = new ScaledResolution(mc);
     int width = res.getScaledWidth();
     int height = res.getScaledHeight();
     FontRenderer fontRenderer = mc.fontRendererObj;
     mc.entityRenderer.setupOverlayRendering();
     if (strobeLinger > 0F) {
       GL11.glPushMatrix();
       {
         GL11.glDisable(GL11.GL_TEXTURE_2D);
         GL11.glEnable(GL11.GL_BLEND);
         GL11.glBegin(GL11.GL_QUADS);
         {
           GL11.glColor4f(1F, 1F, 1F, strobeLinger);
           GL11.glVertex2f(width, 0);
           GL11.glVertex2f(0, 0);
           GL11.glVertex2f(0, height);
           GL11.glVertex2f(width, height);
         }
         GL11.glEnd();
         GL11.glDisable(GL11.GL_BLEND);
         GL11.glEnable(GL11.GL_TEXTURE_2D);
       }
       GL11.glPopMatrix();
       strobeLinger -= (ConfigHandler.flashyMode < 3 ? 0.01F : 0.2F);
     }
     if (!tutorialText.equals("")) {
       if (tutorialTime > System.currentTimeMillis()) {
         String[] str = BetterUtils.getWordWrappedString(70, tutorialText);
         long difference = tutorialTime - System.currentTimeMillis();
         if (difference > 9000) difference = 10000 - difference;
         else if (difference > 1000) difference = 1000;
         GL11.glPushMatrix();
         {
           GL11.glDisable(GL11.GL_TEXTURE_2D);
           GL11.glTranslatef(width / 2 - 100, -50 + (difference / 20), 0F);
           GL11.glEnable(GL11.GL_BLEND);
           GL11.glBegin(GL11.GL_QUADS);
           {
             GL11.glColor4f(0F, 0F, 0F, .75F);
             GL11.glVertex2f(180, 0);
             GL11.glVertex2f(0, 0);
             GL11.glVertex2f(0, 4 + str.length * 5);
             GL11.glVertex2f(180, 4 + str.length * 5);
           }
           GL11.glEnd();
           GL11.glDisable(GL11.GL_BLEND);
           GL11.glEnable(GL11.GL_TEXTURE_2D);
           GL11.glScalef(.5F, .5F, 0F);
           for (int i = 0; i < str.length; i++)
             fontRenderer.drawStringWithShadow(
                 str[i], 180 - fontRenderer.getStringWidth(str[i]) / 2, 5 + i * 10, 0xFFFFFF);
         }
         GL11.glPopMatrix();
       } else {
         tutorialText = "";
         tutorialTime = 0;
       }
     }
     if (FileDownloader.isDownloading) {
       GL11.glPushMatrix();
       {
         GL11.glDisable(GL11.GL_TEXTURE_2D);
         GL11.glTranslatef(width / 2 - 50, height - height / 4 + 26, 0F);
         GL11.glEnable(GL11.GL_BLEND);
         GL11.glBegin(GL11.GL_QUADS);
         {
           GL11.glColor4f(0F, 0F, 0F, .8F);
           GL11.glVertex2f(100, 0);
           GL11.glVertex2f(0, 0);
           GL11.glVertex2f(0, 4);
           GL11.glVertex2f(100, 4);
         }
         GL11.glEnd();
         GL11.glBegin(GL11.GL_QUADS);
         {
           GL11.glColor4f(1F, 1F, 1F, .5F);
           GL11.glVertex2f(FileDownloader.downloadPercent * 100F, 0);
           GL11.glVertex2f(0, 0);
           GL11.glVertex2f(0, 4);
           GL11.glVertex2f(FileDownloader.downloadPercent * 100F, 4);
         }
         GL11.glEnd();
         GL11.glDisable(GL11.GL_BLEND);
         GL11.glEnable(GL11.GL_TEXTURE_2D);
       }
       GL11.glPopMatrix();
       fontRenderer.drawStringWithShadow(
           BetterUtils.getTranslatedString("overlay.downloading")
               + ": "
               + FileDownloader.nowDownloading,
           width / 2
               - fontRenderer.getStringWidth(
                       BetterUtils.getTranslatedString("overlay.downloading")
                           + ": "
                           + FileDownloader.nowDownloading)
                   / 2,
           height - height / 4 + 15,
           0xFFFF33);
     }
     if (!SoundHandler.nowPlaying.equals("")) {
       if (SoundHandler.nowPlaying.startsWith("Error:")) {
         fontRenderer.drawStringWithShadow(
             SoundHandler.nowPlaying,
             width / 2 - fontRenderer.getStringWidth(SoundHandler.nowPlaying) / 2,
             height - height / 4,
             0x990000);
         return;
       } else if (SoundHandler.nowPlaying.startsWith("Info:")) {
         fontRenderer.drawStringWithShadow(
             SoundHandler.nowPlaying,
             width / 2 - fontRenderer.getStringWidth(SoundHandler.nowPlaying) / 2,
             height - height / 4,
             0xFFFF33);
         return;
       }
       float f3 = (float) SoundHandler.nowPlayingInt;
       int l1 = Color.HSBtoRGB(f3 / 50.0F, 0.7F, 0.6F) & 16777215;
       int k1 = (int) (f3 * 255.0F / 20.0F);
       if (k1 > 255) k1 = 255;
       fontRenderer.drawStringWithShadow(
           BetterUtils.getTranslatedString("overlay.nowplaying") + ": " + SoundHandler.nowPlaying,
           width / 2
               - fontRenderer.getStringWidth(
                       BetterUtils.getTranslatedString("overlay.nowplaying")
                           + ": "
                           + SoundHandler.nowPlaying)
                   / 2,
           height - height / 4,
           l1 + (k1 << 24 & -16777216));
     }
   }
 }
예제 #11
0
 public void draw(Graphics g, int x, int y, int scale) {
   float saturate = (float) (this.quantity / Peas.MAX_QUANTITY);
   saturate = saturate < 0.1 ? 0.1f : saturate;
   g.setColor(new Color(Color.HSBtoRGB(8.9f, saturate, 0.8f)));
   g.fillRoundRect(x, y, scale, scale, scale, scale);
 }
예제 #12
0
 public static FlatColor hsb(double hueAngle, double saturation, double value, double alpha) {
   int rgb = Color.HSBtoRGB((float) hueAngle / 360, (float) saturation, (float) value);
   return new FlatColor(rgb, alpha);
 }
예제 #13
0
  /** Regenerates the image. */
  private synchronized void regenerateImage() {
    int size =
        Math.min(
            MAX_SIZE,
            Math.min(
                getWidth() - imagePadding.left - imagePadding.right,
                getHeight() - imagePadding.top - imagePadding.bottom));

    if (mode == ColorPicker.BRI || mode == ColorPicker.SAT) {
      float bri2 = this.bri;
      float sat2 = this.sat;
      float radius = ((float) size) / 2f;
      float hue2;
      float k = 1.2f; // the number of pixels to antialias
      for (int y = 0; y < size; y++) {
        float y2 = (y - size / 2f);
        for (int x = 0; x < size; x++) {
          float x2 = (x - size / 2f);
          double theta = Math.atan2(y2, x2) - 3 * Math.PI / 2.0;
          if (theta < 0) theta += 2 * Math.PI;

          double r = Math.sqrt(x2 * x2 + y2 * y2);
          if (r <= radius) {
            if (mode == ColorPicker.BRI) {
              hue2 = (float) (theta / (2 * Math.PI));
              sat2 = (float) (r / radius);
            } else { // SAT
              hue2 = (float) (theta / (2 * Math.PI));
              bri2 = (float) (r / radius);
            }
            row[x] = Color.HSBtoRGB(hue2, sat2, bri2);
            if (r > radius - k) {
              int alpha = (int) (255 - 255 * (r - radius + k) / k);
              if (alpha < 0) alpha = 0;
              if (alpha > 255) alpha = 255;
              row[x] = row[x] & 0xffffff + (alpha << 24);
            }
          } else {
            row[x] = 0x00000000;
          }
        }
        image.getRaster().setDataElements(0, y, size, 1, row);
      }
    } else if (mode == ColorPicker.HUE) {
      float hue2 = this.hue;
      for (int y = 0; y < size; y++) {
        float y2 = ((float) y) / ((float) size);
        for (int x = 0; x < size; x++) {
          float x2 = ((float) x) / ((float) size);
          row[x] = Color.HSBtoRGB(hue2, x2, y2);
        }
        image.getRaster().setDataElements(0, y, image.getWidth(), 1, row);
      }
    } else { // mode is RED, GREEN, or BLUE
      int red2 = red;
      int green2 = green;
      int blue2 = blue;
      for (int y = 0; y < size; y++) {
        float y2 = ((float) y) / ((float) size);
        for (int x = 0; x < size; x++) {
          float x2 = ((float) x) / ((float) size);
          if (mode == ColorPicker.RED) {
            green2 = (int) (x2 * 255 + .49);
            blue2 = (int) (y2 * 255 + .49);
          } else if (mode == ColorPicker.GREEN) {
            red2 = (int) (x2 * 255 + .49);
            blue2 = (int) (y2 * 255 + .49);
          } else {
            red2 = (int) (x2 * 255 + .49);
            green2 = (int) (y2 * 255 + .49);
          }
          row[x] = 0xFF000000 + (red2 << 16) + (green2 << 8) + blue2;
        }
        image.getRaster().setDataElements(0, y, size, 1, row);
      }
    }
    repaint();
  }
예제 #14
0
 private void setHSBValue(float h, float s, float b, int opacity) {
   //noinspection UseJBColor
   Color rgb = new Color(Color.HSBtoRGB(h, s, b));
   setColor(ColorUtil.toAlpha(rgb, opacity), this);
 }
예제 #15
0
class PanelForSquare extends JPanel implements Runnable, MouseListener, ActionListener {

  /** */
  private static final long serialVersionUID = 1L;

  Random randomNumber = new Random();
  // Int variable maxChange is the largest amount by which dX and dY
  // can change by when they collide.  This speed limiter is to prevent
  // Them from bouncing around the screen in an absurd manner, which
  // would prevent them from being clicked properly
  int maxChange = 3;

  // Starting parameters for the first MyYinYang object
  int yin1X = 100;
  int yin1Y = 100;
  int yin1Width = 150;
  int yin1Height = 150;

  // The four random directions in which the yinYangs will travel.
  // The deltas for X and Y 1 are multiplied by -1 so that it goes to the
  // top left to prevent them from colliding and scaling too early
  int deltaX1 = (randomNumber.nextInt(maxChange) + 1) * -1;
  int deltaY1 = (randomNumber.nextInt(maxChange) + 1) * -1;
  int deltaX2 = randomNumber.nextInt(maxChange) + 1;
  int deltaY2 = randomNumber.nextInt(maxChange) + 1;

  // Initial parameters for the second yinYang object
  int yin2X = 600;
  int yin2Y = 600;
  int yin2Width = 90;
  int yin2Height = 90;

  // Four int variables which track if the mouse click is
  // inside of either shape
  int x1Clicked, y1Clicked, x2Clicked, y2Clicked;

  // Points currently scored in the game
  int points = 0;

  // Remaining amount of times you can miss a target before the game ends
  int misses = 3;

  // New font object to alter how the text is displayed on the panel
  Font font = new Font("Sans-Serif", Font.BOLD, 35);

  // The two MyYinYang objects being initially created with the
  // previously defined stats
  MyYinYang yin1 = new MyYinYang(yin1X, yin1Y, yin1Width, yin1Height);
  MyYinYang yin2 = new MyYinYang(yin2X, yin2Y, yin2Width, yin2Height);

  // Frame for game over screen
  final JFrame frame = new JFrame();
  JPanel panel = new JPanel();

  // Two color objects which start out being randomly generated
  Color color1 =
      new Color(
          Color.HSBtoRGB(
              randomNumber.nextFloat(), randomNumber.nextFloat(), randomNumber.nextFloat()));
  Color color2 =
      new Color(
          Color.HSBtoRGB(
              randomNumber.nextFloat(), randomNumber.nextFloat(), randomNumber.nextFloat()));

  // Panel size
  public static final int PANEL_WIDTH = 1000;
  public static final int PANEL_HEIGHT = 800;

  // Variable to display how much time is left in seconds as the time value is in the thousands
  Double timeDisplay = 0.0;

  // Degrees by which to rotate the shape
  double degrees = 0;

  // How much time is left in the game
  Integer timeLeft = 12000;

  private void initTimer() {
    Timer timer;
    timer = new Timer(timeLeft, this);
    timer.setInitialDelay(0);
    timer.start();
  }

  public PanelForSquare() {
    setPreferredSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
    setBackground(Color.white);

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

  @Override
  // TODO Auto-generated method stub
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;

    // Draws the two initial two YinYang symbols on the frame
    g2.setColor(color1);
    if (timeLeft < 6000) {
      g2.rotate(degrees, yin1X + (yin1Width / 2), yin1Y + (yin1Height / 2));
    }
    g2.fill(new MyYinYang(yin1X, yin1Y, yin1Width, yin1Height));
    if (timeLeft < 6000) {
      g2.rotate(-degrees, yin1X + (yin1Width / 2), yin1Y + (yin1Height / 2));
    }
    g2.setColor(color2);
    if (timeLeft < 6000) {
      g2.rotate(degrees, yin2X + (yin2Width / 2), yin2Y + (yin2Height / 2));
    }
    g2.fill(new MyYinYang(yin2X, yin2Y, yin2Width, yin2Height));
    if (timeLeft < 6000) {
      g2.rotate(-degrees, yin2X + (yin2Width / 2), yin2Y + (yin2Height / 2));
    }

    // Alters and prints the text on the screen
    g2.setColor(Color.BLACK);
    g2.setFont(font);
    g2.drawString("Score", 700, 25);
    g2.drawString(Integer.toString(points), 700, 75);
    g2.drawString("Misses", 800, 25);
    g2.drawString(Integer.toString(misses), 800, 75);
    g2.drawString("Time Left", 700, 110);
    timeDisplay = timeLeft / 100.0;
    g2.drawString(timeDisplay.toString(), 700, 160);
  }

  public void run() {
    // Mouse listener to check if the mouse has been clicked
    addMouseListener(this);
    while (true) {
      // Changes the next X and Y value for each
      // shape according the their defined delta values
      yin1X += deltaX1;
      yin1Y += deltaY1;
      yin2X += deltaX2;
      yin2Y += deltaY2;

      // Makes the shapes bounce faster the longer the game elapses
      // Also decreases the score appropriately
      if (timeLeft < 9000) {
        maxChange = 4;
        points -= 1;
      } else if (timeLeft < 7500) {
        maxChange = 6;
        points -= 2;
      } else if (timeLeft < 6000) {
        maxChange = 7;
        points -= 3;
      } else if (timeLeft < 4500) {
        maxChange = 8;
        points -= 4;
      } else if (timeLeft < 3000) {
        maxChange = 10;
        points -= 5;
      }

      if (timeLeft == 0 || misses <= 0) {
        JOptionPane.showMessageDialog(frame, "Game over. Your final score is:  " + points);
        int status = 0;
        System.exit(status);
      }

      // Method to check if either shape has hit the edge of the panel yet
      calculateEdges();

      // Method to check if the two objects have collided with each other
      checkForCollision();

      degrees += .2;
      timeLeft--;
      // Calls PaintComponent again to redraw the screen
      repaint();
      try {
        Thread.sleep(10);
      } catch (InterruptedException ex) {
      }
    }
  }

  // Method to check if the two YinYang shapes have collided with each other,
  // and subsequently perform scaling operations if they have
  private void checkForCollision() {
    // Creates two MyYinYang objects with the already used coordinates
    // for use in the changing of color, direction, and scale once they
    // have collided
    yin1 = new MyYinYang(yin1X, yin1Y, yin1Width, yin1Height);
    yin2 = new MyYinYang(yin2X, yin2Y, yin2Width, yin2Height);

    if (hasCollided(yin1)) {
      // If the two shapes have collided, then the
      // shapes will reverse direction to go on until they
      // hit the edges of the screen
      // The reason the directions are not random
      // is because if they don't bounce away
      // from each other, they keep colliding
      // until they fly off of the screen

      deltaX1 = deltaX1 * -1;
      deltaY1 = deltaY1 * -1;
      deltaX2 = deltaX2 * -1;
      deltaY2 = deltaY2 * -1;

      // Commands to scale the two Yin Yang shapes based on the current
      // size when being compared to each other
      // IF SECTION IS IF YIN1 IS LARGER, ELSE IS IF THE SECOND IS LARGER
      double scale = 0;
      if (yin1.getWidth() >= yin2.getWidth()) {
        // Uses a do while loop so that it executes once, but if
        // the scale ends up being 0, it does it again
        do {
          // Scales by a random double between .5 and 1
          scale = ((randomNumber.nextDouble() + .5) - randomNumber.nextDouble());
        } while (scale <= 0);

        // Yin1Width is now set to it's original value times the scale
        // which has been set
        yin1Width = (int) (scale * yin1Width);
        // Simple equality so that the height and width are the same, since it is a circular object
        yin1Height = yin1Width;

        do {
          // Scales by a factor between 1 and 2
          scale = randomNumber.nextDouble() + 1;
        } while (scale <= 0);
        yin2Width = (int) (yin2Width * scale);
        yin2Height = yin2Width;
      } else {
        do {
          scale = randomNumber.nextDouble() + 1;
        } while (scale <= 0);
        yin1Width = (int) (yin1Width * scale);
        yin1Height = yin1Width;

        do {
          scale = ((randomNumber.nextDouble() + .5) - randomNumber.nextDouble());
        } while (scale <= 0);
        yin2Width = (int) (yin2Width * scale);
        yin2Height = yin2Width;
      }
    }
  }

  public boolean hasCollided(MyYinYang y1) {
    // Checks to see if the bounds of the first yinYang intersect anywhere within
    // the bounds of the second yinYang
    return y1.getBounds().intersects(yin2X, yin2Y, yin2Width, yin2Height);
  }

  private void calculateEdges() {

    // Calculates the new X and Y values to become the
    // destination once the edges are hit, taking
    // into account that they are randomly
    // scaled so that the speed changes
    // once the edges are hit

    int destX1 = randomNumber.nextInt(maxChange);
    int destY1 = randomNumber.nextInt(maxChange);
    int destX2 = randomNumber.nextInt(maxChange);
    int destY2 = randomNumber.nextInt(maxChange);

    // Checks to see if the right side of yin1
    // has hit right edge.  Bounces off on
    // the inverse angle in a different color if it has
    if ((yin1X + yin1Width) >= PANEL_WIDTH) {
      destX1 = randomNumber.nextInt(maxChange);
      deltaX1 = destX1 * -1;
      color1 = changeColor();
    }

    // Checks if the right side of yin2 has hit the right edge
    if ((yin2X + yin2Width) >= PANEL_WIDTH) {
      destX2 = randomNumber.nextInt(maxChange);
      deltaX2 = destX2 * -1;
      color2 = changeColor();
    }

    // Checks if the left side of yin1 has hit the left edge
    if (yin1X <= 0) {
      destX1 = randomNumber.nextInt(maxChange);
      deltaX1 = destX1;
      color1 = changeColor();
    }

    // Checks if the left side of yin2 has hit the left edge
    if (yin2X <= 0) {
      destX2 = randomNumber.nextInt(maxChange);
      deltaX2 = destX2;
      color2 = changeColor();
    }

    // Checks if the bottom side of yin1 has hit the bottom edge
    if ((yin1Y + yin1Height) >= PANEL_HEIGHT) {
      destY1 = randomNumber.nextInt(maxChange);
      deltaY1 = destY1 * -1;
      color1 = changeColor();
    }

    // Checks if the bottom side of yin2 has hit the bottom edge
    if ((yin2Y + yin2Height) >= PANEL_HEIGHT) {
      destY2 = randomNumber.nextInt(maxChange);
      deltaY2 = destY2 * -1;
      color2 = changeColor();
    }

    // Checks if the top side of yin1 has hit the top edge
    if (yin1Y <= 0) {
      destY1 = randomNumber.nextInt(maxChange);
      deltaY1 = destY1;
      color1 = changeColor();
    }

    // Checks if the top side of yin2 has hit the top edge
    if (yin2Y <= 0) {
      destY2 = randomNumber.nextInt(maxChange);
      deltaY2 = destY2;
      color2 = changeColor();
    }
  }

  private Color changeColor() {
    // Commands to change the colors of the two Yin Yangs randomly
    // to some other color
    return new Color(
        Color.HSBtoRGB(
            randomNumber.nextFloat(), randomNumber.nextFloat(), randomNumber.nextFloat()));
  }

  @Override
  public void mouseClicked(MouseEvent event) {}

  @Override
  public void mouseEntered(MouseEvent event) {}

  @Override
  public void mouseExited(MouseEvent arg0) {}

  @Override
  public void mousePressed(MouseEvent event) {
    x1Clicked = event.getX();
    y1Clicked = event.getY();
    x2Clicked = event.getX();
    y2Clicked = event.getY();

    // Conditions to update the score depending on speed and size of shapes
    if (yin1.getBounds().contains(x1Clicked, y1Clicked)) {
      if (yin1.getWidth() > 250) {
        if (deltaX1 < 2) {
          points += 1;
        } else if (deltaX1 < 3) {
          points += 3;
        } else if (deltaX1 < 6) {
          points += 5;
        } else {
          points += 7;
        }
      } else if (yin1.getWidth() > 150) {
        if (deltaX1 < 2) {
          points += 15;
        } else if (deltaX1 < 3) {
          points += 35;
        } else if (deltaX1 < 6) {
          points += 55;
        } else {
          points += 75;
        }
      } else {
        if (deltaX1 < 2) {
          points += 125;
        } else if (deltaX1 < 3) {
          points += 225;
        } else if (deltaX1 < 6) {
          points += 325;
        } else {
          points += 425;
        }
      }
    } else if (yin2.getBounds().contains(x2Clicked, y2Clicked)) {
      if (yin2.getWidth() > 250) {
        if (deltaX2 < 2) {
          points += 1;
        } else if (deltaX2 < 3) {
          points += 3;
        } else if (deltaX2 < 6) {
          points += 5;
        } else {
          points += 7;
        }
      } else if (yin2.getWidth() > 150) {
        if (deltaX2 < 2) {
          points += 15;
        } else if (deltaX2 < 3) {
          points += 35;
        } else if (deltaX2 < 6) {
          points += 55;
        } else {
          points += 75;
        }
      } else {
        if (deltaX2 < 2) {
          points += 125;
        } else if (deltaX2 < 3) {
          points += 225;
        } else if (deltaX2 < 6) {
          points += 325;
        } else {
          points += 425;
        }
      }
    } else {
      misses--;
    }
  }

  @Override
  public void mouseReleased(MouseEvent arg0) {}

  @Override
  public void actionPerformed(ActionEvent arg0) {}
}