-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontours.pde
42 lines (33 loc) · 1.29 KB
/
contours.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
float max(float[][] array) {
float maxValue = -Float.MAX_VALUE;
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) {
if (array[i][j] > maxValue) {
maxValue = array[i][j];
}
}
}
return maxValue;
}
void drawBenchmarkContours(String benchmarkType, float xMin, float xMax, float yMin, float yMax, int gridX, int gridY) {
float[][] values = new float[gridX][gridY];
float dx = (xMax - xMin) / (gridX - 1);
float dy = (yMax - yMin) / (gridY - 1);
for (int i = 0; i < gridX; i++) {
for (int j = 0; j < gridY; j++) {
float x = xMin + i * dx;
float y = yMin + j * dy;
values[i][j] = evaluationFunction(objectiveFunction(new float[] {x, y}, benchmarkType));
}
}
float maxValue = max(values);
noStroke();
for (int i = 0; i < gridX - 1; i++) {
for (int j = 0; j < gridY - 1; j++) {
float value = values[i][j];
float normalizedValue = map(value, 0, maxValue, 0, 1);
fill(lerpColor(color(0, 0, 255), color(255, 0, 0), normalizedValue));
rect(map(i, 0, gridX, 0, width), map(j, 0, gridY, height, 0), dx * width / (xMax - xMin), dy * height / (yMax - yMin));
}
}
}