Skip to content

Instantly share code, notes, and snippets.

View williammustaffa's full-sized avatar
🎯

William Lima williammustaffa

🎯
View GitHub Profile
@williammustaffa
williammustaffa / CANVAS RETROFFECT
Last active August 29, 2015 14:15
Effects: RGB shift, Scan Lines, TV Shine, TV noise
/*
* SCRIPT BY WILLIAM LIMA
* NAME: CANVAS RETROFFECT
* DATE: 08/02/2015
* LANGUAGE: JAVASCRIPT
* USAGE: draw_rgb_shift(CanvasElement,EnableRgbShift,EnableScanLine,EnableShine,EnableTvNoise)
* USE THE FUNCTION INTO ### AN ANIMATION FRAME ### BUT CREATE IT OUTSIDE
*/
var room={height: canvas.height,width: canvas.width,currentTime:0}
function draw_rgb_shift(canvas,rgbshift,scanline,shine,noise){
/**
* Usage:
* Go to https://objectedge.slack.com/files/{username}
* and run this code in the browser console
*/
(function() {
var time = new Date().getTime();
var url = {
list: "/api/files.list?t=" + time,
del: "/api/files.delete?t=" + time
/**
* "string".cuckalize(value)
* transform any word into a custom object
*
* @param {Any} v Variable value
*
* @return {Object}
*/
String.prototype.cuckalize = function (v) { return this.split('').reverse().reduce((p, c) => ({ [c]: p }), v) };
@williammustaffa
williammustaffa / customToFixed.js
Last active July 17, 2018 19:00
custom toFixed to prevent rounding values
Number.prototype.customToFixed = function (digits) {
return parseFloat(String(this).replace(new RegExp(`(\\d+\\.\\d{${digits}}).*`), '$1'));
};
import pubsub from 'pubsub';
import spinner from 'spinner';
import ccLogger from 'ccLogger';
export default {
onLoad() {
const occDebugger = this._occDebugger;
occDebugger.debug('spinner');
occDebugger.debug('topics');
const getLastDigits = (cardNumber = '') => {
const match = cardNumber.match(/(?<lastDigits>\d{4})$/);
return match && match.groups.lastDigits || false;
}
PinchZoom.prototype.getContainerCenter = function () {
var centerX = this.container.offsetLeft + this.container.offsetWidth / 2;
var centerY = this.container.offsetTop + this.container.offsetHeight / 2;
return {
x: centerX,
y: centerY,
};
};
@williammustaffa
williammustaffa / createPaginations.js
Created October 22, 2020 17:39
Simple pagination algorithm using lodash
import first from 'lodash/first'
import last from 'lodash/last'
import inRange from 'lodash/inRange'
export function createPagination(items, current, delta) {
const currentIndex = items.indexOf(current)
const left = currentIndex - delta
const right = currentIndex + delta + 1
const applyDots = (data, item, lastItem) => {
@williammustaffa
williammustaffa / load_xml.gml
Last active March 22, 2022 12:54
Load XML file into game maker ds_map
/**
* Reads a XML file and converts its content into a ds_map
*
* Example output:
*
* <ds_map>{
* type: "root",
* content: "",
* nodes: <ds_list>[
* <ds_map>{
@williammustaffa
williammustaffa / sh_element_clip.fsh
Last active May 8, 2022 13:21
Simple CSS-Like Game Maker Studio 2 UI
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
varying vec3 v_vPosition;
uniform vec4 u_bounds;
void main() {
vec4 color = v_vColour * texture2D(gm_BaseTexture, v_vTexcoord);
// calculate alpha
color.a *= float(