Difference between revisions of "Perl:Flags with Repeats Tutorial"

From Progzoo
Jump to: navigation, search
(Bahrain)
(Qatar)
Line 77: Line 77:
 
Use RGB(128,0,0) for the less jaunty red.
 
Use RGB(128,0,0) for the less jaunty red.
 
</p>
 
</p>
[[Image:Flagqatar.png|border]]
+
[[Image:Flagqatar.png|frame|Flag of Qatar]]
 
<p>The need for a loop becomes even more obvious for this flag.
 
<p>The need for a loop becomes even more obvious for this flag.
 
</p>
 
</p>
 
</question>
 
</question>
 +
 
==India==
 
==India==
 
<question xmlns:htm="http://www.w3.org/1999/xhtml" lang="pl" className="Raster" height="204" width="306" imgOut="flag.png"><prog><![CDATA[
 
<question xmlns:htm="http://www.w3.org/1999/xhtml" lang="pl" className="Raster" height="204" width="306" imgOut="flag.png"><prog><![CDATA[

Revision as of 22:37, 6 September 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.

for (my $i=0;$i<10;$i++){
<i>statement</i>
}

Bahrain

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), (128,0) (200,31) (128,62) and (0,62).

Flag of Bahrain
[Font] [Default] [Show] [Resize] [History] [Profile]

Qatar

Neighbouring state Qatar has 9 pillars, each pillar is 34 units below the previous. 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]

India

The flag of India is 306 by 204. The orange, white and green stripes are 306 by 68. The wheel has radius 30.

The flag of India includes a wheel with 24 spokes, the spokes are 2*pi/24 radians apart.

The code given draws only three of the spokes - we could copy and paste - but it would be much better to use a loop.

We have not really done India justice here - the actual flag is much more elegant, the spokes taper and the rim includes decoration. Nevertheless - we apologize to the sub-continent and move on.

Flagindia.png

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

Namibia

Flagnamibia.png

Each the rightmost triangle has coordinates (19,5) (29,0) (19,-5) relative to the centre of the star burst - which is at (60,60).

Notice that only two of the 12 triangles are drawn by the example code. Also note that the colors are mixed up.

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

European Union

Flageurope.png

We need the trigonometry functions cos and sin to draw flags in a circle. The coordinates of a point on a circle radius 125 at 30° from the x-axis (East) these are 125*cos(30), 125*sin(30).

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