Pixel-Composer/scripts/node_line/node_line.gml

189 lines
6.1 KiB
Plaintext
Raw Normal View History

2022-12-13 09:20:36 +01:00
function Node_Line(_x, _y, _group = -1) : Node(_x, _y, _group) constructor {
2022-01-13 05:24:03 +01:00
name = "Line";
2022-11-21 06:38:44 +01:00
inputs[| 0] = nodeValue(0, "Dimension", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, def_surf_size2 )
2022-01-13 05:24:03 +01:00
.setDisplay(VALUE_DISPLAY.vector);
2022-01-19 03:05:13 +01:00
inputs[| 1] = nodeValue(1, "Backgroud", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false);
2022-01-13 05:24:03 +01:00
inputs[| 2] = nodeValue(2, "Segment", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 1)
.setDisplay(VALUE_DISPLAY.slider, [1, 32, 1]);
inputs[| 3] = nodeValue(3, "Width", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [ 2, 2 ])
.setDisplay(VALUE_DISPLAY.vector);
inputs[| 4] = nodeValue(4, "Wiggle", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0)
.setDisplay(VALUE_DISPLAY.slider, [0, 16, 0.01]);
2022-01-19 03:05:13 +01:00
inputs[| 5] = nodeValue(5, "Random seed", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0);
2022-01-13 05:24:03 +01:00
inputs[| 6] = nodeValue(6, "Rotation", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 0)
2022-01-19 03:05:13 +01:00
.setDisplay(VALUE_DISPLAY.rotation);
2022-01-13 05:24:03 +01:00
2022-11-21 06:38:44 +01:00
inputs[| 7] = nodeValue(7, "Path", self, JUNCTION_CONNECT.input, VALUE_TYPE.object, 0)
.setVisible(true, true);
2022-01-13 05:24:03 +01:00
inputs[| 8] = nodeValue(8, "Range", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, [0, 1])
.setDisplay(VALUE_DISPLAY.slider_range, [0, 1, 0.01]);
inputs[| 9] = nodeValue(9, "Shift", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 0)
.setDisplay(VALUE_DISPLAY._default, 1 / 64);
inputs[| 10] = nodeValue(10, "Color", self, JUNCTION_CONNECT.input, VALUE_TYPE.color, c_white)
.setDisplay(VALUE_DISPLAY.gradient);
2022-12-12 09:08:03 +01:00
inputs[| 11] = nodeValue(11, "Width over length", self, JUNCTION_CONNECT.input, VALUE_TYPE.curve, [1, 1, 1, 1]);
2022-01-13 05:24:03 +01:00
input_display_list = [
["Output", true], 0, 1,
["Line data", false], 6, 7, 2,
2022-12-12 09:08:03 +01:00
["Line settings", false], 3, 11, 8, 9,
2022-01-13 05:24:03 +01:00
["Wiggle", false], 4, 5,
["Render", false], 10
];
2022-09-21 06:09:40 +02:00
outputs[| 0] = nodeValue(0, "Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, PIXEL_SURFACE);
2022-01-13 05:24:03 +01:00
2022-01-18 05:31:19 +01:00
static update = function() {
2022-01-13 05:24:03 +01:00
var _dim = inputs[| 0].getValue();
var _bg = inputs[| 1].getValue();
var _seg = inputs[| 2].getValue();
var _wid = inputs[| 3].getValue();
var _wig = inputs[| 4].getValue();
var _sed = inputs[| 5].getValue();
var _ang = inputs[| 6].getValue() % 360;
var _pat = inputs[| 7].getValue();
var _ratio = inputs[| 8].getValue();
var _shift = inputs[| 9].getValue();
var _color = inputs[| 10].getValue();
var _col_data = inputs[| 10].getExtraData();
2022-12-12 09:08:03 +01:00
var _widc = inputs[| 11].getValue();
2022-01-13 05:24:03 +01:00
2022-12-12 09:08:03 +01:00
var _rtStr = min(_ratio[0], _ratio[1]);
var _rtLen = max(_ratio[0], _ratio[1]) - _rtStr;
2022-01-13 05:24:03 +01:00
var _use_path = _pat != 0 && instanceof(_pat) == "Node_Path";
if(_ang < 0) _ang = 360 + _ang;
if(_use_path) {
2022-01-19 06:11:17 +01:00
inputs[| 6].setVisible(false);
2022-01-13 05:24:03 +01:00
} else {
2022-01-19 06:11:17 +01:00
inputs[| 6].setVisible(true);
2022-01-13 05:24:03 +01:00
}
random_set_seed(_sed);
var _outSurf = outputs[| 0].getValue();
if(!is_surface(_outSurf)) {
2022-11-01 03:06:03 +01:00
_outSurf = surface_create_valid(_dim[0], _dim[1]);
2022-01-13 05:24:03 +01:00
outputs[| 0].setValue(_outSurf);
} else
2022-11-01 03:06:03 +01:00
surface_size_to(_outSurf, _dim[0], _dim[1]);
2022-01-13 05:24:03 +01:00
surface_set_target(_outSurf);
if(_bg) draw_clear_alpha(0, 1);
else draw_clear_alpha(0, 0);
var _ox, _nx, _oy, _ny, _ow, _nw, _oa, _na;
if(_use_path) {
2022-12-12 09:08:03 +01:00
var ww = _rtLen / _seg;
2022-01-13 05:24:03 +01:00
2022-12-12 09:08:03 +01:00
var _total = _rtLen;
var _prog_curr = frac(_shift + _rtStr) - ww;
2022-09-21 06:09:40 +02:00
var _prog = _prog_curr + 1;
2022-01-13 05:24:03 +01:00
var _prog_eli = 0;
while(_total > 0) {
if(_prog_curr >= 1) _prog_curr = 0;
else _prog_curr = min(_prog_curr + min(_total, ww), 1);
_prog_eli += min(_total, ww);
var p = _pat.getPointRatio(_prog_curr);
_nx = p[0];
_ny = p[1];
2022-12-12 09:08:03 +01:00
if(_total < _rtLen) {
2022-09-21 06:09:40 +02:00
var _d = point_direction(_ox, _oy, _nx, _ny);
2022-01-13 05:24:03 +01:00
_nx += lengthdir_x(random(_wig) * choose(-1, 1), _d + 90);
_ny += lengthdir_y(random(_wig) * choose(-1, 1), _d + 90);
}
_nw = random_range(_wid[0], _wid[1]);
2022-12-12 09:08:03 +01:00
_nw *= eval_bezier_cubic(1 - _prog_curr, _widc[0], _widc[1], _widc[2], _widc[3]);
2022-01-13 05:24:03 +01:00
if(_total <= _prog_curr - _prog) {
_na = point_direction(_ox, _oy, _nx, _ny) + 90;
} else {
var np = _pat.getPointRatio(_prog_curr + ww);
var _nna = point_direction(_nx, _ny, np[0], np[1]) + 90;
2022-12-12 09:08:03 +01:00
if(_total == _rtLen)
2022-01-13 05:24:03 +01:00
_na = _nna;
else {
var _da = point_direction(_ox, _oy, _nx, _ny) + 90;
_na = _da + angle_difference(_nna, _da) / 2;
}
}
if(_prog_curr > _prog) {
2022-12-12 09:08:03 +01:00
draw_set_color(gradient_eval(_color, _prog_eli / _rtLen, ds_list_get(_col_data, 0)));
2022-01-13 05:24:03 +01:00
draw_line_width2_angle(_ox, _oy, _nx, _ny, _ow, _nw, _oa, _na);
_total -= (_prog_curr - _prog);
}
_prog = _prog_curr;
_oa = _na;
_ox = _nx;
_oy = _ny;
_ow = _nw;
}
} else {
var x0, y0, x1, y1;
var _0 = point_rectangle_overlap(_dim[0], _dim[1], (_ang + 180) % 360);
var _1 = point_rectangle_overlap(_dim[0], _dim[1], _ang);
x0 = _0[0];
y0 = _0[1];
x1 = _1[0];
y1 = _1[1];
var _l = point_distance(x0, y0, x1, y1);
var _d = point_direction(x0, y0, x1, y1);
2022-12-12 09:08:03 +01:00
var ww = _rtLen / _seg;
var _total = _rtLen;
var _prog_curr = frac(_shift + _rtStr) - ww;
2022-09-21 06:09:40 +02:00
var _prog = _prog_curr + 1;
2022-01-13 05:24:03 +01:00
var _prog_eli = 0;
while(_total > 0) {
if(_prog_curr >= 1) _prog_curr = 0;
else _prog_curr = min(_prog_curr + min(_total, ww), 1);
_prog_eli += min(_total, ww);
_nx = x0 + lengthdir_x(_l * _prog_curr, _d);
_ny = y0 + lengthdir_y(_l * _prog_curr, _d);
_nx += lengthdir_x(random(_wig) * choose(-1, 1), _d + 90);
_ny += lengthdir_y(random(_wig) * choose(-1, 1), _d + 90);
_nw = random_range(_wid[0], _wid[1]);
2022-12-12 09:08:03 +01:00
_nw *= eval_bezier_cubic(1 - _prog_curr, _widc[0], _widc[1], _widc[2], _widc[3]);
2022-01-13 05:24:03 +01:00
if(_prog_curr > _prog) {
2022-12-12 09:08:03 +01:00
draw_set_color(gradient_eval(_color, _prog_eli / _rtLen, ds_list_get(_col_data, 0)));
2022-01-13 05:24:03 +01:00
draw_line_width2_angle(_ox, _oy, _nx, _ny, _ow, _nw, _d + 90, _d + 90);
_total -= (_prog_curr - _prog);
}
_prog = _prog_curr;
_ox = _nx;
_oy = _ny;
_ow = _nw;
}
}
surface_reset_target();
}
doUpdate();
2022-01-13 05:24:03 +01:00
}