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