import java.awt.*;
import javax.swing.*;
public class RandomCircles extends Canvas{
private static int delay;
private static int numCircles;
private static int frameSize;
public static Graphics g;
public void paint(Graphics g){
}
public static void main(String args[]){
frameSize = 800;
numCircles = 1;
delay = 5;
RandomCircles circles = new RandomCircles();
JFrame frame = new JFrame("Random Circles");
frame.setBounds(0, 0, frameSize, frameSize);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(circles);
frame.setVisible(true);
drawAllCircles();
}
private static void drawAllCircles(){
for(int j = 0; j < numCircles; j++){
int red = (int)(256 * Math.random());
int green = (int)(256 * Math.random());
int blue = (int)(256 * Math.random());
Color color = new Color(red, green, blue);
int radius = (int)((frameSize / 4 + 1) * Math.random());
int xCenter = radius + (int)((frameSize - 2 * radius + 1) * Math.random());
int yCenter = radius + (int)((frameSize - 2 * radius + 1) * Math.random());
drawOneCircle(xCenter, yCenter, radius, color);
}
}
public static void drawOneCircle(int xCenter, int yCenter, int radius, Color color){
g.setColor(color);
for(int angle = 360; angle >= 1; angle--){
double radians = (angle + 90)* Math.PI / 180;
int xEdge = xCenter + (int)(Math.sin(radians) * radius);
int yEdge = yCenter - (int)(Math.sin(radians) * radius);
try{
Thread.sleep(delay);
} catch(InterruptedException e){}
}
}
}
bearcoyote1 0 Newbie Poster
zeroliken 79 Nearly a Posting Virtuoso
bearcoyote1 0 Newbie Poster
zeroliken 79 Nearly a Posting Virtuoso
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.