Skip to content

Instantly share code, notes, and snippets.

View attic-stuff's full-sized avatar
🎃
not eating canned air

attic-stuff attic-stuff

🎃
not eating canned air
View GitHub Profile
@attic-stuff
attic-stuff / round_pot.gml
Created December 29, 2023 15:29
round a value to the nearest power of two
/**
* rounds a value to its nearest power of two neighbor
* @param {real} n the value to round
* @return {real}
*/
function round_pot(n) {
return power(2, ceil(log2(n)));
}
@attic-stuff
attic-stuff / array_shuffle_hella.gml
Created December 9, 2023 14:44
shuffle a multi dimensional array
function array_shuffle_hella(array) {
var l = array_length(array);
array_shuffle_ext(array);
for (var i = 0; i < l; i++) {
if (is_array(array[i]) == true) {
array_shuffle_hella(array[i]);
}
}
}
@attic-stuff
attic-stuff / string_destruct.gml
Last active December 7, 2023 21:22
destructs a whole string character by character
function string_pewpewBOOMahhhhh(thing) {
var count = string_length(thing);
var bucket = array_create(count, "");
for (var i = 1; i <= count; i++){
bucket[i - 1] = string_char_at(thing, i);
}
return bucket;
}
@attic-stuff
attic-stuff / line_intersect_point.gml
Last active December 16, 2024 18:50
get the intersecting point of two (2) line segments
/**
* finds the point at which 2 line segments intersect using paul bourke's method
* @param {real} x1 point 1 x
* @param {real} y1 point 1 y
* @param {real} x2 point 2 x
* @param {real} y2 point 2 y
* @param {real} x3 point 3 x
* @param {real} y3 point 3 y
* @param {real} x4 point 4 x
* @param {real} y4 point 4 y
@attic-stuff
attic-stuff / animcurve_channel_exists.gml
Created July 3, 2023 13:56
check if a channel on an animcurve exists
/**
* test whether or not a channel exists within an animation curve
* @param {asset.GMAnimCurve} curve the animation curve to check
* @param {any} channel the channel index or name to evaluate
* @return {bool}
*/
function animcurve_channel_exists(curve, channel) {
var data = animcurve_get(curve);
if (is_real(channel) == true) {
return channel < array_length(data.channels);
function perlin(x, y, z) {
static permutations = [
151, 160, 137, 91, 90, 15, 131, 13, 201, 95,
96, 53, 194, 233, 7, 225, 140, 36, 103, 30,
69, 142, 8, 99, 37, 240, 21, 10, 23, 190,
6, 148, 247, 120, 234, 75, 0, 26, 197, 62,
94, 252, 219, 203, 117, 35, 11, 32, 57, 177,
33, 88, 237, 149, 56, 87, 174, 20, 125, 136,
171, 168, 68, 175, 74, 165, 71, 134, 139, 48,
27, 166, 77, 146, 158, 231, 83, 111, 229, 122,
@attic-stuff
attic-stuff / distance_to_line_segment.gml
Created May 29, 2023 18:26
functions for calculating the distance between a point (P) and the closest point on a line segment (AB) to that point (P);
/**
* calculates the closest point on a line to a point not on that line and returns the distance between them
* @param {real} px the point x
* @param {real} py the point y
* @param {real} x1 segment point 1 x
* @param {real} y1 segment point 1 y
* @param {real} x2 segment point 2 x
* @param {real} y2 segment point 2 y
* @returns {real}
*/
@attic-stuff
attic-stuff / hexcolor_convert.gml
Last active April 14, 2025 22:51
converts a string hex color code like #FFFFFF to a regular number for use in gamemaker
/**
* converts a string hex color code into a usable decimal color number (#ffffff becomes c_white, etc).
* if there is a chance this will receive an invalid string, uncomment the validation
* @param {String} hexcode the hex color to convert in #nnnnnn form
* @returns {Real}
*/
function hexcolor_convert(hexcode) {
static hexadecimal_letter = {
a: 10, b: 11, c: 12, d: 13, e: 14, f: 15,
A: 10, B: 11, C: 12, D: 13, E: 14, F: 15
@attic-stuff
attic-stuff / colorbits.gml
Last active May 15, 2023 14:38
color packing and unpacking functions for gml
/**
* packs four color values, r g b and a, into a single unsigned 32 bit value
* @param {real} r red value, 0 to 255
* @param {real} g green value, 0 to 255
* @param {real} b blue value, 0 to 255
* @param {real} a alpha value, 0 to 255
* @returns {real}
*/
function pack_colors(r, g, b, a) {
return r + (g << 8) + (b << 16) + (a << 24);
@attic-stuff
attic-stuff / steps.gml
Created May 9, 2023 17:13
step functions for gamemaker
/**
* step function, returns 1 if value is higher than threshold, returns 0 otherwise
* @param {real} t the threshold to compare our value to
* @param {real} v the value being compared to threshold
* @returns {real} 1 or 0
*/
function step(t, v) {
if (v > t) {
return 1;
}