[CSC 204] MercMan2 Help
Andrew J. Pounds
pounds_aj at mercer.edu
Tue Feb 2 03:03:41 EST 2010
Several of you asked me to send out pieces of my MercMan2 code so you
could see how I did the scaling. I have examples of how I called the
Ellipse, Rectangle and Line2D and BasicStroke methods below. Hopefully
this will help you finish off your MercMan2 lab. Please try to get it
to me by midnight tonight.
final int OLD_WINDOW_WIDTH = 300;
final int OLD_WINDOW_HEIGHT = 500;
g2.setColor(Color.BLACK);
g2.setStroke(new BasicStroke(3));
// Draw the head
// Ellipse2D.Double head = new Ellipse2D.Double(100, 0, 100,
150);
Ellipse2D.Double head = new Ellipse2D.Double(xLeft +
100/((double) OLD_WINDOW_WIDTH) * width ,
yTop,
100/((double)
OLD_WINDOW_WIDTH) * width,
150/((double)
OLD_WINDOW_HEIGHT) * height);
g2.draw(head);
// Draw the mouth
// Rectangle mouth = new Rectangle(140, 130, 20, 5);
Rectangle mouth = new Rectangle(xLeft + (int) (140/((double)
OLD_WINDOW_WIDTH) * width),
yTop + (int) (130/((double)
OLD_WINDOW_HEIGHT) * height),
(int) (20/((double)
OLD_WINDOW_WIDTH) * width),
(int) (5/((double)
OLD_WINDOW_HEIGHT) * height));
g2.setColor(Color.RED);
g2.fill(mouth);
g2.setStroke(new BasicStroke( (float) 20.0 * (float) height
/ (float) OLD_WINDOW_HEIGHT));
// Draw Left Arm
// Line2D.Double leftArm = new Line2D.Double(100, 160, 0, 190);
Line2D.Double leftArm = new Line2D.Double(xLeft +
100/((double) OLD_WINDOW_WIDTH) * width,
yTop +
160/((double) OLD_WINDOW_HEIGHT) * height,
xLeft + 0/((double)
OLD_WINDOW_WIDTH) * width,
yTop +
190/((double) OLD_WINDOW_HEIGHT) * height);
g2.draw(leftArm);
// g2.setStroke(new BasicStroke(40));
g2.setStroke(new BasicStroke( (float) 40.0 * (float) width /
(float) OLD_WINDOW_WIDTH));
// Draw Left Leg
// Line2D.Double leftLeg = new Line2D.Double(120, 300, 100, 500);
Line2D.Double leftLeg = new Line2D.Double(xLeft +
120/((double) OLD_WINDOW_WIDTH) * width,
yTop + 300/((double) OLD_WINDOW_HEIGHT) * height,
xLeft + 100/((double) OLD_WINDOW_WIDTH) * width,
yTop + 500/((double) OLD_WINDOW_HEIGHT) * height);
--
Andrew J. Pounds, Ph.D. (pounds at theochem.mercer.edu)
Associate Professor of Chemistry and Computer Science
Mercer University, Macon, GA 31207 (478) 301-5627
More information about the csc204
mailing list