Skip to content

Instantly share code, notes, and snippets.

@filmibuff
Created April 25, 2013 22:42
Show Gist options
  • Save filmibuff/5463827 to your computer and use it in GitHub Desktop.
Save filmibuff/5463827 to your computer and use it in GitHub Desktop.
Here's my code. By setting a max_circles constant, this program can be possibly extended to draw more circles with just a minor change on adding a calculation to determine each circle's radius which could be radius-=(radius/MAX_CIRCLES).
import acm.graphics.*;
import acm.program.*;
import java.awt.*;
public class Target2 extends GraphicsProgram {
private static final int MAX_CIRCLES=3;
private static final int PIXELS_PER_INCH=72;
public void run() {
/* Set Initial Radius */
double radius=1;
drawTarget(radius);
}
private void drawTarget(double radius){
radius*=PIXELS_PER_INCH;
for(int i=0; i<MAX_CIRCLES; i++){
double x=(getWidth()/2)-radius;
double y=(getHeight()/2)-radius;
GOval circle=new GOval(x, y, 2*radius, 2*radius);
circle.setFilled(true);
if (i%2==0){
circle.setColor(Color.RED);
}
else{
circle.setColor(Color.WHITE);
}
add(circle);
radius-=0.35*PIXELS_PER_INCH;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment