mirror of
https://github.com/Ttanasart-pt/Pixel-Composer.git
synced 2024-12-24 14:06:23 +01:00
[Array Sample] Add random mode, index shift properties.
This commit is contained in:
parent
7e8c6758e9
commit
7e2191de98
1 changed files with 55 additions and 14 deletions
|
@ -6,29 +6,70 @@ function Node_Array_Sample(_x, _y, _group = noone) : Node(_x, _y, _group) constr
|
|||
.setArrayDepth(1)
|
||||
.setVisible(true, true);
|
||||
|
||||
newInput(1, nodeValue_Float("Step", self, 1))
|
||||
.setVisible(true, true);
|
||||
newInput(1, nodeValue_Float("Step", self, 1));
|
||||
|
||||
newInput(2, nodeValue_Enum_Scroll("Mode", self, 0, [ "Uniform", "Random" ]))
|
||||
|
||||
newInput(3, nodeValue_Int("Shift", self, 0))
|
||||
|
||||
newInput(4, nodeValueSeed(self, VALUE_TYPE.float));
|
||||
|
||||
newInput(5, nodeValue_Int("Amount", self, 4))
|
||||
|
||||
newOutput(0, nodeValue_Output("Array", self, VALUE_TYPE.float, 0))
|
||||
.setArrayDepth(1);
|
||||
|
||||
static sample = function(arr, stp) {
|
||||
input_display_list = [ 0, 2,
|
||||
1, 3,
|
||||
4, 5,
|
||||
];
|
||||
|
||||
static sample = function(arr) {
|
||||
__temp_arr = arr;
|
||||
__temp_stp = stp;
|
||||
|
||||
var _len = floor(array_length(arr));
|
||||
var _siz = floor(_len / stp);
|
||||
var _mod = getInputData(2);
|
||||
var _len = array_length(arr);
|
||||
|
||||
if(_mod == 0) {
|
||||
|
||||
var _stp = getInputData(1);
|
||||
var _shf = getInputData(3);
|
||||
_shf = safe_mod(_shf, _stp);
|
||||
|
||||
var _res = [];
|
||||
var _ind = 0;
|
||||
|
||||
for( var i = _shf; i < _len; i += _stp )
|
||||
_res[_ind++] = arr[i];
|
||||
|
||||
return _res;
|
||||
|
||||
} else if(_mod == 1) {
|
||||
|
||||
var _sed = getInputData(4);
|
||||
var _amo = getInputData(5);
|
||||
|
||||
var _res = array_create(_amo);
|
||||
|
||||
random_set_seed(_sed);
|
||||
for( var i = 0; i < _amo; i++ )
|
||||
_res[i] = arr[irandom(_len - 1)];
|
||||
|
||||
return _res;
|
||||
}
|
||||
|
||||
var _res = array_create_ext(_siz, function(_i) {
|
||||
return __temp_arr[_i * __temp_stp];
|
||||
});
|
||||
|
||||
return _res;
|
||||
return [];
|
||||
}
|
||||
|
||||
static update = function(frame = CURRENT_FRAME) {
|
||||
var _arr = getInputData(0);
|
||||
var _stp = getInputData(1);
|
||||
var _mod = getInputData(2);
|
||||
|
||||
inputs[1].setVisible(_mod == 0);
|
||||
inputs[3].setVisible(_mod == 0);
|
||||
|
||||
inputs[4].setVisible(_mod == 1);
|
||||
inputs[5].setVisible(_mod == 1);
|
||||
|
||||
if(array_empty(_arr)) return;
|
||||
|
||||
|
@ -36,9 +77,9 @@ function Node_Array_Sample(_x, _y, _group = noone) : Node(_x, _y, _group) constr
|
|||
|
||||
if(is_array(_arr[0])) {
|
||||
for( var i = 0, n = array_length(_arr); i < n; i++ )
|
||||
res[i] = sample(_arr[i], _stp);
|
||||
res[i] = sample(_arr[i]);
|
||||
} else
|
||||
res = sample(_arr, _stp);
|
||||
res = sample(_arr);
|
||||
|
||||
outputs[0].setValue(res);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue