Difference between revisions of "Flags with Rectangles Tutorial"
(Added question: Switzerland.) |
|||
(2 intermediate revisions by 2 users not shown) | |||
Line 2: | Line 2: | ||
* 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. | ||
− | + | ||
==Libya== | ==Libya== | ||
<question title='Libya' imgOut='flag.png' width='150' height='100' | <question title='Libya' imgOut='flag.png' width='150' height='100' | ||
Line 75: | Line 75: | ||
The flag of Switzerland is red with a white cross in the center. | The flag of Switzerland is red with a white cross in the center. | ||
− | The background has been filled in. Use rectangles to | + | 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) | [[Image:swissflag.png|border]] <prog lang="java">static void drawFlag(Graphics2D g) | ||
{ | { | ||
g.setColor(Color.red); | g.setColor(Color.red); | ||
g.fillRect(0,0,100,100); | g.fillRect(0,0,100,100); | ||
− | |||
} | } | ||
</prog> | </prog> | ||
Line 102: | 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. | ||
− | |||
[[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"> |
Latest revision as of 10:10, 9 September 2015
Contents
- 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.
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.
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.
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.
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.
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.
g.fillOval(0,0,150,100)
will fill an oval bounded by the whole shape.
See Draw Circle
Now you can try any of: Rectangles Quick Quiz, Harder Problems with Rectangles Lecture 2 Support