CS111

PictureWorld Contract

Picture Combinators

These are methods that return Picture objects. Remember that the picture grid is a 1x1 square where (0.0,0.0) is the bottom left corner and (1.0,1.0) is the top right corner.

empty

public Picture empty()
Returns the empty picture.

Methods that Rotate Pictures

public Picture clockwise90 (Picture p)
Returns a new Picture that is the original Picture p rotated 90 degrees in the clockwise direction.

public Picture clockwise180 (Picture p)
Returns a new Picture that is the original Picture p rotated 180 degrees in the clockwise direction.

public Picture clockwise270 (Picture p)
Returns a new Picture that is the original Picture p rotated 270 degrees in the clockwise direction.


p1

clockwise90(p1)

clockwise180(p1)

clockwise270(p1)

Methods that Flip Pictures around an Axis

The axes are defined as shown in the diagram below:

public Picture flipHorizontally (Picture p)
Returns a new Picture that is the original Picture p flipped around its vertical axis (from (0.5,0.0) to (0.5,1.0)).

public Picture flipVertically (Picture p)
Returns a new Picture that is the original Picture p flipped around its horizontal axis (from (0.0,0.5) to (1.0,0.5)).

public Picture flipDiagonally (Picture p)
Returns a new Picture that is the original Picture p flipped around its diagonal axis (from (0.0,0.0) to (1.0,1.0)).


p1

flipVertically(p1)

flipHorizontally(p1)

flipDiagonally(p1)

overlay

public Picture overlay (Picture p1, Picture p2)
Returns a new Picture that is the result of placing Picture p1 on top of Picture p2.


p1

p2

overlay(p1,p2)

Methods that Place Pictures Next to Each Other

public Picture beside (Picture p1, Picture p2)
Returns a new Picture that is the result of placing Picture p1 to the left of Picture p2, where each Picture takes up half of the screen.

public Picture beside (Picture p1, Picture p2, double fraction)
Returns a new Picture that is the result of placing Picture p1 to the left of Picture p2, where p1 takes up the specified fraction of the screen. fraction is a decimal number between 0.0 (none of the screen) and 1.0 (the entire screen).

public Picture above (Picture p1, Picture p2)
Returns a new Picture that is the result of placing Picture p1 above Picture p2, where each Picture takes up half of the screen.

public Picture above (Picture p1, Picture p2, double fraction)
Returns a new Picture that is the result of placing Picture p1 above Picture p2, where p1 takes up the specified fraction of the screen. fraction is a decimal number between 0.0 (none of the screen) and 1.0 (the entire screen).


beside(p1,p1)

beside(p1,p1,0.25)

above(p1,p1)

above(p1,p1,0.66)

Picture Choice Manipulators

public void initializePictureChoices()
This method is invoked when a PictureWorld applet is created.

public void addPictureChoice(String name, Picture pic)
This method adds the choice name to the list of Picture choices and associates it with the Picture pic.