1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-09-03 19:27:54 +00:00

color parser

This commit is contained in:
Zeno Rogue
2024-05-27 12:24:12 +02:00
parent d381caba1f
commit 83575d9d7d
3 changed files with 71 additions and 27 deletions

View File

@@ -1669,18 +1669,10 @@ EX namespace ccolor {
return r;
}, {0, 0xFFFFFF});
EX string color_formula = "to01(rgb(x,y,z))";
EX string color_formula = "rgb(to01(x),to01(y),to01(z))";
EX data formula = data("formula", always_available, CCO {
color_t res;
for(int i=0; i<4; i++) {
ld v = real(patterns::compute_map_function(c, 1+i, color_formula));
if(i == 3) part(res, i) = (v > 0);
else if(v < 0) part(res, i) = 0;
else if(v > 1) part(res, i) = 255;
else part(res, i) = int(v * 255 + .5);
}
return res;
return patterns::compute_map_function(c, color_formula);
}, {});
EX data threecolor = data("threecolor", [] { return geosupport_threecolor(); }, CCO {
@@ -2062,9 +2054,8 @@ EX namespace patterns {
}
EX cld compute_map_function(cell *c, int p, const string& formula) {
EX color_t compute_map_function(cell *c, const string& formula) {
exp_parser ep;
ep.extra_params["p"] = p;
hyperpoint h = calc_relative_matrix(c, currentmap->gamestart(), C0) * C0;
ep.extra_params["x"] = h[0];
@@ -2137,7 +2128,7 @@ EX namespace patterns {
ep.s = formula;
try {
return ep.parse();
return ep.parsecolor();
}
catch(hr_parse_exception&) {
return 0;