Skip to content

Instantly share code, notes, and snippets.

@dsch31
Created August 3, 2018 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsch31/08d99362e51678a32f7220238c9edaff to your computer and use it in GitHub Desktop.
Save dsch31/08d99362e51678a32f7220238c9edaff to your computer and use it in GitHub Desktop.
ArcheryTarget
package assigment2;
/*
*
* author: Atila Sabo
* Aug.03.2018.
* (my first solution)
*
https://see.stanford.edu/materials/icspmcs106a/13-assignment-2-simple-java.pdf
TASK 02
Suppose that you’ve been hired to produce a program that draws an image of an
archery target—or, if you prefer commercial applications, a logo for a national
department store chain—that looks like this:
This figure is simply three GOval objects, two red and one white, drawn in the correct
order. The outer circle should have a radius of one inch (72 pixels), the white circle
has a radius of 0.65 inches, and the inner red circle has a radius of 0.3 inches. The
figure should be centered in the window of a GraphicsProgram subclass.
*/
import acm.graphics.*;
import acm.program.*;
import java.awt.*;
public class ArcheryTarget extends GraphicsProgram {
// I'm sure there is some better, faster,... solution
private static final int OVAL_SIZE = 144;
public void run () {
// I first calculated 3 different position for each Oval
double x = (getWidth () - OVAL_SIZE) / 2;
double y = (getHeight () - OVAL_SIZE) / 2;
double x1 = (getWidth () - OVAL_SIZE*0.65) / 2;
double y1 = (getHeight () - OVAL_SIZE*0.65) / 2;
double x2 = (getWidth () - OVAL_SIZE*0.3) / 2;
double y2 = (getHeight () - OVAL_SIZE*0.3) / 2;
// Just create the Ovals
GOval bigRed = new GOval (x, y, OVAL_SIZE, OVAL_SIZE);
bigRed.setFilled(true);
bigRed.setFillColor(Color.RED);
add (bigRed);
GOval white = new GOval (x1, y1, OVAL_SIZE*0.65, OVAL_SIZE*0.65);
white.setFilled(true);
white.setFillColor(Color.WHITE);
add (white);
GOval smallRed = new GOval (x2, y2, OVAL_SIZE*0.3, OVAL_SIZE*0.3);
smallRed.setFilled(true);
smallRed.setFillColor(Color.RED);
add (smallRed);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment