I am trying to draw a cupola circles at random positions in an Android application.
I draw them on a bitmap and then draw that bitmap on the canvas. This is the function where a draw the circles:
private void drawRandomCircles(int numOfCircles) {
Canvas c = new Canvas(b);
Paint cPaint = new Paint;
cPaitn.setColor(Color.RED);
for(int i = 0; i < numOfCircles; i++) {
int x = Math.Random % 100;
int y = Math.Random % 100;
c.drawCircle(x, y, 20, cPaint)
}
}
The Bitmap b is global.
And after calling this function I just draw the bitmap in the onDraw method.
Now the problem is that I only get one circle drawn on the screen, no matter the size of numOfCircles.
Any clue what is happening here?
That code doesn’t even compile. What is
new Paint;for instance?I suggest you log your arguments to
drawCircleto make sure you draw them on different locations. IfMath.Randomfor instance is a field, it would change in between reads, which would put the circles on top of each other.If you intended to write
Math.random()the error is thatMath.random()returns a value between 0 and 1. You may want to use