circles
in
Programming Questions
•
1 year ago
i want to make a program of 10 circles such that the first
Circle has radius of 10 with center at (10,10), second Circle has radius of 20 with center at
(50,50), third has radius of 30 with center at (90,90) and so on. with random colors and after each circle is drawn the background should be changed .. any assistance ?
this is my code
Circle [] circles = new Circle[11];
void setup() {
size(600, 600);
background(255);
int radius = 10;
int centerX = 10;
int centerY = 10;
circles = new Circle[11];
for (int i=10; i < circles.length; i+=10)
circles[i] = new Circle(radius, centerX, centerY);
centerX += 40;
centerY += 40;
radius += 10;
}
void draw() {
for (int i=10; i < circles.length; i+=10)
circles[i].display();
}
//the below code should not be changed but the upper codes are mine
class Circle {
int centerX, centerY, radius;
color col;
Circle() {
centerX = 1;
centerY = 1;
radius = 1;
col = color(random(255), random(255), random(255));
}
Circle(int _radius, int _centerX, int _centerY) {
centerX = _centerX;
centerY = _centerY;
radius = _radius;
col = color(random(255), random(255), random(255));
}
void display() {
noStroke();
fill(col);
ellipseMode(RADIUS);
ellipse(centerX, centerY, radius, radius);
}
float area() {
return PI* radius * radius;
}
float circumference() {
return 2* PI * radius;
}
float diameter() {
return 2 * radius;
}
int compareTo(Circle other) {
if(radius > other.radius)
return 1;
if(radius < other.radius)
return -1;
return 0;
}
Circle bigger(Circle other) {
return null;
}
}
1