Ответ 1
Вы просто используете общую часть рисования на холсте... затем укажите радиус, на который нужно нарисовать. Затем, используя "случайную" функцию, нарисуйте (x) количество точек внутри области круга, которую вы определили, используя радиус до тех пор, пока пользователь нажимает вниз. Если вам нужна более точная помощь, пожалуйста, дайте мне знать.
[Изменить] Это будет очень псевдокод. Но вы должны очень легко сделать код из этого.
// This needs to happen in the down press on the canvas
if(currentBrush == Brush.SPRAY_CAN){
int dotsToDrawAtATime = 20;
double brushRadius = 1.0; // This is however large they set the brush size, could be (1), could be whatever the max size of your brush is, e.g., (50), but set it based on what they choose
for (int i = 0; i < dotsToDrawAtATime; i++){
// Pick a random color for single dot to draw
// Get the circumference of the circle (2*pi*brushRadius), based on the X/Y that the user input when they pressed down. Pick a random spot inside that area, and draw a single dot. As this is a for loop, it will happen 20 different times for this one occurrence.
}
}
[Редактировать 2] Если вы собираетесь использовать это, я бы очень хотел рассмотреть возможность использования метода Iain_b. Пожалуйста, учтите его пост.
[Редактировать 3] Вот изображение... может быть, это поможет вам понять...
[Редактировать 4]
Здесь мой код обновлен с помощью lain_b, чтобы упростить его.
// This needs to happen in the down press on the canvas
if(currentBrush == Brush.SPRAY_CAN){
int dotsToDrawAtATime = 20;
double brushRadius = 1.0; // This is however large they set the brush size, could be (1), could be whatever the max size of your brush is, e.g., (50), but set it based on what they choose
for (int i = 0; i < dotsToDrawAtATime; i++){
// Pick a random color for single dot to draw
...
// Get the location to draw to
int x = touchedX + Random.nextGaussian()*brushRadius;
int y = touchedY + Random.nextGaussian()*brushRadius;
// Draw the point, using the random color, and the X/Y value
...
}
}