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

Get Random Location and Colors

import java.util.Vector;


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 x=(int) (dimensions.left+(Math.round(width*Math.random())));
      int y=(int) (*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())]);
    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