Random Circles

This applet paints 100 random sized circles in random places. it used a drawCircle method that paints a circle based on the position of the centre and the radius. This method is called 100 times with randomly generated centre and radius. Note that the randomly generated numbers are converted to a limited range and changed to integers.

import java.applet.Applet;
import java.awt.*;

public class Circles extends Applet
{

int Xpos, Ypos, size;
public void init()

{
size=20;
}

public void paint (Graphics g)

{
for (int count=0;count<100;count++)

{
size = (int)(Math.random()*10);
Xpos= (int)(Math.random()*100+100);
Ypos= (int)(Math.random()*100+100);
drawCircle(g, Xpos,Ypos,size);
}

}

private void drawCircle(Graphics g, int x, int y, int radius)

{
g.drawOval(x-radius,y-radius,radius*2,radius*2);
}

}

This is a sample of the output:

circles.JPG
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License