1. Using Greenfoot and PictureWorld, make a
subclass Homework61
of Picture
with a method
verticalStripes
that makes vertical stripes on a picture, like
this:
(Who, you ask, is this handsome feline? It is the Horstmanns' cat, Mr. Darcy.)
This is much simpler than it looks. Check out the MyPicture1
class that comes with PictureWorld. One of the methods is almost what you
need. You can probably guess what the getX
and getY
methods do. The % has nothing to do with percentages. In Java, it computes
the remainder of a division. For example, 15 % 2 is 1 since there is a
remainder of 1 when dividing 15 by 2. In general, a number is even if
number % 2 == 0
. A very trivial modification of one of the
methods in MyPicture1
will do the trick. The easiest 15 points
you'll ever make.
Grading criteria:
Is the image striped vertically?
Is the class called Homework61
and the method called
verticalStripes
?
2. Using Greenfoot, make a subclass Homework62
of
Picture
with a method
public void swapBlueAndGreen() { // your work here }
that swaps the blue and green components of every pixel.
For example, consider a pixel with lots of blue and a little green:
double blue = pix.getBlue(); // assume it gets 255 double green = pix.getGreen(); // assume it gets 10
Afterwards, that pixel should have blueness 10 and greenness 255.
If you try this out on the road photo, the sky should turn green, and the trees should turn blue.
Grading criteria:
Does it really swap the colors?
Does it leave red alone?
Is the class called Homework62
and the method called
swapBlueAndGreen
?
Attach just the two class files Homework61.java and Homework62.java to your submission. They will be in your PictureWorld folder.