Image img = ImageViewer.getImage();
int width=img.getWidth();
int height=img.getHeight();
int p=width*1/2;
int q=height*1/2;
int []a= {1,-1,-1,-1,1,-1,-1,1,-1,1,1,1,1,1,-1,-1,1,-1};//A random array with 1 or -1
for(int i:a) {
for(int x=p;x<width&&x>0;x+=i) {
for(int y=q;y<height&&y>0;y+=i) {
img.setPixelColor(x, y, Color.BLACK);
}
}
}
I want to draw random dots starting from the center of a blank image. The dots should travel randomly up, down, left or right until one leaves the border of the image. Here's what I have done so far, which doesn't work at all.
Aucun commentaire:
Enregistrer un commentaire