Difference between revisions of "Tutorial/Flags"

From Progzoo
Jump to: navigation, search
 
(119 intermediate revisions by 4 users not shown)
Line 1: Line 1:
Libya
+
__NOTOC__ __NOEDITSECTION__ 
The flag of Libya is a green rectangle.
+
In these exercises you draw the flags of various countries using graphics commands.
<question title='L' imgOut='flag.png' width='300' height='200'
+
{{Table6 
  className="Raster">     
+
|1) Rectangles|Tut1page1.png|The '''[[Tutorial/Flags/1 Rectangles|rectangles tutorial]]''' has you drawing the flags of Libya, France, Germany and Palau. You can draw these flags using only rectangles of different colors. These exercise get you used to some graphics commands. You might need to be reminded of x,y coordinates.
<blurb>Here we go </blurb>
+
|2) Lines|tut1page2.png|The '''[[Tutorial/Flags/2 Lines|lines tutorial]]''' includes flags that require lines. By changing the color and the thickness of the lines drawn you can produce the flags of England, Scotland, Botswana and Trinidad and Tobago.
<prog lang="java">
+
|3) Polygons|tut1page3.png|The '''[[Tutorial/Flags/3 Polygons|polygons tutorial]]''' includes flags made with triangles and other polygons. The flags of Napier University, Jamaica and the Bahamas can be drawn with triangles, the Seychelles require triangles and a quadrilateral.
static void drawFlag(Graphics g){
+
|4) Stars|tut1page4.png|The '''[[Tutorial/Flags/4 Stars|stars tutorial]]''' includes flags that feature the pentangle - a five pointed star. In each example the star has already been defined as a polygon - all you have to do is to translate and scale the star to produce the flags of Vietnam, Panama, Bosina Herzeginia and Zaire.
  g.setColor(new Color(0,128,0));
+
|5) Repeat|tut1page5.png|The '''[[Tutorial/Flags/5 Repeats|repeats tutorial]]''' focuses on flags that include repetition. You can use loops, such as <code>for</code> to perform the same action over and over. This is how to draw the flag of Bahrain or Qatar, also India, Namibia and the European Union.
  g.fillRect(0,0,150,200);
+
|6) Hard|tut1page6.png|The '''[[Tutorial/Flags/6 Harder|harder tutorials]]''' includes flags that include repetition that can be exploited. Your aim in tackling these problems is to produce short code that makes the most of the repetition. Ideally you will be defining your own methods or subroutines.
}
+
}}
</prog>
 
<answer lang="java">
 
static void drawFlag(Graphics g){
 
  g.setColor(new Color(0,128,0));
 
  g.fillRect(0,0,300,200);
 
}
 
</answer>   
 
<shell id="raster" lang='java'><![CDATA[
 
import java.awt.image.BufferedImage;
 
import java.awt.*;
 
import java.io.File;
 
import javax.imageio.ImageIO;
 
  
public class Raster{
+
See also [[SVG:Tutorial]]
 
 
QcQ
 
 
 
 
 
  public static void main(String argv []){
 
    BufferedImage image = new BufferedImage(QwidthQ,QheightQ, BufferedImage.TYPE_INT_ARGB);
 
    Graphics2D g = image.createGraphics();
 
    drawFlag(g);
 
    g.dispose();
 
    try {
 
        File out = new File("flag.png");
 
        ImageIO.write(image, "png", out);
 
    }catch(Exception e){
 
    System.err.println(e);
 
    }
 
  }
 
}
 
]]></shell> 
 
</question>
 

Latest revision as of 01:35, 9 January 2008

In these exercises you draw the flags of various countries using graphics commands.

The rectangles tutorial has you drawing the flags of Libya, France, Germany and Palau. You can draw these flags using only rectangles of different colors. These exercise get you used to some graphics commands. You might need to be reminded of x,y coordinates.
tut1page2.png
[[The polygons tutorial includes flags made with triangles and other polygons. The flags of Napier University, Jamaica and the Bahamas can be drawn with triangles, the Seychelles require triangles and a quadrilateral.

|The lines tutorial includes flags that require lines. By changing the color and the thickness of the lines drawn you can produce the flags of England, Scotland, Botswana and Trinidad and Tobago.

]]
File:3) Polygons
tut1page3.png
4) Stars

[[Image:The stars tutorial includes flags that feature the pentangle - a five pointed star. In each example the star has already been defined as a polygon - all you have to do is to translate and scale the star to produce the flags of Vietnam, Panama, Bosina Herzeginia and Zaire. |thumb|left|5) Repeat]]The repeats tutorial focuses on flags that include repetition. You can use loops, such as for to perform the same action over and over. This is how to draw the flag of Bahrain or Qatar, also India, Namibia and the European Union.

[[{{{19}}}|6) Hard]]
The harder tutorials includes flags that include repetition that can be exploited. Your aim in tackling these problems is to produce short code that makes the most of the repetition. Ideally you will be defining your own methods or subroutines.
{{{20}}}
[[{{{24}}}|{{{21}}}]]

[[Image:{{{22}}}|thumb|left|{{{23}}}]]{{{25}}}

[[{{{29}}}|{{{26}}}]]

[[Image:{{{27}}}|thumb|left|{{{28}}}]]{{{30}}}

See also SVG:Tutorial