Beispiel #1
0
  /** Creates the background shapes */
  protected void makeBackground() {
    int backgroundShapes = (int) (new Random().nextFloat() * 50) + 70;
    for (int i = 0; i < backgroundShapes; ++i) {
      Random random = new Random();

      // Get random values
      float y = 4 + random.nextFloat() * 2;
      float x = i + random.nextFloat() * 2 - 5;
      float size = random.nextFloat() * 8;
      float speed = random.nextFloat() * 0.02f - 0.01f;

      // Every second element is placed at the bottom
      if (i % 2 == 0) {
        y *= -1;
      }

      // Create the rectangle
      Rectangle rect = new Rectangle(x, y, size, speed);

      // Set the color
      float[] colors = Util.getColorParts(getBackgroundColor());
      rect.setColor(colors[0], colors[1], colors[2], 1);

      // Add the element
      backgroundElements.add(rect);
    }
  }
Beispiel #2
0
 public void drawBackground(GL10 gl) {
   int color = Util.hex2Color(colors.get(4));
   float[] colors = Util.getColorParts(color);
   gl.glClearColor(colors[0], colors[1], colors[2], 1);
 }