Difference between revisions of "Draw a Crescent"

From Progzoo
Jump to: navigation, search
(New page: <question height="196" width="392" imgOut="flag.png" className="Raster" title="Malaysia"> 392 by 196, radius of the star is 30. Yellow crescent and a yellow 14 point star on blue. Fourteen...)
 
Line 1: Line 1:
 
<question height="196" width="392" imgOut="flag.png" className="Raster" title="Malaysia">
 
<question height="196" width="392" imgOut="flag.png" className="Raster" title="Malaysia">
392 by 196, radius of the star is 30.
+
You can draw a crescent as two circles. A large yellow circle that is partitally eclipsed by a smaller blue circle.
Yellow crescent and a yellow 14 point star on blue. Fourteen red
+
The parameters are:
and white stripes.
+
:r1
 
+
::radius of the large circle
 +
:r2
 +
::radius of the small circle
 +
:off
 +
::the offset - the distance between the circles' centres
  
 
[[Image:flagmalaysia.png|border]]
 
[[Image:flagmalaysia.png|border]]
Line 10: Line 14:
 
<prog>
 
<prog>
 
static void drawFlag(Graphics2D g){
 
static void drawFlag(Graphics2D g){
   g.setColor(Color.blue);p
+
  g.setRenderingHint(
   g.fillRect(0,0,192,196*8/14);
+
    RenderingHints.KEY_ANTIALIASING,
 +
    RenderingHints.VALUE_ANTIALIAS_ON);
 +
  int blueH = 196*8/14;
 +
  int blueW = 197;
 +
   g.setColor(Color.blue);
 +
   g.fillRect(0,0,blueW,blueH);
 +
  int r1 = 42;
 +
  int r2 = 36;
 +
  int off= 10;
 
   g.setColor(Color.yellow);
 
   g.setColor(Color.yellow);
   g.drawOval(0,0,100,100);
+
   g.fillOval(blueW/2-r1,blueH/2-r1,2*r1,2*r1);
 +
  g.setColor(Color.blue);
 +
  g.fillOval(blueW/2-r2+off,blueH/2-r2,2*r2,2*r2);
 
}
 
}
 
</prog>
 
</prog>
 
</question>
 
</question>

Revision as of 15:58, 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 offset - the distance between the circles' centres

Flagmalaysia.png

Model answer has 39 lines.


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