Skip to content
Snippets Groups Projects

Added user feedback to buttons

Merged Edvard Granheim Harbo requested to merge MinorAdjustments into dev
16 files
+ 248
108
Compare changes
  • Side-by-side
  • Inline
Files
16
@@ -5,12 +5,17 @@ import edu.ntnu.idatt2003.mappevurderingprog2.models.Complex;
import edu.ntnu.idatt2003.mappevurderingprog2.models.JuliaTransform;
import edu.ntnu.idatt2003.mappevurderingprog2.models.Transform2D;
import edu.ntnu.idatt2003.mappevurderingprog2.models.Vector2D;
import edu.ntnu.idatt2003.mappevurderingprog2.models.chaos.ChaosCanvas;
import edu.ntnu.idatt2003.mappevurderingprog2.models.chaos.ChaosGame;
import edu.ntnu.idatt2003.mappevurderingprog2.models.chaos.ChaosGameDescription;
import edu.ntnu.idatt2003.mappevurderingprog2.models.chaos.ChaosGameDescriptionFactory;
import edu.ntnu.idatt2003.mappevurderingprog2.models.chaos.ChaosGameFileHandler;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
/**
* The GameController class is a controller class that handles the logic for the ChaosGame.
@@ -20,6 +25,8 @@ import java.util.List;
*/
public class GameController {
private int greenThreshold, blueThreshold;
/**
* Creates a Sierpinski triangle ChaosGameDescription
* and sets it as the current ChaosGameDescription.
@@ -263,5 +270,57 @@ public class GameController {
description.setMaxCoords(initialMax);
ChaosGame.getInstance().setDescription(description);
}
public void calculateQuantiles() {
List<Integer> hitCounts = new ArrayList<>();
for (int[] row : ChaosGame.getInstance().getCanvas().getCanvasArray()) {
for (int hit : row) {
if (hit > 0) {
hitCounts.add(hit);
}
}
}
if (hitCounts.isEmpty()) {
return;
}
Collections.sort(hitCounts);
int n = hitCounts.size();
greenThreshold = hitCounts.get((int) (n * 0.33));
blueThreshold = hitCounts.get((int) (n * 0.66));
}
private Color getColorForHits(int hits) {
if (hits == 0) {
return Color.WHITE;
} else if (hits <= greenThreshold) {
return Color.GREEN;
} else if (hits <= blueThreshold) {
return Color.BLUE;
} else {
return Color.RED;
}
}
public Canvas updateCanvasDisplay(Canvas mainCanvas) {
GraphicsContext gc = mainCanvas.getGraphicsContext2D();
int[][] canvasArray = ChaosGame.getInstance().getCanvas().getCanvasArray();
double canvasWidth = mainCanvas.getWidth() - 20;
double canvasHeight = mainCanvas.getHeight() - 20;
double pixelWidth = canvasWidth / canvasArray[0].length;
double pixelHeight = canvasHeight / canvasArray.length;
gc.clearRect(0, 0, mainCanvas.getWidth(), mainCanvas.getHeight());
for (int i = 0; i < canvasArray.length; i++) {
for (int j = 0; j < canvasArray[i].length; j++) {
double x = j * pixelWidth + 3;
double y = i * pixelHeight + 3;
gc.setFill(getColorForHits(canvasArray[i][j]));
gc.fillRect(x, y, pixelWidth, pixelHeight);
}
}
return mainCanvas;
}
}
Loading