Difference between revisions of "Flags with Rectangles Tutorial"

From Progzoo
Jump to: navigation, search
(Japan)
 
(23 intermediate revisions by 7 users not shown)
Line 1: Line 1:
 
<shell import='shells.xml#raster'/>{{Flags Tutorial}}__TOC__
 
<shell import='shells.xml#raster'/>{{Flags Tutorial}}__TOC__
 
* You may want to review:  [[Drawing_Rectangles]] before tackling these questions.
 
* You may want to review:  [[Drawing_Rectangles]] before tackling these questions.
* You might want to try [[coordinates exercises]] if you are not comfortable with x,y coordinates.
+
* You might want to try [[coordinates exercises]] if you are not comfortable with x ,y coordinates.
[[Experiment in interaction]]
+
 
 
==Libya==
 
==Libya==
 
<question title='Libya' imgOut='flag.png' width='150' height='100'
 
<question title='Libya' imgOut='flag.png' width='150' height='100'
Line 27: Line 27:
 
   className="Raster" level='1' rows='9'>
 
   className="Raster" level='1' rows='9'>
 
The flag of France is blue, white  and red.   
 
The flag of France is blue, white  and red.   
The code given draws only one of the three rectangles required, and it is in the wrong place.<br/>
+
The code given draws only one of the three rectangles required and it is in the wrong place.<br/>
[[Image:flag_guide_france.png|border]]<prog lang="java">
+
[[Image:flag_guide_france.png|border]]<prog lang="java">static void drawFlag(Graphics g)
static void drawFlag(Graphics g)
 
 
{
 
{
 
   g.setColor(Color.blue);
 
   g.setColor(Color.blue);
 
   g.fillRect(100,0,50,100);
 
   g.fillRect(100,0,50,100);
 
}
 
}
</prog><answer lang="java">
+
</prog><answer lang="java">static void drawFlag(Graphics g)
static void drawFlag(Graphics g)
 
 
{
 
{
 
   g.setColor(Color.blue);
 
   g.setColor(Color.blue);
Line 53: Line 51:
  
 
Only one of the three rectangles has been drawn - and that one is in the wrong place.<br/>
 
Only one of the three rectangles has been drawn - and that one is in the wrong place.<br/>
[[Image:flaggermany.png|border]] <prog lang="java">
+
[[Image:flaggermany.png|border]] <prog lang="java">static void drawFlag(Graphics g)
static void drawFlag(Graphics g)
 
 
{
 
{
 
   g.setColor(Color.yellow);
 
   g.setColor(Color.yellow);
Line 70: Line 67:
 
   g.fillRect(0,60,150,30);
 
   g.fillRect(0,60,150,30);
 
}
 
}
 +
 +
</answer></question>
 +
 +
==Switzerland==
 +
<question title='Switzerland' imgOut='flag.png' width='100' height='100'
 +
  className="Raster" level='1'>
 +
The flag of Switzerland is red with a white cross in the center.
 +
 +
The background has been filled in. Use white rectangles to draw the cross.<br/>
 +
[[Image:swissflag.png|border]] <prog lang="java">static void drawFlag(Graphics2D g)
 +
{
 +
  g.setColor(Color.red);
 +
  g.fillRect(0,0,100,100);
 +
}
 +
</prog>
 +
<answer lang="java">
 +
static void drawFlag(Graphics2D g)
 +
{
 +
  g.setColor(Color.red);
 +
  g.fillRect(0,0,100,100);
 +
  g.setColor(Color.white);
 +
  g.fillRect(10,40,80,20);
 +
  g.fillRect(40,10,20,80);
 +
}
 +
  
 
</answer></question>
 
</answer></question>
Line 79: Line 101:
 
*The rectangle is 150 by 100.
 
*The rectangle is 150 by 100.
 
*The circle is in position 45,20, width and height are 60,60.
 
*The circle is in position 45,20, width and height are 60,60.
*The dark lines are NOT part of the flag. They are shown as guides only.
 
 
[[Image:flagjapan.png|border]]
 
[[Image:flagjapan.png|border]]
 
<div class='dhint' title="How to draw a circle">
 
<div class='dhint' title="How to draw a circle">
Line 85: Line 106:
 
See [[Draw Circle]]
 
See [[Draw Circle]]
 
</div>
 
</div>
<prog lang="java">
+
<prog lang="java">static void drawFlag(Graphics2D g)
static void drawFlag(Graphics2D g)
 
 
{
 
{
 
   g.setColor(Color.white);
 
   g.setColor(Color.white);
Line 104: Line 124:
 
<hr/>
 
<hr/>
 
{{Flags Tutorial}}
 
{{Flags Tutorial}}
Now you can try the [[Graphics Quick Quiz|Rectangles Quick Quiz]]
+
Now you can try any of: [[Graphics Quick Quiz|Rectangles Quick Quiz]],
 +
[[Harder Problems with Rectangles]]
 
[[Lecture 2 Support]]  
 
[[Lecture 2 Support]]  
 
[[Category:Tutorial]]
 
[[Category:Tutorial]]
 
[[Category:Graphics]]
 
[[Category:Graphics]]

Latest revision as of 10:10, 9 September 2015

Libya

The flag of Libya is a simple green rectangle.

Try the program as it is given, then change it so that the green rectangle is 150 wide.
Flaglibya.png

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

France

The flag of France is blue, white and red. The code given draws only one of the three rectangles required and it is in the wrong place.
Flag guide france.png

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

Germany

The flag of Germany is black, red and yellow.

Only one of the three rectangles has been drawn - and that one is in the wrong place.
Flaggermany.png

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

Switzerland

The flag of Switzerland is red with a white cross in the center.

The background has been filled in. Use white rectangles to draw the cross.
Swissflag.png

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

Japan

  • The flag of Japan is a red circle on a white background.
  • The rectangle is 150 by 100.
  • The circle is in position 45,20, width and height are 60,60.

Flagjapan.png

g.fillOval(0,0,150,100) will fill an oval bounded by the whole shape. See Draw Circle


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

Now you can try any of: Rectangles Quick Quiz, Harder Problems with Rectangles Lecture 2 Support