Pixel-Composer/scripts/node_wiggler/node_wiggler.gml

104 lines
3.4 KiB
Plaintext
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_Wiggler(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
2022-01-13 05:24:03 +01:00
name = "Wiggler";
update_on_frame = true;
2024-03-28 14:18:02 +01:00
setDimension(96, 96);
2023-01-17 08:11:55 +01:00
2023-12-10 14:55:05 +01:00
inputs[| 0] = nodeValue("Range", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 1 ])
2022-09-23 13:28:42 +02:00
.setDisplay(VALUE_DISPLAY.vector);
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 1] = nodeValue("Frequency", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 4 )
2024-03-24 04:58:08 +01:00
.setDisplay(VALUE_DISPLAY.slider, { range: [1, 32, 0.1] });
2022-01-13 05:24:03 +01:00
2023-12-10 14:55:05 +01:00
inputs[| 2] = nodeValue("Seed", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, irandom_range(1000000, 9999999) );
2022-01-13 05:24:03 +01:00
2023-02-14 05:32:32 +01:00
inputs[| 3] = nodeValue("Display", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 1 )
2023-12-10 14:55:05 +01:00
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "Number", "Graph" ])
2022-09-21 06:09:40 +02:00
2023-02-14 05:32:32 +01:00
outputs[| 0] = nodeValue("Output", self, JUNCTION_CONNECT.output, VALUE_TYPE.float, 0);
2022-01-13 05:24:03 +01:00
2022-09-21 06:09:40 +02:00
input_display_list = [
2022-09-23 13:28:42 +02:00
["Display", true], 3,
["Wiggle", false], 2, 0, 1,
2022-09-21 06:09:40 +02:00
];
2022-11-14 03:16:15 +01:00
random_value = array_create(64, 0);
2022-09-21 06:09:40 +02:00
2023-12-10 14:55:05 +01:00
static onValueUpdate = function(index = 0) { #region
2023-02-14 05:32:32 +01:00
var ran = getSingleValue(0);
var fre = getSingleValue(1);
var sed = getSingleValue(2);
2022-09-21 06:09:40 +02:00
2023-10-09 16:07:33 +02:00
var step = TOTAL_FRAMES / 64;
2023-02-14 05:32:32 +01:00
for( var i = 0; i < 64; i++ )
2024-03-31 05:36:11 +02:00
random_value[i] = getWiggle(array_safe_get_fast(ran, 0), array_safe_get_fast(ran, 1), TOTAL_FRAMES / fre, step * i, sed, 0, TOTAL_FRAMES);
2023-12-10 14:55:05 +01:00
} run_in(1, function() { onValueUpdate(); }); #endregion
2022-09-21 06:09:40 +02:00
2023-12-10 14:55:05 +01:00
static processData = function(_output, _data, _output_index, _array_index = 0) { #region
2023-02-14 05:32:32 +01:00
var ran = _data[0];
var fre = _data[1];
var sed = _data[2];
2023-10-09 16:07:33 +02:00
var time = CURRENT_FRAME;
2022-12-12 09:08:03 +01:00
2024-03-31 05:36:11 +02:00
return getWiggle(array_safe_get_fast(ran, 0), array_safe_get_fast(ran, 1), TOTAL_FRAMES / fre, time, sed, 0, TOTAL_FRAMES);
2023-12-10 14:55:05 +01:00
} #endregion
2022-01-13 05:24:03 +01:00
2023-12-10 14:55:05 +01:00
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) { #region
2024-03-31 05:36:11 +02:00
var ran = array_safe_get_fast(current_data, 0);
var fre = array_safe_get_fast(current_data, 1);
var sed = array_safe_get_fast(current_data, 2);
var disp = array_safe_get_fast(current_data, 3);
2023-10-09 16:07:33 +02:00
var time = CURRENT_FRAME;
var total_time = TOTAL_FRAMES;
2022-09-21 06:09:40 +02:00
2023-11-29 03:04:28 +01:00
if(!is_array(ran)) return;
2022-09-21 06:09:40 +02:00
switch(disp) {
case 0 :
draw_set_text(f_sdf, fa_center, fa_center, COLORS._main_text);
2023-10-09 16:07:33 +02:00
var str = getWiggle(ran[0], ran[1], TOTAL_FRAMES / fre, time, sed, 0, TOTAL_FRAMES);
2023-01-04 02:30:04 +01:00
var ss = string_scale(str, (w - 16) * _s, (h - 16) * _s - 20 * draw_name);
2022-09-21 06:09:40 +02:00
draw_text_transformed(xx + w / 2 * _s, yy + 10 + h / 2 * _s, str, ss, ss, 0);
break;
2024-03-28 14:18:02 +01:00
case 1 :
2022-09-23 13:28:42 +02:00
var _min = ran[0];
var _max = ran[1];
var val = (_min + _max) / 2;
var _ran = _max - _min;
2022-09-21 06:09:40 +02:00
var x0 = xx + 8 * _s;
var x1 = xx + (w - 8) * _s;
2023-01-04 02:30:04 +01:00
var y0 = yy + 20 * draw_name + 8 * _s;
2022-09-21 06:09:40 +02:00
var y1 = yy + (h - 8) * _s;
var ww = x1 - x0;
var hh = y1 - y0;
var yc = (y0 + y1) / 2;
2022-11-18 03:20:31 +01:00
draw_set_color(COLORS.node_wiggler_frame);
2023-12-10 14:55:05 +01:00
draw_set_alpha(0.5);
2022-09-21 06:09:40 +02:00
draw_line(x0, yc, x1, yc);
2023-12-10 14:55:05 +01:00
draw_set_alpha(1);
2022-09-21 06:09:40 +02:00
2022-12-12 09:08:03 +01:00
var lw = ww / (64 - 1);
2022-09-21 06:09:40 +02:00
var ox, oy;
2023-12-10 14:55:05 +01:00
draw_set_color(c_white);
2022-12-12 09:08:03 +01:00
for( var i = 0; i < 64; i++ ) {
2022-09-21 06:09:40 +02:00
var _x = x0 + i * lw;
2023-01-09 03:14:20 +01:00
var _y = yc - (random_value[i] - val) / _ran * hh;
2023-12-10 14:55:05 +01:00
if(i) draw_line(ox, oy, _x, _y);
2022-09-21 06:09:40 +02:00
ox = _x;
oy = _y;
}
2023-12-10 14:55:05 +01:00
draw_set_color(COLORS._main_accent);
var _fx = x0 + (time / total_time * ww);
draw_line(_fx, y0, _fx, y1);
2022-09-21 06:09:40 +02:00
2022-11-18 03:20:31 +01:00
draw_set_color(COLORS.node_wiggler_frame);
2022-09-21 06:09:40 +02:00
draw_rectangle(x0, y0, x1, y1, true);
break;
}
2023-12-10 14:55:05 +01:00
} #endregion
static doApplyDeserialize = function() { onValueUpdate(); }
2022-01-13 05:24:03 +01:00
}