Difference between revisions of "Test"

From Progzoo
Jump to: navigation, search
(Bahrain)
Line 4: Line 4:
  
 
The control variable <i>i</i> takes every value 0,1,2..9 in turn. We can use the value of <i>i</i> inside the loop if required.
 
The control variable <i>i</i> takes every value 0,1,2..9 in turn. We can use the value of <i>i</i> inside the loop if required.
==Bahrain==
+
 
<question height="155" width="250" imgOut="flag.png" className="Raster" title="Bahrain" rows='16'>
 
The flag of Bahrain has a five irregular pentagons on a red background..
 
 
Each pentagon can be represented by five points such as (0,0), (64,0)
 
(100,15) (64,31) and (0,31)..
 
[[Image:flagbahrain.png|left|frame|Flag of Bahrain]]
 
 
 
<prog lang="java">
 
static void drawFlag(Graphics2D g){
 
  //Flag of Bahrain
 
  //Define a pillar as a polygon
 
  Polygon pillar = new Polygon(
 
  new int[]{0,64,100,64, 0},
 
  new int[]{0, 0, 15,31,31}, 5);
 
  //Do the background
 
  g.setColor(Color.red);
 
  g.fillRect(0,0,250,155);
 
  g.setColor(Color.white);
 
  for (int i=0;i&lt;2;i++){
 
    //Draw the pillar
 
    g.fillPolygon(pillar);
 
    g.translate(0,31);
 
  }
 
}
 
</prog>
 
<answer lang="java">
 
static void drawFlag(Graphics2D g){
 
  //Flag of Bahrain
 
  //Define a pillar as a polygon
 
  Polygon pillar = new Polygon(
 
  new int[]{0,64,100,64, 0},
 
  new int[]{0, 0, 15,31,31}, 5);
 
  //Do the background
 
  g.setColor(Color.red);
 
  g.fillRect(0,0,250,155);
 
  g.setColor(Color.white);
 
  for (int i=0;i&lt;5;i++){
 
    //Draw the pillar
 
    g.fillPolygon(pillar);
 
    g.translate(0,31);
 
  }
 
}
 
</answer>
 
</question>
 
  
 
==Qatar==
 
==Qatar==

Revision as of 16:22, 7 October 2008

We can repeat a statement or block of statements with a for loop. The simplest for loops take the following form:

The control variable i takes every value 0,1,2..9 in turn. We can use the value of i inside the loop if required.


Qatar

Consider the neighbouring state Qatar.

  • 9 pillars, each pillar is 17 pixels below the previous.
  • The five coordinates of the top pillar are (0,0) (84,0) (125,9) (84,17), (0,17)
  • Use RGB(128,0,0) for the less jaunty red.

Flag of Qatar

The need for a loop becomes even more obvious for this flag.



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