2023-01-17 08:11:55 +01:00
|
|
|
function irandom_seed(val, seed) {
|
|
|
|
random_set_seed(floor(seed));
|
|
|
|
return irandom(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
function irandom_range_seed(from, to, seed) {
|
|
|
|
random_set_seed(floor(seed));
|
|
|
|
return irandom_range(from, to);
|
|
|
|
}
|
|
|
|
|
|
|
|
function random_seed(val, seed) {
|
|
|
|
random_set_seed(floor(seed));
|
|
|
|
var _s0 = random(val);
|
|
|
|
|
|
|
|
random_set_seed(floor(seed) + 1);
|
|
|
|
var _s1 = random(val);
|
|
|
|
|
|
|
|
return lerp(_s0, _s1, frac(seed));
|
|
|
|
}
|
|
|
|
|
|
|
|
function random_range_seed(from, to, seed) {
|
|
|
|
random_set_seed(floor(seed));
|
|
|
|
var _s0 = random_range(from, to);
|
|
|
|
|
|
|
|
random_set_seed(floor(seed) + 1);
|
|
|
|
var _s1 = random_range(from, to);
|
|
|
|
|
|
|
|
return lerp(_s0, _s1, frac(seed));
|
|
|
|
}
|
|
|
|
|
2022-12-12 09:08:03 +01:00
|
|
|
function random1D(seed, startRange = 0, endRange = 1) {
|
2023-03-19 09:17:39 +01:00
|
|
|
if(startRange == endRange) return startRange;
|
|
|
|
|
2023-01-09 03:14:20 +01:00
|
|
|
var _f = frac(seed);
|
|
|
|
if(_f == 0) {
|
|
|
|
random_set_seed(GLOBAL_SEED + seed);
|
|
|
|
return random_range(startRange, endRange);
|
|
|
|
}
|
|
|
|
|
|
|
|
random_set_seed(GLOBAL_SEED + floor(seed));
|
|
|
|
var f1 = random_range(startRange, endRange);
|
|
|
|
|
|
|
|
random_set_seed(GLOBAL_SEED + floor(seed) + 1);
|
|
|
|
var f2 = random_range(startRange, endRange);
|
|
|
|
|
|
|
|
return lerp(f1, f2, _f);
|
2022-12-12 09:08:03 +01:00
|
|
|
}
|
|
|
|
|
2023-03-19 09:17:39 +01:00
|
|
|
function perlin1D(seed, scale = 1, octave = 1, startRange = 0, endRange = 1) {
|
|
|
|
var amp = power(2., octave - 1.) / (power(2., octave) - 1.);
|
|
|
|
var val = 0;
|
|
|
|
|
|
|
|
repeat(octave) {
|
|
|
|
val = sin(seed * scale) * amp;
|
|
|
|
scale *= 2;
|
|
|
|
amp /= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return lerp(startRange, endRange, val);
|
|
|
|
}
|
|
|
|
|
2022-12-12 09:08:03 +01:00
|
|
|
function getWiggle(_min, _max, _freq, _time, seed_shift = 0, startTime = noone, endTime = noone) {
|
|
|
|
_freq = max(1, _freq);
|
2023-01-09 03:14:20 +01:00
|
|
|
|
2022-12-12 09:08:03 +01:00
|
|
|
var sdMin = floor(_time / _freq) * _freq;
|
|
|
|
var sdMax = sdMin + _freq;
|
2023-01-09 03:14:20 +01:00
|
|
|
if(endTime) //Clip at ending
|
2022-12-12 09:08:03 +01:00
|
|
|
sdMax = min(endTime, sdMax);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-01-09 03:14:20 +01:00
|
|
|
var _x0 = (startTime != noone && sdMin <= startTime)? 0.5 : random1D(GLOBAL_SEED + seed_shift + sdMin);
|
|
|
|
var _x1 = (endTime != noone && sdMax >= endTime)? 0.5 : random1D(GLOBAL_SEED + seed_shift + sdMax);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-12-12 09:08:03 +01:00
|
|
|
var t = (_time - sdMin) / (sdMax - sdMin);
|
2022-09-21 06:09:40 +02:00
|
|
|
t = -(cos(pi * t) - 1) / 2;
|
2023-01-09 03:14:20 +01:00
|
|
|
var _lrp = lerp(_x0, _x1, t);
|
|
|
|
return lerp(_min, _max, _lrp);
|
2022-01-19 03:05:13 +01:00
|
|
|
}
|
|
|
|
|
2023-06-21 20:36:53 +02:00
|
|
|
function UUID_generate(length = 16) {
|
|
|
|
static str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
|
|
|
2023-05-03 21:42:17 +02:00
|
|
|
var _id = "";
|
2023-06-21 20:36:53 +02:00
|
|
|
repeat(length) _id += string_char_at(str, irandom_range(1, string_length(str)));
|
2023-05-03 21:42:17 +02:00
|
|
|
return _id;
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|