Difference between revisions of "Draw a Crescent"

From Progzoo
Jump to: navigation, search
Line 19: Line 19:
 
   int blueH = 196*8/14;
 
   int blueH = 196*8/14;
 
   int blueW = 197;
 
   int blueW = 197;
 +
  int circL = 35;
 
   g.setColor(Color.blue);
 
   g.setColor(Color.blue);
 
   g.fillRect(0,0,blueW,blueH);
 
   g.fillRect(0,0,blueW,blueH);
Line 24: Line 25:
 
   int r2 = 36;
 
   int r2 = 36;
 
   int off= 10;
 
   int off= 10;
  int circL = 35;
 
 
   g.setColor(Color.yellow);
 
   g.setColor(Color.yellow);
 
   g.fillOval(circlL,blueH/2-r1,2*r1,2*r1);
 
   g.fillOval(circlL,blueH/2-r1,2*r1,2*r1);

Revision as of 16:06, 10 January 2008

You can draw a crescent as two circles. A large yellow circle that is partitally eclipsed by a smaller blue circle. The parameters are:

  • r1: radius of the large circle
  • r2: radius of the small circle
  • off: the distance between the circles' left edges

In addition we can use variables to denote the width and height of the blue rectangle and the distance of the left edge of the circle from the left of the blue rectangle:

  • blueW
  • blueH
  • circL

Flagmalaysia.png

Model answer has 39 lines.


[Font] [Default] [Show] [Resize] [History] [Profile]