prepare for some colors - greyed background

- background is not greyed depending on surrouding walls
- MazeColorMap to prepare for color edition
This commit is contained in:
philippe lhardy
2020-12-13 18:05:02 +01:00
parent 9b4f035d0f
commit 56585712c8
2 changed files with 55 additions and 7 deletions

View File

@@ -73,6 +73,23 @@ public class MazeCellParameters {
offsetY + (int) (mapHeight * height)); offsetY + (int) (mapHeight * height));
} }
public Color getGreyedColor(Color color, int greylevel)
{
Color greyedColor = new Color(
Math.max(0,color.getRed() - greylevel),
Math.max(0,color.getGreen() - greylevel),
Math.max(0,color.getBlue() - greylevel));
return greyedColor;
}
public void drawBackground(Graphics g, int pX, int pY, short walls) {
int x = offsetX + (int) (pX * width);
int y = offsetY + (int) (pY * height);
Color savecolor = g.getColor();
int greylevel = walls << 2;
g.setColor(getGreyedColor(savecolor,greylevel));
//g.fillRect(x+1,y+1,((int)width) -1,((int)height) - 1);
g.fillRect(x,y,((int)width),((int)height));
}
public void drawWalls(Graphics g, int pX, int pY, short walls) { public void drawWalls(Graphics g, int pX, int pY, short walls) {
int x = offsetX + (int) (pX * width); int x = offsetX + (int) (pX * width);
int y = offsetY + (int) (pY * height); int y = offsetY + (int) (pY * height);

View File

@@ -45,6 +45,24 @@ public class MazeComponent
StatusListener statusListener; StatusListener statusListener;
MazeColorMap colorMap = new MazeColorMap(Color.white, Color.black, Color.blue, Color.green, Color.red);
public class MazeColorMap
{
public Color background;
public Color wall;
public Color path;
public Color resolved_path;
public Color goal;
public MazeColorMap(Color background, Color wall, Color path, Color resolved_path, Color goal) {
this.background = background;
this.wall = wall;
this.path = path;
this.resolved_path = resolved_path;
this.goal = goal;
}
}
// for a given (x,y) pixel return cell position. // for a given (x,y) pixel return cell position.
// if rightmost position of view not (0,0) this is not working. // if rightmost position of view not (0,0) this is not working.
Position getPosition(int x, int y) { Position getPosition(int x, int y) {
@@ -277,16 +295,16 @@ public class MazeComponent
} }
if ((sX == gX) && (sY == gY)) { if ((sX == gX) && (sY == gY)) {
g.setColor(Color.red); g.setColor(colorMap.goal);
} else { } else {
g.setColor(Color.green); g.setColor(colorMap.resolved_path);
cp.drawDot(g, new Position(gX, gY), pX, pY, mX, mY); cp.drawDot(g, new Position(gX, gY), pX, pY, mX, mY);
g.setColor(Color.blue); g.setColor(colorMap.path);
} }
cp.drawDot(g, new Position(sX, sY), pX, pY, mX, mY); cp.drawDot(g, new Position(sX, sY), pX, pY, mX, mY);
synchronized (lockChange) { synchronized (lockChange) {
g.setColor(Color.red); g.setColor(colorMap.goal);
if (current != null) { if (current != null) {
cp.drawDot(g, current, pX, pY, mX, mY); cp.drawDot(g, current, pX, pY, mX, mY);
} }
@@ -301,9 +319,22 @@ public class MazeComponent
int aX = pX; int aX = pX;
int aY = pY; int aY = pY;
g.setColor(Color.black);
// draw background
for (; pY < mY; pY++) {
for (pX = 0; pX < mX; pX++) {
walls = map.getWalls(pX, pY);
g.setColor(colorMap.background);
cp.drawBackground(g, pX, pY, walls);
}
}
pX = aX;
pY = aY;
// draw all walls within clip bounds horiz first then lines // draw all walls within clip bounds horiz first then lines
g.setColor(colorMap.wall);
for (; pY < mY; pY++) { for (; pY < mY; pY++) {
for (pX = 0; pX < mX; pX++) { for (pX = 0; pX < mX; pX++) {
walls = map.getWalls(pX, pY); walls = map.getWalls(pX, pY);
@@ -321,9 +352,9 @@ public class MazeComponent
for (pX = 0; pX < mX; pX++) { for (pX = 0; pX < mX; pX++) {
path = map.getPath(pX, pY); path = map.getPath(pX, pY);
if ((path & LabyModel.SOLVED) == LabyModel.SOLVED) { if ((path & LabyModel.SOLVED) == LabyModel.SOLVED) {
g.setColor(Color.green); g.setColor(colorMap.resolved_path);
} else { } else {
g.setColor(Color.blue); g.setColor(colorMap.path);
} }
if (path != 0) { if (path != 0) {
DirectionPosition dp = new DirectionPosition(path, new Position(pX, pY)); DirectionPosition dp = new DirectionPosition(path, new Position(pX, pY));