mirror of
https://github.com/Ttanasart-pt/Pixel-Composer.git
synced 2025-02-03 00:35:14 +01:00
fn math
This commit is contained in:
parent
733ed54fc4
commit
46d2787b98
12 changed files with 265 additions and 11 deletions
|
@ -754,6 +754,10 @@
|
||||||
{"name":"node_flip","order":13,"path":"scripts/node_flip/node_flip.yy",},
|
{"name":"node_flip","order":13,"path":"scripts/node_flip/node_flip.yy",},
|
||||||
{"name":"node_flood_fill","order":3,"path":"scripts/node_flood_fill/node_flood_fill.yy",},
|
{"name":"node_flood_fill","order":3,"path":"scripts/node_flood_fill/node_flood_fill.yy",},
|
||||||
{"name":"node_flow_noise","order":18,"path":"scripts/node_flow_noise/node_flow_noise.yy",},
|
{"name":"node_flow_noise","order":18,"path":"scripts/node_flow_noise/node_flow_noise.yy",},
|
||||||
|
{"name":"node_fn_constant","order":3,"path":"scripts/node_fn_constant/node_fn_constant.yy",},
|
||||||
|
{"name":"node_fn_ease","order":5,"path":"scripts/node_fn_ease/node_fn_ease.yy",},
|
||||||
|
{"name":"node_fn_math","order":6,"path":"scripts/node_fn_math/node_fn_math.yy",},
|
||||||
|
{"name":"node_fn_smoothstep","order":4,"path":"scripts/node_fn_smoothstep/node_fn_smoothstep.yy",},
|
||||||
{"name":"node_fn_wave_table","order":1,"path":"scripts/node_fn_wave_table/node_fn_wave_table.yy",},
|
{"name":"node_fn_wave_table","order":1,"path":"scripts/node_fn_wave_table/node_fn_wave_table.yy",},
|
||||||
{"name":"node_fn","order":2,"path":"scripts/node_fn/node_fn.yy",},
|
{"name":"node_fn","order":2,"path":"scripts/node_fn/node_fn.yy",},
|
||||||
{"name":"node_fold_noise","order":14,"path":"scripts/node_fold_noise/node_fold_noise.yy",},
|
{"name":"node_fold_noise","order":14,"path":"scripts/node_fold_noise/node_fold_noise.yy",},
|
||||||
|
|
|
@ -1172,6 +1172,10 @@
|
||||||
{"id":{"name":"node_flip","path":"scripts/node_flip/node_flip.yy",},},
|
{"id":{"name":"node_flip","path":"scripts/node_flip/node_flip.yy",},},
|
||||||
{"id":{"name":"node_flood_fill","path":"scripts/node_flood_fill/node_flood_fill.yy",},},
|
{"id":{"name":"node_flood_fill","path":"scripts/node_flood_fill/node_flood_fill.yy",},},
|
||||||
{"id":{"name":"node_flow_noise","path":"scripts/node_flow_noise/node_flow_noise.yy",},},
|
{"id":{"name":"node_flow_noise","path":"scripts/node_flow_noise/node_flow_noise.yy",},},
|
||||||
|
{"id":{"name":"node_fn_constant","path":"scripts/node_fn_constant/node_fn_constant.yy",},},
|
||||||
|
{"id":{"name":"node_fn_ease","path":"scripts/node_fn_ease/node_fn_ease.yy",},},
|
||||||
|
{"id":{"name":"node_fn_math","path":"scripts/node_fn_math/node_fn_math.yy",},},
|
||||||
|
{"id":{"name":"node_fn_smoothstep","path":"scripts/node_fn_smoothstep/node_fn_smoothstep.yy",},},
|
||||||
{"id":{"name":"node_fn_wave_table","path":"scripts/node_fn_wave_table/node_fn_wave_table.yy",},},
|
{"id":{"name":"node_fn_wave_table","path":"scripts/node_fn_wave_table/node_fn_wave_table.yy",},},
|
||||||
{"id":{"name":"node_fn_wiggler","path":"scripts/node_fn_wiggler/node_fn_wiggler.yy",},},
|
{"id":{"name":"node_fn_wiggler","path":"scripts/node_fn_wiggler/node_fn_wiggler.yy",},},
|
||||||
{"id":{"name":"node_fn","path":"scripts/node_fn/node_fn.yy",},},
|
{"id":{"name":"node_fn","path":"scripts/node_fn/node_fn.yy",},},
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
function Node_Fn(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
|
function Node_Fn(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
|
||||||
name = "Fn";
|
name = "Fn";
|
||||||
|
time_based = true;
|
||||||
update_on_frame = true;
|
update_on_frame = true;
|
||||||
setDimension(96, 96);
|
setDimension(96, 96);
|
||||||
|
|
||||||
|
@ -15,7 +16,8 @@ function Node_Fn(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constr
|
||||||
];
|
];
|
||||||
|
|
||||||
text_display = 0;
|
text_display = 0;
|
||||||
graph_display = array_create(64, 0);
|
graph_res = 64;
|
||||||
|
graph_display = array_create(graph_res, 0);
|
||||||
graph_display_min = 0;
|
graph_display_min = 0;
|
||||||
graph_display_max = 0;
|
graph_display_max = 0;
|
||||||
|
|
||||||
|
@ -25,14 +27,17 @@ function Node_Fn(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constr
|
||||||
graph_display_min = undefined;
|
graph_display_min = undefined;
|
||||||
graph_display_max = undefined;
|
graph_display_max = undefined;
|
||||||
|
|
||||||
for( var i = 0; i < 64; i++ ) {
|
for( var i = 0; i < graph_res; i++ ) {
|
||||||
var _c = __fnEval(i / 64);
|
var _c = __fnEval(refreshDisplayX(i));
|
||||||
graph_display[i] = _c;
|
graph_display[i] = _c;
|
||||||
graph_display_min = graph_display_min == undefined? _c : min(graph_display_min, _c);
|
graph_display_min = graph_display_min == undefined? _c : min(graph_display_min, _c);
|
||||||
graph_display_max = graph_display_max == undefined? _c : max(graph_display_max, _c);
|
graph_display_max = graph_display_max == undefined? _c : max(graph_display_max, _c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static refreshDisplayX = function(i) { return i / graph_res; }
|
||||||
|
static getDisplayX = function(i) { return graph_display[i]; }
|
||||||
|
|
||||||
static postPostProcess = function() { if(!IS_PLAYING) refreshDisplay(); }
|
static postPostProcess = function() { if(!IS_PLAYING) refreshDisplay(); }
|
||||||
|
|
||||||
static processData = function(_output, _data, _output_index, _array_index = 0) { }
|
static processData = function(_output, _data, _output_index, _array_index = 0) { }
|
||||||
|
@ -72,10 +77,10 @@ function Node_Fn(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constr
|
||||||
draw_set_text(f_sdf, fa_right, fa_bottom, COLORS._main_text_sub);
|
draw_set_text(f_sdf, fa_right, fa_bottom, COLORS._main_text_sub);
|
||||||
draw_text_transformed(x1 - 2 * _s, y1, text_display, 0.3 * _s, 0.3 * _s, 0);
|
draw_text_transformed(x1 - 2 * _s, y1, text_display, 0.3 * _s, 0.3 * _s, 0);
|
||||||
|
|
||||||
var lw = ww / (64 - 1);
|
var lw = ww / (graph_res - 1);
|
||||||
var ox, oy;
|
var ox, oy;
|
||||||
draw_set_color(c_white);
|
draw_set_color(c_white);
|
||||||
for( var i = 0; i < 64; i++ ) {
|
for( var i = 0; i < graph_res; i++ ) {
|
||||||
var _x = x0 + i * lw;
|
var _x = x0 + i * lw;
|
||||||
var _y = yc - (graph_display[i] - val) / _ran * hh;
|
var _y = yc - (graph_display[i] - val) / _ran * hh;
|
||||||
if(i) draw_line(ox, oy, _x, _y);
|
if(i) draw_line(ox, oy, _x, _y);
|
||||||
|
@ -83,9 +88,12 @@ function Node_Fn(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constr
|
||||||
ox = _x;
|
ox = _x;
|
||||||
oy = _y;
|
oy = _y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(time_based) {
|
||||||
draw_set_color(COLORS._main_accent);
|
draw_set_color(COLORS._main_accent);
|
||||||
var _fx = x0 + (time / total_time * ww);
|
var _fx = x0 + (time / total_time * ww);
|
||||||
draw_line(_fx, y0, _fx, y1);
|
draw_line(_fx, y0, _fx, y1);
|
||||||
|
}
|
||||||
|
|
||||||
draw_set_color(COLORS.node_wiggler_frame);
|
draw_set_color(COLORS.node_wiggler_frame);
|
||||||
draw_rectangle(x0, y0, x1, y1, true);
|
draw_rectangle(x0, y0, x1, y1, true);
|
||||||
|
|
25
scripts/node_fn_constant/node_fn_constant.gml
Normal file
25
scripts/node_fn_constant/node_fn_constant.gml
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
function Node_Fn_Constant(_x, _y, _group = noone) : Node_Fn(_x, _y, _group) constructor {
|
||||||
|
name = "Constant";
|
||||||
|
|
||||||
|
inputs[| inl + 0] = nodeValue("Value", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0 );
|
||||||
|
|
||||||
|
array_append(input_display_list, [
|
||||||
|
["Value", false], inl + 0
|
||||||
|
]);
|
||||||
|
|
||||||
|
value = 0;
|
||||||
|
|
||||||
|
static __fnEval = function(_x = 0) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
static processData = function(_output, _data, _output_index, _array_index = 0) { #region
|
||||||
|
value = _data[inl + 0];
|
||||||
|
|
||||||
|
var val = __fnEval(CURRENT_FRAME / TOTAL_FRAMES);
|
||||||
|
text_display = val;
|
||||||
|
|
||||||
|
return val;
|
||||||
|
} #endregion
|
||||||
|
|
||||||
|
}
|
13
scripts/node_fn_constant/node_fn_constant.yy
Normal file
13
scripts/node_fn_constant/node_fn_constant.yy
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
{
|
||||||
|
"$GMScript":"",
|
||||||
|
"%Name":"node_fn_constant",
|
||||||
|
"isCompatibility":false,
|
||||||
|
"isDnD":false,
|
||||||
|
"name":"node_fn_constant",
|
||||||
|
"parent":{
|
||||||
|
"name":"fn",
|
||||||
|
"path":"folders/nodes/data/animation/fn.yy",
|
||||||
|
},
|
||||||
|
"resourceType":"GMScript",
|
||||||
|
"resourceVersion":"2.0",
|
||||||
|
}
|
56
scripts/node_fn_ease/node_fn_ease.gml
Normal file
56
scripts/node_fn_ease/node_fn_ease.gml
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
function Node_Fn_Ease(_x, _y, _group = noone) : Node_Fn(_x, _y, _group) constructor {
|
||||||
|
name = "Ease";
|
||||||
|
|
||||||
|
inputs[| inl + 0] = nodeValue("Range", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0, 1 ] )
|
||||||
|
.setDisplay(VALUE_DISPLAY.slider_range );
|
||||||
|
|
||||||
|
inputs[| inl + 1] = nodeValue("Amount", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 0.1, 0.9 ] )
|
||||||
|
.setDisplay(VALUE_DISPLAY.slider_range );
|
||||||
|
|
||||||
|
inputs[| inl + 2] = nodeValue("Smooth", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0 )
|
||||||
|
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "Cubic poly", "Quadratic rat", "Cubic rat", "Cosine" ] );
|
||||||
|
|
||||||
|
array_append(input_display_list, [
|
||||||
|
["Value", false], inl + 0, inl + 1, inl + 2,
|
||||||
|
]);
|
||||||
|
|
||||||
|
rang = [ 0, 1 ];
|
||||||
|
ease = [ 0, 1 ];
|
||||||
|
type = 0;
|
||||||
|
|
||||||
|
static __smooth = function(_x = 0) {
|
||||||
|
switch(type) {
|
||||||
|
case 0 : return _x * _x * (3.0 - 2.0 * _x);
|
||||||
|
case 1 : return _x * _x / (2.0 * _x * _x - 2.0 * _x + 1.0);
|
||||||
|
case 2 : return _x * _x * _x / (3.0 * _x * _x - 3.0 * _x + 1.0);
|
||||||
|
case 3 : return 0.5 - 0.5 * cos(pi * _x);
|
||||||
|
}
|
||||||
|
|
||||||
|
return _x;
|
||||||
|
}
|
||||||
|
|
||||||
|
static __fnEval = function(_x = 0) {
|
||||||
|
if(_x < rang[0] || _x > rang[1]) return 0;
|
||||||
|
|
||||||
|
var _eo = 1 - ease[1];
|
||||||
|
|
||||||
|
var _v = clamp(min(
|
||||||
|
ease[0] == 0? 1 : (_x - rang[0]) / ease[0],
|
||||||
|
_eo == 0? 1 : 1 - (_x - (rang[1] - _eo)) / _eo,
|
||||||
|
), 0, 1);
|
||||||
|
|
||||||
|
return __smooth(_v);
|
||||||
|
}
|
||||||
|
|
||||||
|
static processData = function(_output, _data, _output_index, _array_index = 0) { #region
|
||||||
|
rang = _data[inl + 0];
|
||||||
|
ease = _data[inl + 1];
|
||||||
|
type = _data[inl + 2];
|
||||||
|
|
||||||
|
var val = __fnEval(CURRENT_FRAME / TOTAL_FRAMES);
|
||||||
|
text_display = val;
|
||||||
|
|
||||||
|
return val;
|
||||||
|
} #endregion
|
||||||
|
|
||||||
|
}
|
13
scripts/node_fn_ease/node_fn_ease.yy
Normal file
13
scripts/node_fn_ease/node_fn_ease.yy
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
{
|
||||||
|
"$GMScript":"",
|
||||||
|
"%Name":"node_fn_ease",
|
||||||
|
"isCompatibility":false,
|
||||||
|
"isDnD":false,
|
||||||
|
"name":"node_fn_ease",
|
||||||
|
"parent":{
|
||||||
|
"name":"fn",
|
||||||
|
"path":"folders/nodes/data/animation/fn.yy",
|
||||||
|
},
|
||||||
|
"resourceType":"GMScript",
|
||||||
|
"resourceVersion":"2.0",
|
||||||
|
}
|
56
scripts/node_fn_math/node_fn_math.gml
Normal file
56
scripts/node_fn_math/node_fn_math.gml
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
function Node_Fn_Math(_x, _y, _group = noone) : Node_Fn(_x, _y, _group) constructor {
|
||||||
|
name = "Math";
|
||||||
|
time_based = false;
|
||||||
|
|
||||||
|
inputs[| inl + 0] = nodeValue("Operation", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 2 )
|
||||||
|
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "Add", "Minus", "Multiply" ] );
|
||||||
|
|
||||||
|
inputs[| inl + 1] = nodeValue("Value 1", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0 )
|
||||||
|
.setVisible(true, true);
|
||||||
|
|
||||||
|
inputs[| inl + 2] = nodeValue("Value 2", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0 )
|
||||||
|
.setVisible(true, true);
|
||||||
|
|
||||||
|
array_append(input_display_list, [
|
||||||
|
["Value", false], inl + 0, inl + 1, inl + 2,
|
||||||
|
]);
|
||||||
|
|
||||||
|
type = 0;
|
||||||
|
|
||||||
|
static __fnEval = function(_x) {
|
||||||
|
switch(type) {
|
||||||
|
case 0 : return _x[0] + _x[1];
|
||||||
|
case 1 : return _x[0] - _x[1];
|
||||||
|
case 2 : return _x[0] * _x[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static refreshDisplayX = function(i) {
|
||||||
|
var _v0 = getSingleValue(inl + 1);
|
||||||
|
var _v1 = getSingleValue(inl + 2);
|
||||||
|
|
||||||
|
var _f0 = inputs[| inl + 1].value_from;
|
||||||
|
if(_f0 != noone && is_instanceof(_f0.node, Node_Fn))
|
||||||
|
_v0 = _f0.node.getDisplayX(i);
|
||||||
|
|
||||||
|
var _f1 = inputs[| inl + 2].value_from;
|
||||||
|
if(_f1 != noone && is_instanceof(_f1.node, Node_Fn))
|
||||||
|
_v1 = _f1.node.getDisplayX(i);
|
||||||
|
|
||||||
|
return [ _v0, _v1 ];
|
||||||
|
}
|
||||||
|
|
||||||
|
static processData = function(_output, _data, _output_index, _array_index = 0) { #region
|
||||||
|
type = _data[inl + 0];
|
||||||
|
var v0 = _data[inl + 1];
|
||||||
|
var v1 = _data[inl + 2];
|
||||||
|
|
||||||
|
var val = __fnEval([ v0, v1 ]);
|
||||||
|
|
||||||
|
text_display = val;
|
||||||
|
return val;
|
||||||
|
} #endregion
|
||||||
|
|
||||||
|
}
|
13
scripts/node_fn_math/node_fn_math.yy
Normal file
13
scripts/node_fn_math/node_fn_math.yy
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
{
|
||||||
|
"$GMScript":"",
|
||||||
|
"%Name":"node_fn_math",
|
||||||
|
"isCompatibility":false,
|
||||||
|
"isDnD":false,
|
||||||
|
"name":"node_fn_math",
|
||||||
|
"parent":{
|
||||||
|
"name":"fn",
|
||||||
|
"path":"folders/nodes/data/animation/fn.yy",
|
||||||
|
},
|
||||||
|
"resourceType":"GMScript",
|
||||||
|
"resourceVersion":"2.0",
|
||||||
|
}
|
46
scripts/node_fn_smoothstep/node_fn_smoothstep.gml
Normal file
46
scripts/node_fn_smoothstep/node_fn_smoothstep.gml
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
function Node_Fn_SmoothStep(_x, _y, _group = noone) : Node_Fn(_x, _y, _group) constructor {
|
||||||
|
name = "SmoothStep";
|
||||||
|
time_based = false;
|
||||||
|
|
||||||
|
inputs[| inl + 0] = nodeValue("Value", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0 )
|
||||||
|
.setVisible(true, true);
|
||||||
|
|
||||||
|
inputs[| inl + 1] = nodeValue("Type", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0 )
|
||||||
|
.setDisplay(VALUE_DISPLAY.enum_scroll, [ "Cubic poly", "Quadratic rat", "Cubic rat", "Cosine" ] );
|
||||||
|
|
||||||
|
array_append(input_display_list, [
|
||||||
|
["Value", false], inl + 1, inl + 0,
|
||||||
|
]);
|
||||||
|
|
||||||
|
type = 0;
|
||||||
|
value = 0;
|
||||||
|
|
||||||
|
static __fnEval = function(_x = 0) {
|
||||||
|
switch(type) {
|
||||||
|
case 0 : return _x * _x * (3.0 - 2.0 * _x);
|
||||||
|
case 1 : return _x * _x / (2.0 * _x * _x - 2.0 * _x + 1.0);
|
||||||
|
case 2 : return _x * _x * _x / (3.0 * _x * _x - 3.0 * _x + 1.0);
|
||||||
|
case 3 : return 0.5 - 0.5 * cos(pi * _x);
|
||||||
|
}
|
||||||
|
|
||||||
|
return _x;
|
||||||
|
}
|
||||||
|
|
||||||
|
static refreshDisplayX = function(i) {
|
||||||
|
var _fr = inputs[| inl + 0].value_from;
|
||||||
|
if(_fr != noone && is_instanceof(_fr.node, Node_Fn))
|
||||||
|
return _fr.node.getDisplayX(i);
|
||||||
|
return i / graph_res;
|
||||||
|
}
|
||||||
|
|
||||||
|
static processData = function(_output, _data, _output_index, _array_index = 0) { #region
|
||||||
|
value = _data[inl + 0];
|
||||||
|
type = _data[inl + 1];
|
||||||
|
|
||||||
|
var val = __fnEval(value);
|
||||||
|
|
||||||
|
text_display = val;
|
||||||
|
return val;
|
||||||
|
} #endregion
|
||||||
|
|
||||||
|
}
|
13
scripts/node_fn_smoothstep/node_fn_smoothstep.yy
Normal file
13
scripts/node_fn_smoothstep/node_fn_smoothstep.yy
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
{
|
||||||
|
"$GMScript":"",
|
||||||
|
"%Name":"node_fn_smoothstep",
|
||||||
|
"isCompatibility":false,
|
||||||
|
"isDnD":false,
|
||||||
|
"name":"node_fn_smoothstep",
|
||||||
|
"parent":{
|
||||||
|
"name":"fn",
|
||||||
|
"path":"folders/nodes/data/animation/fn.yy",
|
||||||
|
},
|
||||||
|
"resourceType":"GMScript",
|
||||||
|
"resourceVersion":"2.0",
|
||||||
|
}
|
|
@ -955,6 +955,9 @@ function __initNodes() {
|
||||||
ds_list_add(animation, "Value");
|
ds_list_add(animation, "Value");
|
||||||
addNodeObject(animation, "WaveTable", s_node_wave, "Node_Fn_WaveTable", [1, Node_Fn_WaveTable],, "Create value changing overtime in wave pattern.");
|
addNodeObject(animation, "WaveTable", s_node_wave, "Node_Fn_WaveTable", [1, Node_Fn_WaveTable],, "Create value changing overtime in wave pattern.");
|
||||||
addNodeObject(animation, "Wiggler", s_node_wiggler, "Node_Wiggler", [1, Node_Wiggler],, "Create random value smoothly changing over time.");
|
addNodeObject(animation, "Wiggler", s_node_wiggler, "Node_Wiggler", [1, Node_Wiggler],, "Create random value smoothly changing over time.");
|
||||||
|
addNodeObject(animation, "Ease", s_node_ease, "Node_Fn_Ease", [1, Node_Fn_Ease],, "");
|
||||||
|
addNodeObject(animation, "Math", s_node_fx_math, "Node_Fn_Math", [1, Node_Fn_Math],, "");
|
||||||
|
addNodeObject(animation, "SmoothStep", s_node_fx_smoothstep, "Node_Fn_SmoothStep", [1, Node_Fn_SmoothStep],, "");
|
||||||
|
|
||||||
ds_list_add(animation, "Audio");
|
ds_list_add(animation, "Audio");
|
||||||
addNodeObject(animation, "WAV File In", s_node_wav_file_read, "Node_WAV_File_Read", [0, Node_create_WAV_File_Read],, "Load wav audio file.").setVersion(1144);
|
addNodeObject(animation, "WAV File In", s_node_wav_file_read, "Node_WAV_File_Read", [0, Node_create_WAV_File_Read],, "Load wav audio file.").setVersion(1144);
|
||||||
|
|
Loading…
Reference in a new issue