Pixel-Composer/scripts/node_gradient_shift/node_gradient_shift.gml

56 lines
1.6 KiB
Plaintext
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_Gradient_Shift(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
2023-02-21 04:48:50 +01:00
name = "Gradient Shift";
previewable = false;
w = 96;
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
.setDisplay(true, true);
2023-02-21 04:48:50 +01:00
inputs[| 1] = nodeValue("Shift", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0)
.setDisplay(VALUE_DISPLAY.slider, [-1, 1, 0.01]);
2023-03-07 14:29:47 +01:00
inputs[| 2] = nodeValue("Wrap", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false)
2023-02-21 04:48:50 +01:00
2023-03-08 12:14:01 +01:00
inputs[| 3] = nodeValue("Scale", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1)
.setDisplay(VALUE_DISPLAY.slider, [0, 2, 0.01]);
2023-05-28 20:00:51 +02:00
outputs[| 0] = nodeValue("Gradient", self, JUNCTION_CONNECT.output, VALUE_TYPE.gradient, new gradientObject(c_white) );
2023-02-21 04:48:50 +01:00
_pal = -1;
static process_data = function(_outSurf, _data, _output_index, _array_index) {
var pal = _data[0];
var sft = _data[1];
var lop = _data[2];
2023-03-08 12:14:01 +01:00
var sca = _data[3];
2023-02-21 04:48:50 +01:00
2023-03-02 07:59:14 +01:00
_outSurf = new gradientObject();
2023-03-07 14:29:47 +01:00
_outSurf.keys = [];
2023-03-02 07:59:14 +01:00
for( var i = 0; i < array_length(pal.keys); i++ ) {
var k = pal.keys[i];
2023-03-08 12:14:01 +01:00
var key = new gradientKey((0.5 + (k.time - 0.5) * sca) + sft, k.value);
2023-03-07 14:29:47 +01:00
if(lop) {
var t = frac(key.time);
if(t < 0) t = 1 + t;
key.time = t;
}
_outSurf.add(key);
2023-02-21 04:48:50 +01:00
}
2023-03-02 07:59:14 +01:00
_outSurf.type = pal.type;
2023-02-21 04:48:50 +01:00
return _outSurf;
}
2023-03-05 07:16:44 +01:00
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
2023-02-21 04:48:50 +01:00
var bbox = drawGetBbox(xx, yy, _s);
if(bbox.h < 1) return;
var grad = outputs[| 0].getValue();
2023-03-02 07:59:14 +01:00
grad.draw(bbox.x0, bbox.y0, bbox.w, bbox.h);
2023-02-21 04:48:50 +01:00
}
}