1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| import java.awt.*;
import ij.*;
import ij.gui.*;
import ij.process.*;
import ij.plugin.PlugIn;
import javax.swing.*;
import java.util.*;
import java.awt.geom.*;
import java.awt.*;
public class Icstest1 implements PlugIn {
public void run(String arg) {
int w = 600, h = 600;
ImageProcessor ip = new ColorProcessor(w, h);
ArrayList<Ellipse2D.Double> listCercles = new ArrayList<Ellipse2D.Double>();
int nombreDeCercles = 100;
double x,y;
double rayon = 20;
x = Math.random()*(600-2*rayon);
y = Math.random()*(578-2*rayon);
Ellipse2D.Double temp;
boolean ok = false;
listCercles.add(new Ellipse2D.Double(x,y,2*rayon,2*rayon));
int attempt = 0;
while ( listCercles.size()<nombreDeCercles) {
x = Math.random()*(600-2*rayon);
y = Math.random()*(578-2*rayon);
temp = new Ellipse2D.Double(x,y,2*rayon,2*rayon);
for (int j=0; j< listCercles.size();j++) {
if (!temp.intersects(listCercles.get(j).getBounds2D())) {
ok = true;
}
else {
ok = false;
break;
}
}
if (ok)
listCercles.add(temp);
}
ip.setColor(65);
ip.fillOval(100,100,100,100);
for (int i=0; i < nombreDeCercles;i++) {
ip.fill(listCercles.get(i));
}
new ImagePlus("Circle Test", ip).show();
}
} |
Partager