Flags with Methods Tutorial

From Progzoo
Jump to: navigation, search

Tricolor

Several countries have flags that contain three colors in vertical stripes.

Draw the flags of:

  • France
  • Romania
  • Belgium
  • Nigeria
    • The green in Nigeria is new Color(0,128,0)

The small flags are 75 by 50

Flag of Four Tricolors



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

We can use a method to take advantage of similarities between flags:

Nordic Crosses

The Nordic Cross features in flags of Scandinavia

Draw the flags of:

  • Sweden
  • Denmark
  • Finland
  • Östergötland

The small flags are 75 by 50. The squares on the left are 20 by 20. The line width is 10. Use the colors:

Color blu = new Color(0,82,147);
Color yel = new Color(254,203,0);
Color red = new Color(198,12,48);
Color whi = Color.white;
Nordic Crosses



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

More Nordic Crosses

The Nordic Cross features in flags of Scandinavia

Draw the flags of:

  • Norway
  • Iceland
  • Faroe Islands
  • Orkney

The small flags are 75 by 50. The line width is 6 with a border of 2 each side. Use the colors:

Color blu = new Color(0,101,189);
Color yel = new Color(254,203,0);
Color red = new Color(237,41,57);
Color whi = Color.white;
More Nordic Crosses



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

China (nearly)

Notice the method fillStar(Graphics2D g,int x,int y, int r)

  • x and y are the coordinates of the centre of the star
  • r is the radius of the star

The stars are:

  • radius 30 at (50,50) - this represents the Communist Party of China
  • radius 10 at (100,20) - this represents the working classes
  • radius 10 at (120,40), representing the peasantry
  • radius 10 at (120,70), representing the urban petite bourgeoisie
  • radius 10 at (100,90), representing the national bourgeoisie
Flag of China (nearly right)


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

China

The four smaller stars should each be rotated so that they point to the centre of the large star.

A little trigonometry gives us the angles to rotate:

  • -Math.PI/2-Math.atan(30.0/50.0)
  • -Math.PI/2-Math.atan(10.0/70.0)
  • -Math.PI/2+Math.atan(20.0/70.0)
  • -Math.PI/2+Math.atan(40.0/50.0)

Change the method fillStar should be updated to allow this new parameter double a

You will need to use the method g.rotate, don't forget to unrotate when you have made the star.

Flag of China


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