| 18 | constexpr int num_steps = 6 * 7; |
| 19 | |
| 20 | static void drawOrgLine(sp<RGBImage> image, const Organisation &org, const Colour &colour, |
| 21 | int steps) |
| 22 | { |
| 23 | const float step_width = static_cast<float>(image->size.x - 1) / static_cast<float>(steps); |
| 24 | constexpr int max_infiltration_value = 100; |
| 25 | float infiltration_y_scale = |
| 26 | static_cast<float>(image->size.y - 1) / static_cast<float>(max_infiltration_value); |
| 27 | |
| 28 | // Initialise all steps to zero, in case there's not enough history (we assume anything |
| 29 | // pre-game-start has 0 infilation anyway) |
| 30 | auto step_values = std::vector<float>(steps, 0.0f); |
| 31 | // First is always current infiltration value |
| 32 | step_values[0] = static_cast<float>(std::min(max_infiltration_value, org.infiltrationValue)); |
| 33 | int step = 1; |
| 34 | for (const auto step_value : org.infiltrationHistory) |
| 35 | { |
| 36 | if (step > steps) |
| 37 | return; |
| 38 | step_values[step] = static_cast<float>(std::min(max_infiltration_value, step_value)); |
| 39 | step++; |
| 40 | } |
| 41 | |
| 42 | auto image_lock = RGBImageLock(image); |
| 43 | |
| 44 | // TODO: Make curved lines |
| 45 | for (step = 0; step < steps - 1; step++) |
| 46 | { |
| 47 | const Vec3<float> start_point = { |
| 48 | static_cast<float>(image->size.x - 1) - static_cast<float>(step) * step_width, |
| 49 | static_cast<float>(image->size.y - 1) - step_values[step] * infiltration_y_scale, 0}; |
| 50 | const Vec3<float> end_point = { |
| 51 | static_cast<float>(image->size.x - 1) - static_cast<float>(step + 1) * step_width, |
| 52 | static_cast<float>(image->size.y - 1) - step_values[step + 1] * infiltration_y_scale, |
| 53 | 0}; |
| 54 | |
| 55 | const auto start_point_int = Vec3<int>(start_point); |
| 56 | const auto end_point_int = Vec3<int>(end_point); |
| 57 | |
| 58 | const auto line = LineSegment<int, false>(start_point_int, end_point_int); |
| 59 | for (auto point : line) |
| 60 | { |
| 61 | if (point.x < 0 || point.y < 0 || point.x >= image->size.x || point.y >= image->size.y) |
| 62 | { |
| 63 | LogWarning("Point %s out of bounds for image of size %s", point, image->size); |
| 64 | point.x = clamp(point.x, 0, static_cast<int>(image->size.x - 1)); |
| 65 | point.y = clamp(point.y, 0, static_cast<int>(image->size.y - 1)); |
| 66 | } |
| 67 | image_lock.set(Vec2<unsigned int>{static_cast<unsigned int>(point.x), |
| 68 | static_cast<unsigned int>(point.y)}, |
| 69 | colour); |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | constexpr std::array<Colour, 10> line_colors = { |
| 75 | Colour{195, 47, 47}, Colour{235, 79, 27}, Colour{243, 171, 87}, Colour{232, 247, 139}, |
no test coverage detected