Pixel-Composer/scripts/node_path_plot/node_path_plot.gml

271 lines
6.7 KiB
Text
Raw Normal View History

2023-03-11 01:40:17 +01:00
function Node_Path_Plot(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
name = "Plot Path";
2023-08-02 19:11:57 +02:00
length = 0;
setDimension(96, 48);
2023-03-11 01:40:17 +01:00
2024-08-18 06:16:20 +02:00
newInput(0, nodeValue_Vec2("Output scale", self, [ 8, 8 ]));
2023-03-11 01:40:17 +01:00
2024-08-20 10:15:53 +02:00
newInput(1, nodeValue_Enum_Scroll("Coordinate", self, 0, [ new scrollItem("Cartesian", s_node_axis_type, 0),
new scrollItem("Polar", s_node_axis_type, 1), ]));
2023-03-11 01:40:17 +01:00
eq_type_car = [ "x function", "y function", "parametric" ];
eq_type_pol = [ "r function", "O function", "parametric" ];
2024-08-18 06:16:20 +02:00
newInput(2, nodeValue_Enum_Scroll("Equation type", self, 0, eq_type_car));
2023-03-11 01:40:17 +01:00
2024-08-18 06:16:20 +02:00
newInput(3, nodeValue_Text("0 function", self, ""));
newInput(4, nodeValue_Text("1 function", self, ""));
2023-03-11 01:40:17 +01:00
2024-08-18 06:16:20 +02:00
newInput(5, nodeValue_Vec2("Origin", self, [ DEF_SURF_W / 2, DEF_SURF_H / 2 ] ));
2023-03-11 01:40:17 +01:00
2024-08-18 06:16:20 +02:00
newInput(6, nodeValue_Slider_Range("Range", self, [ 0, 1 ], { range: [ -1, 1, 0.01 ] }));
2023-03-11 01:40:17 +01:00
2025-01-16 07:27:35 +01:00
newInput(7, nodeValue_Vec2("Input Scale", self, [ 1, 1 ]));
newInput(8, nodeValue_Vec2("Input Shift", self, [ 0, 0 ]));
newInput(9, nodeValue_Bool("Use Weight", self, false));
newInput(10, nodeValue_Text("w(x)", self, ""));
2024-09-04 03:57:11 +02:00
newOutput(0, nodeValue_Output("Path", self, VALUE_TYPE.pathnode, self));
2023-03-11 01:40:17 +01:00
input_display_list = [
2025-01-16 07:27:35 +01:00
[ "Variable", false], 5, 7, 8, 0,
[ "Equation", false], 1, 2, 3, 4, 6,
[ "Weight", false, 9], 10,
2023-03-11 01:40:17 +01:00
]
boundary = new BoundingBox( 0, 0, 1, 1 );
cached_pos = ds_map_create();
2023-03-19 09:17:39 +01:00
2025-01-16 07:27:35 +01:00
curr_sca = 0;
curr_coor = 0;
curr_eqa = 0;
curr_eq0 = 0;
curr_eq1 = 0;
curr_orig = 0;
curr_ran = 0;
curr_iran = 0;
curr_shf = 0;
curr_usew = 0;
curr_wgfn = 0;
fn0 = 0;
fn1 = 0;
_a = new __vec2P();
_param = { x:0, y:0, t:0, r:0, O:0 };
2024-03-14 14:35:19 +01:00
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
2024-08-08 06:57:51 +02:00
inputs[5].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
2023-03-11 01:40:17 +01:00
}
2025-01-16 04:39:54 +01:00
static getLineCount = function() /*=>*/ {return 1};
static getSegmentCount = function() /*=>*/ {return 1};
static getLength = function() /*=>*/ {return length};
static getAccuLength = function() /*=>*/ {return [ length ]};
static getBoundary = function() /*=>*/ {return boundary};
2023-08-02 19:11:57 +02:00
2023-10-29 06:29:10 +01:00
static getPointRatio = function(_rat, ind = 0, out = undefined) {
2025-01-15 07:55:00 +01:00
if(out == undefined) out = new __vec2P(); else { out.x = 0; out.y = 0; }
2023-10-29 06:29:10 +01:00
2025-01-16 07:27:35 +01:00
_rat = curr_ran[0] + (_rat * (curr_ran[1] - curr_ran[0]));
2023-03-11 01:40:17 +01:00
2025-01-16 07:27:35 +01:00
switch(curr_coor) {
2023-03-11 01:40:17 +01:00
case 0 :
2025-01-16 07:27:35 +01:00
switch(curr_eqa) {
2023-03-11 01:40:17 +01:00
case 0 :
2025-01-16 07:27:35 +01:00
_param.x = _rat * curr_iran[0] + curr_shf[0];
out.x = _rat * curr_iran[0] + curr_shf[0];
out.y = fn0.eval(_param);
if(curr_usew) {
_param.x = _rat;
out.weight = fnw.eval(_param);
}
2023-03-11 01:40:17 +01:00
break;
2025-01-16 07:27:35 +01:00
2023-03-11 01:40:17 +01:00
case 1 :
2025-01-16 07:27:35 +01:00
_param.y = _rat * curr_iran[1] + curr_shf[1];
out.x = fn0.eval(_param);
out.y = _rat * curr_iran[1] + curr_shf[1];
if(curr_usew) {
_param.y = _rat;
out.weight = fnw.eval(_param);
}
2023-03-11 01:40:17 +01:00
break;
2025-01-16 07:27:35 +01:00
2023-03-11 01:40:17 +01:00
case 2 :
2025-01-16 07:27:35 +01:00
_param.t = _rat * curr_iran[0] + curr_shf[0];
out.x = fn0.eval(_param);
_param.t = _rat * curr_iran[1] + curr_shf[1];
out.y = fn1.eval(_param);
if(curr_usew) {
_param.t = _rat;
out.weight = fnw.eval(_param);
}
2023-03-11 01:40:17 +01:00
break;
}
break;
2025-01-16 07:27:35 +01:00
2023-03-11 01:40:17 +01:00
case 1 :
2025-01-16 07:27:35 +01:00
var _ax = 0, _ay = 0;
switch(curr_eqa) {
2023-03-11 01:40:17 +01:00
case 0 :
2025-01-16 07:27:35 +01:00
_param.r = _rat * curr_iran[0] + curr_shf[0];
_ax = _rat * curr_iran[0] + curr_shf[0];
_ay = fn0.eval(_param);
if(curr_usew) {
_param.r = _rat;
out.weight = fnw.eval(_param);
}
2023-03-11 01:40:17 +01:00
break;
2025-01-16 07:27:35 +01:00
2023-03-11 01:40:17 +01:00
case 1 :
2025-01-16 07:27:35 +01:00
_param.O = _rat * curr_iran[1] + curr_shf[1];
_ax = fn0.eval(_param);
_ay = _rat * curr_iran[1] + curr_shf[1];
if(curr_usew) {
_param.O = _rat;
out.weight = fnw.eval(_param);
}
2023-03-11 01:40:17 +01:00
break;
2025-01-16 07:27:35 +01:00
2023-03-11 01:40:17 +01:00
case 2 :
2025-01-16 07:27:35 +01:00
_param.t = _rat * curr_iran[0] + curr_shf[0];
_ax = fn0.eval(_param);
_param.t = _rat * curr_iran[1] + curr_shf[1];
_ay = fn1.eval(_param);
if(curr_usew) {
_param.t = _rat;
out.weight = fnw.eval(_param);
}
2023-03-11 01:40:17 +01:00
break;
}
2025-01-16 07:27:35 +01:00
out.x = cos(_ay) * _ax;
out.y = -sin(_ay) * _ax;
2023-03-11 01:40:17 +01:00
break;
}
2025-01-16 07:27:35 +01:00
out.x = out.x * curr_sca[0] + curr_orig[0];
out.y = -out.y * curr_sca[1] + curr_orig[1];
2023-03-11 01:40:17 +01:00
2023-10-29 06:29:10 +01:00
return out;
2023-03-11 01:40:17 +01:00
}
2023-10-29 06:29:10 +01:00
static getPointDistance = function(_dist, ind = 0, out = undefined) { return getPointRatio(_dist / getLength(ind), ind, out); }
2023-08-02 19:11:57 +02:00
2023-09-26 14:35:25 +02:00
static step = function() {
var _coor = getInputData(1);
var _eqa = getInputData(2);
2023-03-11 01:40:17 +01:00
2024-08-08 06:57:51 +02:00
inputs[2].editWidget.data_list = _coor? eq_type_pol : eq_type_car;
2025-01-16 07:27:35 +01:00
inputs[4].setVisible(_eqa == 2);
2023-03-11 01:40:17 +01:00
switch(_coor) {
case 0 :
switch(_eqa) {
case 0 :
2025-01-16 07:27:35 +01:00
inputs[ 3].name = "f(x) = ";
inputs[ 6].name = "x range";
inputs[10].name = "w(x) = ";
2023-03-11 01:40:17 +01:00
break;
2025-01-16 07:27:35 +01:00
2023-03-11 01:40:17 +01:00
case 1 :
2025-01-16 07:27:35 +01:00
inputs[ 3].name = "f(y) = ";
inputs[ 6].name = "y range";
inputs[10].name = "w(y) = ";
2023-03-11 01:40:17 +01:00
break;
2025-01-16 07:27:35 +01:00
2023-03-11 01:40:17 +01:00
case 2 :
2025-01-16 07:27:35 +01:00
inputs[ 3].name = "x(t) = ";
inputs[ 4].name = "y(t) = ";
inputs[ 6].name = "t range";
inputs[10].name = "w(t) = ";
2023-03-11 01:40:17 +01:00
break;
}
break;
2025-01-16 07:27:35 +01:00
2023-03-11 01:40:17 +01:00
case 1 :
switch(_eqa) {
case 0 :
2025-01-16 07:27:35 +01:00
inputs[ 3].name = "f(r) = ";
inputs[ 6].name = "r range";
inputs[10].name = "w(r) = ";
2023-03-11 01:40:17 +01:00
break;
2025-01-16 07:27:35 +01:00
2023-03-11 01:40:17 +01:00
case 1 :
2025-01-16 07:27:35 +01:00
inputs[ 3].name = "f(O) = ";
inputs[ 6].name = "O range";
inputs[10].name = "w(O) = ";
2023-03-11 01:40:17 +01:00
break;
2025-01-16 07:27:35 +01:00
2023-03-11 01:40:17 +01:00
case 2 :
2025-01-16 07:27:35 +01:00
inputs[ 3].name = "r(t) = ";
inputs[ 4].name = "O(t) = ";
inputs[ 6].name = "t range";
inputs[10].name = "w(t) = ";
2023-03-11 01:40:17 +01:00
break;
}
break;
}
}
2023-09-26 14:35:25 +02:00
static updateBoundary = function() {
2023-03-28 06:58:28 +02:00
boundary = new BoundingBox( 0, 0, 1, 1 );
2023-08-02 19:11:57 +02:00
length = 0;
2023-03-28 06:58:28 +02:00
var sample = 64;
2023-08-02 19:11:57 +02:00
var op, np;
2023-03-28 06:58:28 +02:00
for( var i = 0; i <= sample; i++ ) {
2023-08-02 19:11:57 +02:00
np = getPointRatio(i / sample);
boundary.addPoint(np.x, np.y);
if(i) length += point_distance(op.x, op.y, np.x, np.y);
op = np;
2023-03-28 06:58:28 +02:00
}
}
2023-09-26 14:35:25 +02:00
static update = function() {
2025-01-16 07:27:35 +01:00
curr_sca = getInputData(0);
curr_coor = getInputData(1);
curr_eqa = getInputData(2);
curr_eq0 = getInputData(3);
curr_eq1 = getInputData(4);
curr_orig = getInputData(5);
curr_ran = getInputData(6);
curr_iran = getInputData(7);
curr_shf = getInputData(8);
curr_usew = getInputData( 9);
curr_wgfn = getInputData(10);
fn0 = evaluateFunctionList(curr_eq0);
fn1 = evaluateFunctionList(curr_eq1);
fnw = evaluateFunctionList(curr_wgfn);
2023-03-19 09:17:39 +01:00
updateBoundary();
2024-08-08 06:57:51 +02:00
outputs[0].setValue(self);
2023-03-19 09:17:39 +01:00
}
2023-03-11 01:40:17 +01:00
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
var bbox = drawGetBbox(xx, yy, _s);
draw_sprite_fit(s_node_path_trim, 0, bbox.xc, bbox.yc, bbox.w, bbox.h);
}
}