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 / lerp_angle.gml
Last active May 15, 2023 14:41
linearly interpolate between two angles, taking the shortest distance.
/**
* interpolate between angles
* @param {real} a start
* @param {real} b end
* @param {real} i increment
* @returns {real}
*/
function lerp_angle(a, b, i) {
var n = a + angle_difference(b, a);
return lerp(a, n, i);
@attic-stuff
attic-stuff / room_to_gui.gml
Last active May 15, 2023 14:40
convert room coordinates to gui coordinates
/**
* converts a room position to a gui position
* @param {real} x the x coordinate to convert to gui
* @param {real} [view] the view number. defaults to 0
*/
function room_x_to_gui(x, view = 0) {
return (x - camera_get_view_x(view_camera[view])) * (display_get_gui_width() / camera_get_view_width(view_camera[view]));
}
/**
* converts a room position to a gui position
@attic-stuff
attic-stuff / draw_a_big_arrow.gml
Last active May 15, 2023 14:40
draw a bigger arrow
/**
* draws an arrow with a variable width stem and pointy bobby bo diddly thingy
* @param {real} x1 x where the line for the arrow begins
* @param {real} y1 y where the line for the arrow begins
* @param {real} x2 x where the tip of the arrow ends
* @param {real} y2 y where the tip of the arrow ends
* @param {real} [size] the size of the thing; line is this width and triangle sides are size * 2.5
* @param {Constant.Color} [color] the color of the whole thing
*/
function draw_a_big_arrow(x1, y1, x2, y2, size = 1, color = c_white) {
@attic-stuff
attic-stuff / remap.gml
Last active June 23, 2025 01:46
remap a value from between two points to between two other points
/**
* remaps a value between 2 points to be a value between 2 other points.
* for example if you have a number between 0 and 10 and you want to remap it to be between 69 and 420
* you would do remap(number, 0, 10, 69, 420).
* @param {real} value the value to remap
* @param {real} old_min the lowest value in the starting range
* @param {real} old_max the highest value in the starting range
* @param {real} new_min the lowest value of the new range
* @param {real} new_max the highest value of the new range
* @returns {real}
@attic-stuff
attic-stuff / pp_outline.glsl
Last active April 1, 2025 02:19
post processing outline shader
/*
a simple outline shader that applies the outline to faces _and_ corners. this is a pp shader so
put everything u want outlined on a surface then apply the shader to the drawn surface
*/
//* vertex shader *//
attribute vec3 in_Position;
attribute vec2 in_TextureCoord;
@attic-stuff
attic-stuff / poissondisc.gml
Last active April 12, 2025 21:06
generate an array of points using a blue noise distribution.
/**
* generates an array of blue noise points using poisson discs
* @param {real} width the width of the region of points
* @param {real} height the height of the region of points
* @param {real} radius the poisson disc radius, or space between each point
* @param {real} rejections the number of attempts made to generate a point before moving on
*/
function bluenoise(width, height, radius = 4, rejections = 30) constructor {
static sample = function(x, y) constructor {
@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;
}
@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 / 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 / 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}
*/