Get Random Location and Colors : Color « 2D Graphics « Android






Get Random Location and Colors

  
import java.util.Vector;

import android.graphics.Color;
import android.graphics.Point;
import android.graphics.Rect;

class ShakeUtil {
  public static Vector<Point> getRandomLocations(Rect dimensions,int count) {
    Vector<Point> randoms=new Vector<Point>(count);
    for (int i=0;i<count;i++) {
      int width=dimensions.right-dimensions.left;
      int height=dimensions.bottom-dimensions.top;
      int x=(int) (dimensions.left+(Math.round(width*Math.random())));
      int y=(int) (dimensions.top+(Math.round(height*Math.random())));
      randoms.add(new Point(x,y));
    }

    return randoms;
  }
  
  public static Vector<Integer> getRandomColors(int count) {
    String[] barvy={"red", "blue", "green", "gray", "cyan", "magenta", "lightgray", "darkgray"};
    Vector<Integer> randoms=new Vector<Integer>(count);
    for (int i=0;i<count;i++) {
      int c=Color.parseColor(barvy[(int) Math.round((barvy.length-1)*Math.random())]);
      randoms.add(Integer.valueOf(c));
    }
    return randoms;    
  }
}

   
    
  








Related examples in the same category

1.Using solid color to paint
2.Set color for Paint
3.Create Color from RGB value
4.Load Color from resource xml file
5.Using View to display color
6.Change check box color
7.Color Filters
8.Color Matrix Sample
9.HSV To Color
10.RGB To Color
11.lighten Color
12.Returns the complimentary (opposite) color.
13.brighter a color
14.darker a color
15.extends View to create ColorCircle
16.Increase Red
17.Increase Contrast, Reduce Brightness
18.Decrease Saturation