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 50 51 52 53
|
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.Random;
import javax.swing.JFrame;
public class FractalCircle extends JFrame {
FractalCircle()
{
this.setSize(500,500);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.setResizable(false);
}
Random r1 =new Random();
Random r2 =new Random();
Random r3 =new Random();
public void dessinerCercle(Graphics g, int x1, int y1, int radius, int level)
{
if (level == 0) return;
int x2 = x1;
int y2 = y1;
radius= radius+10;
g.setColor(new Color(r1.nextInt(255),r2.nextInt(255),r3.nextInt(255)));
g.drawOval(x1-radius/2, y1-radius/2, radius,radius);
dessinerCercle(g, x2, y2, radius, level - 1);
g.drawLine(0, 0, 500, 500);
}
public void paint(Graphics g) {
dessinerCercle(g, 250,250, 5, 200);
}
public static void main(String[] args) {
new FractalCircle().setVisible(true);
}
} |
Partager