Pixel-Composer/scripts/node_lovify/node_lovify.gml

71 lines
1.9 KiB
Text
Raw Normal View History

2024-02-12 10:25:23 +01:00
function Node_Lovify(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
name = "Lovify";
color = CDEF.red;
2024-08-18 06:16:20 +02:00
newInput(0, nodeValue_Surface("Surface in", self));
2024-02-12 10:25:23 +01:00
2024-11-07 07:59:04 +01:00
newInput(1, nodeValueSeed(self));
2024-02-12 10:25:23 +01:00
2024-08-18 09:13:41 +02:00
newInput(2, nodeValue_Float("Density", self, 0.5 ))
2024-02-12 10:25:23 +01:00
.setDisplay(VALUE_DISPLAY.slider);
2024-08-18 09:13:41 +02:00
newInput(3, nodeValue_Float("Distribution", self, 0.1 ))
2024-02-12 10:25:23 +01:00
.setDisplay(VALUE_DISPLAY.slider);
2024-09-04 03:57:11 +02:00
newOutput(0, nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone));
2024-02-12 10:25:23 +01:00
input_display_list = [ 1,
["Surfaces", false], 0,
["Love", false], 2, 3,
];
attribute_surface_depth();
static processData = function(_outSurf, _data, _output_index, _array_index) {
var _surf = _data[0];
var _seed = _data[1];
var _dens = _data[2];
var _dist = _data[3];
var _dim = surface_get_dimension(_surf);
_outSurf = surface_verify(_outSurf, _dim[0], _dim[1], attrDepth());
random_set_seed(_seed);
var amo = (_dim[0] * _dim[1]) / 8 * _dens;
var sprs = [ s_lovify_heart_6 ];
var sde = max(_dim[0], _dim[1]);
var hmax = 12;
if(sde > 16) { sprs[1] = s_lovify_heart_8; hmax = 16; }
if(sde > 20) { sprs[2] = s_lovify_heart_10; hmax = 20; }
if(sde > 24) { sprs[3] = s_lovify_heart_12; hmax = 24; }
if(sde > 32) { sprs[4] = s_lovify_heart_16; hmax = 32; }
var maxS = min(4, ceil(sde / hmax / 4));
surface_set_target(_outSurf);
DRAW_CLEAR
shader_set(sh_lovify);
draw_surface_safe(_surf);
2024-02-12 10:25:23 +01:00
shader_reset();
repeat(amo) {
var _r = power(random_seed(1, _seed++), _dist) * 0.75;
var _a = random_seed(360, _seed++);
var _x = lengthdir_x(_r, _a) + 0.5;
var _y = lengthdir_y(_r, _a) + 0.5;
_x *= _dim[0];
_y *= _dim[1];
var ss = irandom_range_seed(1, maxS, _seed++);
draw_sprite_ext(sprs[irandom(array_length(sprs) - 1)], 0, _x, _y, ss, ss, 0, c_white, 1);
}
surface_reset_target();
return _outSurf;
}
}