Skip to content
Snippets Groups Projects
ChaosGameButtonController.java 1.21 KiB
package edu.ntnu.stud.chaosgame.controller;
import edu.ntnu.stud.chaosgame.view.ChaosGameGUIView;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.scene.control.Button;
import javafx.scene.image.WritableImage;
import javafx.util.Duration;
import javafx.animation.Animation;

public class ChaosGameButtonController {
    private final Timeline timeline;

    public ChaosGameButtonController(ChaosGameGUIView view, Button startButton, Button stopButton, Button newButton, Button clearButton) {
        this.timeline = new Timeline(new KeyFrame(Duration.seconds(0.05), event -> view.drawChaosGame()));
        this.timeline.setCycleCount(Timeline.INDEFINITE);
        startButton.setOnAction(event -> timeline.play());
        stopButton.setOnAction(event -> timeline.stop());
        newButton.setOnAction(event ->{
            WritableImage newWritableImage = new WritableImage(view.getWidth(), view.getHeight());
            view.setPixelWriter(newWritableImage.getPixelWriter());
            view.setImageViewFromImage(newWritableImage);
        });
        clearButton.setOnAction(event -> {
            view.getImageView().setImage(null);
            view.setCurrentLine(0);
        });


    }

}