Pixel-Composer/scripts/node_VFX_turbulence/node_VFX_turbulence.gml

46 lines
1.5 KiB
Text
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_VFX_Turbulence(_x, _y, _group = noone) : Node_VFX_effector(_x, _y, _group) constructor {
2022-12-13 09:20:36 +01:00
name = "Turbulence";
2022-12-16 09:18:09 +01:00
node_draw_icon = s_node_vfx_turb;
2022-12-13 09:20:36 +01:00
2024-08-08 06:57:51 +02:00
inputs[4].setVisible(false, false);
2023-01-17 08:11:55 +01:00
2024-08-18 06:16:20 +02:00
newInput(effector_input_length + 0, nodeValue_Float("Turbulence scale", self, 1 ));
2023-10-10 07:12:42 +02:00
2024-08-18 06:16:20 +02:00
newInput(effector_input_length + 1, nodeValue_Bool("Constant seed", self, false ));
2023-01-17 08:11:55 +01:00
2023-10-10 07:12:42 +02:00
array_push(input_display_list, effector_input_length + 0, effector_input_length + 1);
2023-01-17 08:11:55 +01:00
2024-12-25 04:52:25 +01:00
tscale = 1;
conspd = false;
static onVFXUpdate = function(frame = CURRENT_FRAME) {
tscale = getInputData(effector_input_length + 0);
conspd = getInputData(effector_input_length + 1);
}
2022-12-13 09:20:36 +01:00
function onAffect(part, str) {
2024-12-25 04:52:25 +01:00
var _rot = random_range(rotateX, rotateY);
var _scX = random_range(scaleX0, scaleX1);
var _scY = random_range(scaleY0, scaleY1);
2023-10-10 07:12:42 +02:00
2024-12-25 04:52:25 +01:00
var pv = part.getPivot();
var _seed = conspd? seed : part.seed;
2023-10-10 07:12:42 +02:00
2024-12-25 04:52:25 +01:00
var perx = (perlin_noise(pv[0] / tscale, pv[1] / tscale, 1, _seed) - 0.5) * 2;
var pery = (perlin_noise(pv[0] / tscale, pv[1] / tscale, 1, _seed + 100) - 0.5) * 2;
2023-01-17 08:11:55 +01:00
2024-12-25 04:52:25 +01:00
part.x += perx * str * strength;
part.y += pery * str * strength;
2023-01-17 08:11:55 +01:00
part.rot += _rot * perx;
2022-12-13 09:20:36 +01:00
2024-12-25 04:52:25 +01:00
var scx_s = _scX * str;
var scy_s = _scY * str;
2023-01-17 08:11:55 +01:00
if(scx_s < 0) part.scx = lerp_linear(part.scx, 0, abs(scx_s));
else if(scx_s > 0) part.scx += sign(part.scx) * scx_s;
if(scy_s < 0) part.scy = lerp_linear(part.scy, 0, abs(scy_s));
else if(scy_s > 0) part.scy += sign(part.scy) * scy_s;
2022-12-13 09:20:36 +01:00
}
}