Skip to content

Instantly share code, notes, and snippets.

@williammalo
williammalo / README.md
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: http://total.maloweb.com/responsive

example html:

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

example javascript:

@williammalo
williammalo / README.md
Last active March 9, 2020 15:58 — forked from 140bytes/LICENSE.txt
Make font size work with percentage
@williammalo
williammalo / README.md
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=img2array(imagedata,width,height)

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]) .