2023-07-17 22:30:27 -04:00
|
|
|
//
|
|
|
|
// Created by brett on 7/17/23.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef PARKSNREC_ARGUMENTS_H
|
|
|
|
#define PARKSNREC_ARGUMENTS_H
|
|
|
|
|
|
|
|
#include <genetic/util.h>
|
|
|
|
|
|
|
|
namespace parks::genetic {
|
|
|
|
|
|
|
|
constexpr double d = 0.4;
|
2023-07-19 22:06:04 -04:00
|
|
|
constexpr double nodeMutationChance = 0.2;
|
|
|
|
constexpr double scalarMutationChance = 0.2;
|
|
|
|
constexpr double colorMutationChance = 0.2;
|
|
|
|
constexpr double functionMutationChance = 0.2;
|
2023-07-17 22:30:27 -04:00
|
|
|
|
|
|
|
struct Color {
|
|
|
|
double r, g, b;
|
|
|
|
|
|
|
|
explicit Color(double _r, double _g, double _b) {
|
|
|
|
r = _r;
|
|
|
|
g = _g;
|
|
|
|
b = _b;
|
|
|
|
if (r < 0)
|
|
|
|
r = std::abs(r);
|
|
|
|
if (g < 0)
|
|
|
|
g = std::abs(g);
|
|
|
|
if (b < 0)
|
|
|
|
b = std::abs(b);
|
|
|
|
if (r > 1)
|
|
|
|
r = r - trunc(r);
|
|
|
|
if (g > 1)
|
|
|
|
g = g - trunc(g);
|
|
|
|
if (b > 1)
|
|
|
|
b = b - trunc(b);
|
|
|
|
}
|
|
|
|
|
2023-07-18 18:37:36 -04:00
|
|
|
explicit Color(double v) {
|
|
|
|
r = v;
|
|
|
|
g = 0;
|
|
|
|
b = 0;
|
|
|
|
}
|
2023-07-17 22:30:27 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
inline Color normalize(Color c) {
|
|
|
|
auto mag = std::sqrt(c.r * c.r + c.g * c.g + c.b * c.b);
|
|
|
|
if (mag == 0)
|
|
|
|
return c;
|
|
|
|
return Color{c.r / mag, c.g / mag, c.b / mag};
|
|
|
|
}
|
|
|
|
|
|
|
|
struct RandomScalar {
|
|
|
|
inline static Color get() {
|
|
|
|
return Color{randomDouble(0, 1)};
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static Color get(Color s) {
|
|
|
|
return Color{s.r + randomDouble(-d, d)};
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static Color get(Color s1, Color s2) {
|
|
|
|
auto min = std::min(s1.r, s2.r);
|
|
|
|
auto max = std::max(s1.r, s2.r);
|
|
|
|
if (min == max)
|
|
|
|
return Color{min};
|
|
|
|
return Color{randomDouble(min, max)};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct RandomColor {
|
|
|
|
inline static Color get() {
|
|
|
|
return normalize(Color{randomDouble(0, 1), randomDouble(0, 1), randomDouble(0, 1)});
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static Color get(Color color) {
|
|
|
|
return normalize(
|
|
|
|
Color{color.r + randomDouble(-d, d), color.g + randomDouble(-d, d), color.b +
|
|
|
|
randomDouble(
|
|
|
|
-d, d
|
|
|
|
)}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline static Color get(Color p1, Color p2) {
|
|
|
|
auto minR = std::min(p1.r, p2.r);
|
|
|
|
auto maxR = std::max(p1.r, p2.r);
|
|
|
|
auto minG = std::min(p1.g, p2.g);
|
|
|
|
auto maxG = std::max(p1.g, p2.g);
|
|
|
|
auto minB = std::min(p1.b, p2.b);
|
|
|
|
auto maxB = std::max(p1.b, p2.b);
|
|
|
|
return normalize(
|
|
|
|
Color{randomDouble(minR, maxR), randomDouble(minG, maxG), randomDouble(minB, maxB)}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct OperatorArguments {
|
2023-07-18 21:59:41 -04:00
|
|
|
unsigned char argsInfo;
|
2023-07-17 22:30:27 -04:00
|
|
|
Color left, right;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ParameterSet {
|
|
|
|
private:
|
|
|
|
std::vector<Color> parameters;
|
|
|
|
public:
|
|
|
|
ParameterSet() = default;
|
|
|
|
|
2023-07-18 18:37:36 -04:00
|
|
|
inline const Color& operator[](int index) const {return parameters[index];}
|
2023-07-17 22:30:27 -04:00
|
|
|
inline size_t size(){return parameters.size();}
|
|
|
|
|
|
|
|
void add(Color c) {parameters.push_back(c);}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //PARKSNREC_ARGUMENTS_H
|