Pixel-Composer/scripts/node_gradient_replace/node_gradient_replace.gml

69 lines
2.1 KiB
Plaintext
Raw Normal View History

2023-03-02 07:59:14 +01:00
function Node_Gradient_Replace_Color(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
2023-12-10 02:48:10 +01:00
name = "Gradient Replace";
w = 96;
2023-03-02 07:59:14 +01:00
2023-05-28 20:00:51 +02:00
inputs[| 0] = nodeValue("Gradient", self, JUNCTION_CONNECT.input, VALUE_TYPE.gradient, new gradientObject(c_white) )
2023-03-02 07:59:14 +01:00
.setVisible(true, true);
2023-07-21 12:40:20 +02:00
inputs[| 1] = nodeValue("Color from", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, DEF_PALETTE )
2023-03-02 07:59:14 +01:00
.setDisplay(VALUE_DISPLAY.palette);
2023-07-21 12:40:20 +02:00
inputs[| 2] = nodeValue("Color to", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, DEF_PALETTE )
2023-03-02 07:59:14 +01:00
.setDisplay(VALUE_DISPLAY.palette);
inputs[| 3] = nodeValue("Threshold", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0.1)
.setDisplay(VALUE_DISPLAY.slider);
2023-03-02 07:59:14 +01:00
2023-05-28 20:00:51 +02:00
outputs[| 0] = nodeValue("Gradient", self, JUNCTION_CONNECT.output, VALUE_TYPE.gradient, new gradientObject(c_white) );
2023-03-02 07:59:14 +01:00
2023-12-10 02:48:10 +01:00
static processData = function(_outSurf, _data, _output_index, _array_index) { #region
2023-03-02 07:59:14 +01:00
var gra = _data[0];
var pfr = _data[1];
var pto = _data[2];
var thr = _data[3];
var graO = new gradientObject();
2023-07-25 20:12:40 +02:00
for( var i = 0, n = array_length(gra.keys); i < n; i++ ) {
2023-03-02 07:59:14 +01:00
var k = gra.keys[i];
var fromValue = 999;
var fromIndex = -1;
for( var j = 0; j < array_length(pfr); j++ ) {
var fr = pfr[j];
var dist = color_diff(k.value, fr);
if(dist <= thr && dist < fromValue) {
fromValue = dist;
fromIndex = j;
}
}
var cTo = fromIndex == -1? k.value : array_safe_get(pto, fromIndex, k.value, ARRAY_OVERFLOW.loop);
graO.keys[i] = new gradientKey(k.time, cTo);
}
graO.type = gra.type;
return graO;
2023-12-10 02:48:10 +01:00
} #endregion
2023-03-02 07:59:14 +01:00
2023-12-10 02:48:10 +01:00
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { #region
2023-03-02 07:59:14 +01:00
var bbox = drawGetBbox(xx, yy, _s);
if(bbox.h < 1) return;
var grad = outputs[| 0].getValue();
2023-12-10 02:48:10 +01:00
if(!is_array(grad)) grad = [ grad ];
var _h = array_length(grad) * 32;
var _y = bbox.y0;
var gh = bbox.h / array_length(grad);
for( var i = 0, n = array_length(grad); i < n; i++ ) {
grad[i].draw(bbox.x0, _y, bbox.w, gh);
_y += gh;
2023-03-02 07:59:14 +01:00
}
2023-12-10 02:48:10 +01:00
if(_h != min_h) will_setHeight = true;
min_h = _h;
} #endregion
2023-03-02 07:59:14 +01:00
}