Results 1 to 3 of 3
Thread: an explaination please!
- 07-23-2009, 02:19 AM #1
Member
- Join Date
- Jul 2009
- Posts
- 7
- Rep Power
- 0
an explaination please!
:confused:
Can someone please explain to me where they are getting the cx, cy values from. As far as I can tell they are never definied as values other then cx, cy.
I know this is probably the most retarded question in the history of time, but if you can explain it to me I would be very happy.
Java Code:/* File: RobotFace.java */ /* This program draws a robot face. */ import acm.graphics.*; import acm.program.*; import java.awt.*; public class tictac extends GraphicsProgram { /* Parameters for the drawing */ private static final int HEAD_WIDTH = 100; private static final int HEAD_HEIGHT = 150; private static final int EYE_RADIUS = 10; private static final int MOUTH_WIDTH = 60; private static final int MOUTH_HEIGHT = 20; public void run() { addFace(getWidth() / 2, getHeight() / 2); } /* Adds the entire face centered at (cx, cy) */ private void addFace(double cx, double cy) { addHead(cx, cy); addEye(cx - HEAD_WIDTH / 4, cy - HEAD_HEIGHT / 4); addEye(cx + HEAD_WIDTH / 4, cy - HEAD_HEIGHT / 4); addMouth(cx, cy + HEAD_HEIGHT / 4); } /* Adds the head centered at (cx, cy) */ private void addHead(double cx, double cy) { double x = cx - HEAD_WIDTH / 2; double y = cy - HEAD_HEIGHT / 2; GRect head = new GRect(x, y, HEAD_WIDTH, HEAD_HEIGHT); head.setFilled(true); head.setFillColor(Color.GRAY); add(head); } /* Adds an eye centered at (cx, cy) */ private void addEye(double cx, double cy) { double x = cx - EYE_RADIUS; double y = cy - EYE_RADIUS; GOval eye = new GOval(x, y, 2 * EYE_RADIUS, 2 * EYE_RADIUS); eye.setFilled(true); eye.setColor(Color.YELLOW); add(eye); } /* Adds a mouth centered at (cx, cy) */ private void addMouth(double cx, double cy) { double x = cx - MOUTH_WIDTH / 2; double y = cy - MOUTH_HEIGHT / 2; GRect mouth = new GRect(x, y, MOUTH_WIDTH, MOUTH_HEIGHT); mouth.setFilled(true); mouth.setColor(Color.WHITE); add(mouth); } }Last edited by sweetjava; 07-23-2009 at 02:20 AM. Reason: more info
- 07-23-2009, 02:29 AM #2
Member
- Join Date
- Jul 2009
- Posts
- 7
- Rep Power
- 0
its OK i get it, it's taking the values from the:
addFace(getWidth()/2, getHeight()/2);
right?
- 07-23-2009, 11:49 AM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,449
- Rep Power
- 16
Similar Threads
-
[SOLVED] Code Explaination Help
By greenco in forum New To JavaReplies: 2Last Post: 12-12-2008, 11:31 PM -
Tiles process flow explaination needed...
By abhishek paul in forum Web FrameworksReplies: 0Last Post: 04-29-2008, 04:02 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks