Results 1 to 3 of 3
  1. #1
    sweetjava is offline Member
    Join Date
    Jul 2009
    Posts
    7
    Rep Power
    0

    Question 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

  2. #2
    sweetjava is offline Member
    Join Date
    Jul 2009
    Posts
    7
    Rep Power
    0

    Default

    its OK i get it, it's taking the values from the:

    addFace(getWidth()/2, getHeight()/2);

    right?

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,049
    Rep Power
    20

    Default

    Correct.
    getWidth() and getHeight() presumably being part of GraphicsProgram.

Similar Threads

  1. [SOLVED] Code Explaination Help
    By greenco in forum New To Java
    Replies: 2
    Last Post: 12-12-2008, 11:31 PM
  2. Tiles process flow explaination needed...
    By abhishek paul in forum Web Frameworks
    Replies: 0
    Last Post: 04-29-2008, 04:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •