Here is my pseudo code :
create a square moving on a map
while( programe run ){
if( color == white ){
square go foward
get color of the map under the square
}
if( color == blue ){
square rotate 90
square go foward
get color of the map under the square
}
}
But the point is i want that to be show to the user, but i don't know how can i do that. I tried by using transition but i couldn't find a way to generate theme and play theme consequently after. I tried with animation timer but i couldn't find a way to synchronised theme. So if you have any idea I really need help.
Here is a real working for the code of the pseudo code without animation if it could help:
Main Class :
`public class Main extends Application {
private final int W= 500, H =500;
private String path = "map.png";
public void start(Stage stage) throws Exception {
Image image = new Image(path, W, H, false, false);
Node node = new ImageView(image);
Group root = new Group(node);
Scene scene = new Scene(root, 500, 500);
stage.setScene(scene);
stage.show();
square bot = new square(root, image);
}
}`
square Class :
`public square(Group group, Image mapImage){
Image image = new Image(path, size, size, false, false);
this.sq = new ImageView(image);
group.getChildren().addAll(sq);
this.mapImage = mapImage;
this.rotate = new Rotate();
rotate.setPivotX(size/2);
rotate.setPivotY(size/2);
sq.getTransforms().addAll(rotate);
this.x = 100;
this.y = x;
sq.relocate(x, y);
System.out.println(look());
Boolean bol = false;
while (bol == false ){
if(look() == "WHITE"){
goFoward(10);
} else if (look() == "BLUE") {
turn(45);
goFoward(10);
}
}
}
public void goFoward(int a ){
System.out.println("goFoward");
x = x + a*sin(toRadians(rotation));
y = y - a*cos(toRadians(rotation));
sq.relocate(x,y);
}
public void turn(int a){
System.out.println("turn");
rotation = rotation + a;
rotate.setAngle(rotation);
}
public String look(){
double c;
PixelReader reader = mapImage.getPixelReader();
Color argb = reader.getColor( (int)x,(int)y );
double r = argb.getRed();
double g = argb.getGreen();
double b = argb.getBlue();
if(r < 0.2 && b > 0.5){
return "BLUE";
} else if (r > 0.8 && g > 0.8 && b > 0.8) {
return "WHITE";
}
else {
System.out.print("RGB : ");
System.out.print(r);
System.out.print(" / ");
System.out.print(g);
System.out.print(" / ");
System.out.println(b);
return "ILLISIBLE";
}
}
}`