Difference between revisions of "Draw a Crescent"

From Progzoo
Jump to: navigation, search
 
(3 intermediate revisions by one other user not shown)
Line 2: Line 2:
 
You can draw a crescent as two circles. A large yellow circle that is partitally eclipsed by a smaller blue circle.
 
You can draw a crescent as two circles. A large yellow circle that is partitally eclipsed by a smaller blue circle.
 
The parameters are:
 
The parameters are:
*<code>r1</code>
+
*<code>r1</code>: radius of the large circle
:radius of the large circle
+
*<code>r2</code>: radius of the small circle
*<code>r2</code>
+
*<code>off</code>: the distance between the circles' left edges
:radius of the small circle
+
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:
*<code>off</code>
 
:the offset - the distance between the circles' centres
 
In addition we can use variables to denote the width and height of the blue rectangle:
 
 
*<code>blueW</code>
 
*<code>blueW</code>
 
*<code>blueH</code>
 
*<code>blueH</code>
 +
*<code>circL</code>
 
[[Image:flagmalaysia.png|border]]
 
[[Image:flagmalaysia.png|border]]
 
<p style="font-size:smaller">Model answer has 39 lines.</p>
 
<p style="font-size:smaller">Model answer has 39 lines.</p>
Line 21: 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 27: Line 26:
 
   int off= 10;
 
   int off= 10;
 
   g.setColor(Color.yellow);
 
   g.setColor(Color.yellow);
   g.fillOval(blueW/2-r1,blueH/2-r1,2*r1,2*r1);
+
   g.fillOval(circL,blueH/2-r1,2*r1,2*r1);
 
   g.setColor(Color.blue);
 
   g.setColor(Color.blue);
   g.fillOval(blueW/2-r2+off,blueH/2-r2,2*r2,2*r2);
+
   g.fillOval(circL+off,blueH/2-r2,2*r2,2*r2);
 
}
 
}
 
</prog>
 
</prog>
 
</question>
 
</question>

Latest revision as of 14:50, 10 October 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]