-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.java
40 lines (36 loc) · 2.3 KB
/
App.java
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
31
32
33
34
35
36
37
38
39
40
package ch.hslu.AD.SW01.Faerben;
import java.awt.Color;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args ) {
colorArea(5, 4, Color.gray, Color.black);
}
private static Color[][] area = new Color[][] {
{ Color.black, Color.black, Color.black, Color.black, Color.black, Color.black, Color.black, Color.black, Color.black, Color.black },
{ Color.black, Color.white, Color.white, Color.white, Color.white, Color.white, Color.white, Color.white, Color.white, Color.black },
{ Color.black, Color.white, Color.white, Color.white, Color.black, Color.black, Color.black, Color.black, Color.white, Color.black },
{ Color.black, Color.white, Color.white, Color.white, Color.black, Color.black, Color.black, Color.black, Color.white, Color.black },
{ Color.black, Color.black, Color.white, Color.white, Color.white, Color.white, Color.white, Color.black, Color.white, Color.black },
{ Color.black, Color.black, Color.white, Color.white, Color.white, Color.black, Color.white, Color.black, Color.white, Color.black },
{ Color.black, Color.black, Color.black, Color.white, Color.white, Color.black, Color.white, Color.black, Color.white, Color.black },
{ Color.black, Color.black, Color.black, Color.white, Color.white, Color.black, Color.white, Color.white, Color.white, Color.black },
{ Color.black, Color.black, Color.white, Color.white, Color.white, Color.black, Color.black, Color.black, Color.black, Color.black },
{ Color.black, Color.black, Color.white, Color.white, Color.white, Color.black, Color.black, Color.black, Color.black, Color.black },
{ Color.black, Color.black, Color.black, Color.black, Color.black, Color.black, Color.black, Color.black, Color.black, Color.black }
};
public static void colorArea(final int x, final int y, final Color fillColor, final Color outsideColor) {
Color actualColor = area[x - 1][y - 1];
if((actualColor != outsideColor) && (actualColor != fillColor)) {
area[x - 1][y - 1] = fillColor;
System.out.println(String.format("x: %d, y: %d", x, y));
colorArea(x + 1, y, fillColor, outsideColor);
colorArea(x, y + 1, fillColor, outsideColor);
colorArea(x - 1, y, fillColor, outsideColor);
colorArea(x, y - 1, fillColor, outsideColor);
}
}
}