Skip to content
Snippets Groups Projects
Commit 2f07e688 authored by EL GAOUAL Zaid's avatar EL GAOUAL Zaid
Browse files

DistinctColorGenerator

parent 65477863
No related branches found
No related tags found
No related merge requests found
package model;
import javafx.scene.paint.Color;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class DistinctColorGenerator implements ColorGenerator {
private List<Color> colors;
private Color defaultColor;
public DistinctColorGenerator(List<Color> colors, Color defaultColor) {
this.colors = colors;
this.defaultColor = defaultColor;
}
@Override
public Color nextColor(Cell cell) {
List<Cell> neighbours = cell.getNeighbours();
List<Color> neighbourscolor = new ArrayList<>();
for (Cell neighbour : neighbours) {neighbourscolor.add(neighbour.getColor());}
int i = 0, j = 0;
while (colors.get(i) == neighbourscolor.get(j)) {
if (j == neighbourscolor.size() - 1 && i == colors.size() - 1) {return defaultColor;}
if (j == neighbourscolor.size() - 1) {
j=0;
i+=1;
continue;}
j+=1;
}
return colors.get(i);
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment