请帮忙。我正在尝试使用Java Random
类在绘图画布上绘制随机位置,大小,颜色等的螺旋。当我调用Random
方法时,我可以使drawCurvedSpiral
课程正常工作。但是,有时它会将部分螺旋打印在屏幕上。那么,我该如何防止这种情况发生呢?
以下就是我的......
import java.awt.Graphics;
import java.awt.Color;
import java.util.Random;
public class AbstractArt
{
public static void main(String[] args)
{
DrawingCanvas canvas = new DrawingCanvas();
Graphics g = canvas.getGraphics();
Random rand = new Random();
for (int i = 0; i < 10; i++)
{
int width = 25 + rand.nextInt(76);
int arc = 0 + rand.nextInt(361);
int x = rand.nextInt(canvas.getWidth()-width);
int y = rand.nextInt(canvas.getHeight()-width);
drawCurvedSpiral(g, x, y, width, width, arc, arc, getRandomCOlor());
}
}