Skip to content

Instantly share code, notes, and snippets.

williammalo / CircleCircleTangents.glsl
Last active December 5, 2016 17:46
Find Tangents of Two Circles in glsl, useful for calculating soft shadows
//visual basics code from ported to glsl
vec4 FindCircleCircleIntersections(vec2 p0, float r0, vec2 p1, float r1){
vec2 dd = p1-p0;
float d = length(dd);
float a = (r0 * r0 - r1 * r1 + d * d) / (2.0 * d);
float h = sqrt(r0 * r0 - a * a);
williammalo /
Last active December 18, 2015 08:20 — forked from 140bytes/LICENSE.txt

##Object Merger

Recurcively merges two objects.



williammalo /
Last active September 24, 2022 23:45 — forked from 140bytes/LICENSE.txt
image to 2d array

converts canvas image data to a 2d array of booleans


array[x][y] //gives true or false

very useful for games where you need pixel perfect collision.

Reading an image every time you check for collision is slow. Using a 2d array makes it much faster, and has a very simple syntax (array[x][y]) .

williammalo /
Last active October 7, 2015 01:48 — forked from 140bytes/LICENSE.txt
masonry under 140bytes

A minimalist masonry function


Only works with one size of brick.

The only advantage of using this over using inline-block elements is that you can use css transitions.

williammalo /
Last active March 1, 2019 17:39 — forked from 140bytes/LICENSE.txt
Responsive image loading in 199bytes (minification help needed)

This function loops through all images on the page, and serves the appropriately sized image file from a list in a data attribute.

example link:

example html:

<img src="default.png" data-widths="400,600,800,1023" data-srcsuffix="-foo.png">

example javascript:

williammalo /
Last active October 6, 2015 14:18 — forked from 140bytes/LICENSE.txt
get offset of element

recursively checks every parent of the element to get the ABSOLUTE offset of the element.

call it like this:



williammalo / calendar.js
Created June 25, 2012 23:10
Javascript Calendar Maker
calendar = function(year,month,template,rowStart,rowEnd,cellStart,cellEnd){
var tmpl=function(a,b){return a.replace(/\{\{([^{}]+)}}/g,function(c,d){return typeof b[d]=="function"?b[d]():b[d]})}
return tmpl(template,{
williammalo /
Last active October 6, 2015 09:58 — forked from 140bytes/LICENSE.txt
set element properties on nodelists

a neat function that allows this:


and it will change the innerHTML of all tags AUTOMATICALLY!!!!



williammalo /
Created June 19, 2012 19:22
Javascript Rss Reader

#Javascript Rss Reader#

Takes a rss feed and prints html (defined by a template) for every post.

williammalo /
Last active October 5, 2015 19:07 — forked from 140bytes/LICENSE.txt

Turns indentation into {curly brackets} Great for a yml to json converter or something. Credit to @maettig for writing all* the code.

Turn this: