2022-01-13 05:24:03 +01:00
|
|
|
function Node_create_Wiggler(_x, _y) {
|
|
|
|
var node = new Node_Wiggler(_x, _y);
|
|
|
|
ds_list_add(PANEL_GRAPH.nodes_list, node);
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
function Node_Wiggler(_x, _y) : Node_Value_Processor(_x, _y) constructor {
|
|
|
|
name = "Wiggler";
|
|
|
|
update_on_frame = true;
|
|
|
|
previewable = false;
|
|
|
|
|
|
|
|
w = 96;
|
|
|
|
min_h = 0;
|
|
|
|
|
2022-09-23 13:28:42 +02:00
|
|
|
inputs[| 0] = nodeValue(0, "Range", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [0, 1])
|
|
|
|
.setDisplay(VALUE_DISPLAY.vector);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-09-23 13:28:42 +02:00
|
|
|
inputs[| 1] = nodeValue(1, "Frequency", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, [ 3, 5 ] )
|
2022-09-21 06:09:40 +02:00
|
|
|
.setDisplay(VALUE_DISPLAY.slider_range, [1, 32, 1]);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-09-23 13:28:42 +02:00
|
|
|
inputs[| 2] = nodeValue(2, "Seed", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, irandom(9999999) );
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-09-23 13:28:42 +02:00
|
|
|
inputs[| 3] = nodeValue(3, "Display", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 1 )
|
2022-09-21 06:09:40 +02:00
|
|
|
.setDisplay(VALUE_DISPLAY.enum_scroll, ["Number", "Graph"])
|
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
outputs[| 0] = nodeValue(0, "Output", self, JUNCTION_CONNECT.output, VALUE_TYPE.float, 0);
|
|
|
|
|
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
|
|
|
|
|
|
|
static onValueUpdate = function(index) {
|
2022-09-23 13:28:42 +02:00
|
|
|
var ran = inputs[| 0].getValue();
|
|
|
|
var fre = inputs[| 1].getValue();
|
|
|
|
var sed = inputs[| 2].getValue();
|
2022-09-21 06:09:40 +02:00
|
|
|
|
|
|
|
var _fmin = ANIMATOR.frames_total / max(1, min(fre[0], fre[1]));
|
|
|
|
var _fmax = ANIMATOR.frames_total / max(1, max(fre[0], fre[1]));
|
|
|
|
var _val;
|
|
|
|
|
2022-11-14 03:16:15 +01:00
|
|
|
for( var i = 0; i < ANIMATOR.frames_total + 1; i++ ) {
|
2022-09-23 13:28:42 +02:00
|
|
|
_val = getWiggle(ran[0], ran[1], _fmin, _fmax, i, sed);
|
2022-11-14 03:16:15 +01:00
|
|
|
random_value[i] = _val;
|
2022-09-21 06:09:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
function process_value_data(_data, index = 0) {
|
2022-11-14 03:16:15 +01:00
|
|
|
if(array_length(random_value) != ANIMATOR.frames_total + 1) {
|
|
|
|
array_resize(random_value, ANIMATOR.frames_total + 1);
|
|
|
|
onValueUpdate(0);
|
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-11-14 03:16:15 +01:00
|
|
|
var time = ANIMATOR.current_frame;
|
|
|
|
return random_value[time];
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
doUpdate();
|
|
|
|
|
|
|
|
static onDrawNode = function(xx, yy, _mx, _my, _s) {
|
2022-11-14 03:16:15 +01:00
|
|
|
if(array_length(random_value) != ANIMATOR.frames_total + 1) {
|
|
|
|
array_resize(random_value, ANIMATOR.frames_total + 1);
|
|
|
|
onValueUpdate(0);
|
|
|
|
}
|
|
|
|
|
2022-09-23 13:28:42 +02:00
|
|
|
var disp = inputs[| 3].getValue();
|
2022-09-21 06:09:40 +02:00
|
|
|
var time = ANIMATOR.current_frame;
|
|
|
|
var total_time = ANIMATOR.frames_total;
|
|
|
|
|
|
|
|
switch(disp) {
|
|
|
|
case 0 :
|
|
|
|
min_h = 0;
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_set_text(f_h5, fa_center, fa_center, COLORS._main_text);
|
2022-11-14 03:16:15 +01:00
|
|
|
var str = string(random_value[time]);
|
2022-09-21 06:09:40 +02:00
|
|
|
var ss = string_scale(str, (w - 16) * _s, (h - 16) * _s - 20);
|
|
|
|
draw_text_transformed(xx + w / 2 * _s, yy + 10 + h / 2 * _s, str, ss, ss, 0);
|
|
|
|
break;
|
|
|
|
case 1 :
|
|
|
|
w = 128;
|
|
|
|
min_h = 96;
|
|
|
|
|
2022-09-23 13:28:42 +02:00
|
|
|
var ran = inputs[| 0].getValue();
|
|
|
|
var fre = inputs[| 1].getValue();
|
|
|
|
var sed = inputs[| 2].getValue();
|
|
|
|
|
|
|
|
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 _fmin = max(1, fre[0]);
|
|
|
|
var _fmax = max(1, fre[1]);
|
|
|
|
|
|
|
|
var x0 = xx + 8 * _s;
|
|
|
|
var x1 = xx + (w - 8) * _s;
|
|
|
|
var y0 = yy + 20 + 8 * _s;
|
|
|
|
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);
|
2022-09-21 06:09:40 +02:00
|
|
|
draw_line(x0, yc, x1, yc);
|
|
|
|
var _fx = x0 + (time / total_time * ww);
|
|
|
|
draw_line(_fx, y0, _fx, y1);
|
|
|
|
|
2022-11-14 03:16:15 +01:00
|
|
|
var lw = ww / (array_length(random_value) - 1);
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_set_color(COLORS.node_wiggler_line);
|
2022-09-21 06:09:40 +02:00
|
|
|
var ox, oy;
|
2022-11-14 03:16:15 +01:00
|
|
|
for( var i = 0; i < array_length(random_value); i++ ) {
|
2022-09-21 06:09:40 +02:00
|
|
|
var _x = x0 + i * lw;
|
2022-11-14 03:16:15 +01:00
|
|
|
var _y = yc - (random_value[i] - val) / (_ran * 2) * hh;
|
2022-09-21 06:09:40 +02:00
|
|
|
if(i)
|
|
|
|
draw_line(ox, oy, _x, _y);
|
|
|
|
|
|
|
|
ox = _x;
|
|
|
|
oy = _y;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
}
|