forked from Toyoyou/homework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNestedRects.java
More file actions
30 lines (27 loc) · 1.09 KB
/
Copy pathNestedRects.java
File metadata and controls
30 lines (27 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import objectdraw.*;
import java.awt.*;
// Recursive structure for collection of nested rectangles
public class NestedRects implements NestedRectsInterface {
private FramedRect outerRect; // Outermost rectangle in picture
private NestedRectsInterface rest; // Remaining nested rectangles
public NestedRects( double x, double y, double width, double height,
Color color, DrawingCanvas canvas ) {
outerRect = new FramedRect( x, y, width, height, canvas );
outerRect.setColor(color);
if ( width >= 8 && height >= 8 ) {
if(color==Color.red){
color = Color.blue;
}else if(color == Color.blue){
color = Color.green;
}else if(color == Color.green){
color = Color.yellow;
}else{
color = Color.red;
}
rest = new NestedRects( x + 4, y + 4, width - 8,
height - 8,color, canvas );
} else { // Construct a base object
rest = new BaseRects();
}
}
}