Difference between revisions of "C#:Flags with Stars Tutorial"

From Progzoo
Jump to: navigation, search
(Vietnam)
(Vietnam)
Line 13: Line 13:
 
which is the wrong place. We must translate to put it in the
 
which is the wrong place. We must translate to put it in the
 
right place.
 
right place.
<strike>We can use the [http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Graphics.html#translate(int,%20int) translate] method to move the star to the right location.</strike>
+
<strike>We can use the [xx translate] method to move the star to the right location.</strike>
  
 
The translate call is to the wrong location (50,50) - it should be at
 
The translate call is to the wrong location (50,50) - it should be at
Line 26: Line 26:
 
  new int [] {1,2,3}
 
  new int [] {1,2,3}
 
</hint>
 
</hint>
<prog>
+
<prog><![CDATA[
 
static void drawFlag(Graphics g){
 
static void drawFlag(Graphics g){
 
   Point[] star={new Point(0,0),new Point(64,0),
 
   Point[] star={new Point(0,0),new Point(64,0),
Line 38: Line 38:
 
}
 
}
  
</prog>
+
]]></prog>
 
<answer>
 
<answer>
 
static void drawFlag(Graphics2D g){
 
static void drawFlag(Graphics2D g){

Revision as of 08:37, 12 June 2008

Drawing flags: reusing shapes.

Vietnam

Flagvietnam.png

The flag of Vietnam has a yellow five pointed star on a red background. This star is a popular device on many flags, we define the star once and use it many times in later flags.

The given star has a radius of 50, it is centred on 0,0 which is the wrong place. We must translate to put it in the right place. We can use the [xx translate] method to move the star to the right location.

The translate call is to the wrong location (50,50) - it should be at (100,75).


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

Panama

The flag of Panama requires two stars. We can draw the same star twice.

Flagpanama.png


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

Bosnia and Herzegovina

The flag of Bosnia and Herzegovina includes 9 white stars. Each star is 38 right and 38 below the previous star.

Flagbosnia.png




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

Democratic Republic of Congo (formerly Zaire)

  • The large star has a radius of 100
  • The 6 smaller stars have a radius of 10.
  • The background color is rgb: 173,216,230

Flagcongo.png




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