Skip to content

Instantly share code, notes, and snippets.

View JordanDelcros's full-sized avatar
Having fun with maps & swiftui

Jordan JordanDelcros

Having fun with maps & swiftui
View GitHub Profile
@JordanDelcros
JordanDelcros / file.js
Created June 4, 2021 13:49
Fixed number without .toFixed()
// Default 2 numbers after comma
function fixNumber( number, precision = 1e2 ){
return Math.sign(number) * (Math.round((Math.abs(number) + Number.EPSILON) * precision) / precision);
}
@JordanDelcros
JordanDelcros / GLSL-Noise.md
Created March 3, 2017 14:07 — forked from patriciogonzalezvivo/GLSL-Noise.md
GLSL Noise Algorithms

Generic 1,2,3 Noise

float rand(float n){return fract(sin(n) * 43758.5453123);}

float noise(float p){
	float fl = floor(p);
  float fc = fract(p);
	return mix(rand(fl), rand(fl + 1.0), fc);
}
@JordanDelcros
JordanDelcros / gist:c52db5343acf1e15cd72abdab1289c70
Created June 8, 2016 14:00
Open Chrome without WebGL (Mac OS)
open -a Google\ Chrome --args --disable-webgl
@JordanDelcros
JordanDelcros / parseHTML.js
Created November 6, 2015 19:36
Parse HTML file and highlight it
var parser = function( html ){
html = html
.replace(/&(lt|nbsp|amp)/gim, "&$1")
.replace(/•/gi, "·")
.replace(/#/gi, "&#35")
.replace(/</gim, "&lt;")
.replace(/>/gim, "&gt;")
.replace(/(&lt;(?!\!)\/?(?:\w+)((?:\s*?[\w-]+(?:\s*=\s*)?(?:\"[^\"]*(?:\")?|\'[^\']*(?:\')?)?)*)?(?:\s*\/?\s*&gt;|[\s\S]*$)?)/gi, function( matchTag ){
@JordanDelcros
JordanDelcros / parseJavaScript.js
Last active August 29, 2015 14:27
Highlight JavaScript
// Basic JavaScript RegExps to parse JavaScript (itself ahah!)
// and translate it into HTML markup ready for CSS.
// Please, give me your feedback on twitter @JordanDelcros.
code // string (multiline) of JavaScript code
.replace(/&(lt|nbsp|amp)/gim, "&amp;$1")
.replace(/(\/\/[^\n]*)/gi, "##comment••$1••comment##")
.replace(/(\/\*[\s\S]*?((\*\/)|$))/gi, "##comment••$1••comment##")
.replace(/(\"[\s\S]*?(\"|$))/gi, "##string••$1••string##")
.replace(/([\<\>\+\-\*\/\%\!]|\=+)/gim, "##math••$1••math##")
@JordanDelcros
JordanDelcros / combine-rgba-colors.js
Created July 31, 2015 09:55
Combine two RGBA colors with JavaScript
// Fast and easy way to combine (additive mode) two RGBA colors with JavaScript.
// [red, green, blue, alpha] based on these maximul values [255, 255, 255, 1].
var base = [69, 109, 160, 1];
var added = [61, 47, 82, 0.8];
var mix = [];
mix[3] = 1 - (1 - added[3]) * (1 - base[3]); // alpha
mix[0] = Math.round((added[0] * added[3] / mix[3]) + (base[0] * base[3] * (1 - added[3]) / mix[3])); // red
mix[1] = Math.round((added[1] * added[3] / mix[3]) + (base[1] * base[3] * (1 - added[3]) / mix[3])); // green
mix[2] = Math.round((added[2] * added[3] / mix[3]) + (base[2] * base[3] * (1 - added[3]) / mix[3])); // blue
@JordanDelcros
JordanDelcros / distance-between-vectors.js
Created July 30, 2015 13:33
Find distance between two vectors
// Easy way to find distance between two vectors in JavaScript
// [x, y, z]
var vectorFrom = [10, 10, 1];
var vectorTo = [12, 11, 0];
var distance = Math.sqrt(((vectorFrom[0] - vectorTo[0]) * (vectorFrom[0] - vectorTo[0])) + ((vectorFrom[1] - vectorTo[1]) * (vectorFrom[1] - vectorTo[1])) + ((vectorFrom[2] - vectorTo[2]) * (vectorFrom[2] - vectorTo[2])));
@JordanDelcros
JordanDelcros / triangle-center.js
Created July 30, 2015 08:48
Find centroid of a triangle with JavaScript
// Very simple way to compute the center (centroid) of a triangle.
// The only things you have to know are the three vectors forming the triangle.
// vector = [x, y, z];
var vectorA = [-1, -3, -2];
var vectorB = [2, 1, 2];
var vectorC = [8, -4, 1];
var centerX = ((vectorA[0] + vectorB[0] + vectorC[0]) / 3);
var centerY = ((vectorA[1] + vectorB[1] + vectorC[1]) / 3);
@JordanDelcros
JordanDelcros / elegant-class.js
Last active August 29, 2015 14:22
Elegant JavaScript Class creation
/*
Must easy and elegant way to create classes or complex objects in JavaScript
*/
(function( window, document ){
function Class( options ){
if( this instanceof Class ){
return Class.fn.init(options);