Created
October 31, 2011 19:41
-
-
Save NatashaTheRobot/1328631 to your computer and use it in GitHub Desktop.
This is the solution to the Target problem from Assignment 2 of the Stanford CS106A Introduction to Programming Methodology Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* File: Target.java | |
* Name: | |
* Section Leader: | |
* ----------------- | |
* This file is the starter file for the Target problem. | |
*/ | |
import acm.graphics.*; | |
import acm.program.*; | |
import java.awt.*; | |
public class Target extends GraphicsProgram { | |
public void run() { | |
putOuterCircle(); | |
putMiddleCircle(); | |
putInnerCircle(); | |
} | |
private void putOuterCircle() { | |
int radius = 72; | |
int x = getWidth()/2 - radius/2; | |
int y = getHeight()/2 - radius/2; | |
GOval OuterCircle = new GOval (x, y, radius, radius); | |
OuterCircle.setColor(Color.RED); | |
OuterCircle.setFilled(true); | |
OuterCircle.setFillColor(Color.RED); | |
add(OuterCircle); | |
} | |
private void putMiddleCircle() { | |
double radius = 72*64/100; | |
double x = getWidth()/2 - radius/2; | |
double y = getHeight()/2 - radius/2; | |
GOval MiddleCircle = new GOval (x, y, radius, radius); | |
MiddleCircle.setColor(Color.WHITE); | |
MiddleCircle.setFilled(true); | |
MiddleCircle.setFillColor(Color.WHITE); | |
add(MiddleCircle); | |
} | |
private void putInnerCircle() { | |
double radius = 72*3/10; | |
double x = getWidth()/2 - radius/2; | |
double y = getHeight()/2 - radius/2; | |
GOval InnerCircle = new GOval (x, y, radius, radius); | |
InnerCircle.setColor(Color.RED); | |
InnerCircle.setFilled(true); | |
InnerCircle.setFillColor(Color.RED); | |
add(InnerCircle); | |
} | |
} |
I am taking cs101 at staford. Need Need help with coding "image expressions excercises" -week 3
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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);