Skip to content

Instantly share code, notes, and snippets.

@izb
izb / wordwrap
Created August 12, 2013 10:40
Canvas word wrap
function wordwrap(text, twidth, con) {
con = con || context
twidth = twidth || con.canvas.width
var texts = [text], n = 0, s
while (con.measureText(texts[n]).width > twidth && (s = texts[n].indexOf(" ")) > -1) {
var t = texts[n], a = t.lastIndexOf(" ")
while (con.measureText(t.substr(0, a)).width > twidth && a > s) a = t.lastIndexOf(" ", a-1)
texts[n++] = t.substr(0, a)
texts.push(t.substr(a+1))
}
@izb
izb / debounced
Created September 5, 2013 14:08
Debounced function call
// WIP - needs a context object to store debounce info in.
Function.prototype.debounced = function() {return this}
var a = function(r) {console.log("Hello "+r)}
a.debounced()("World")
@izb
izb / chasing-value.html
Last active April 18, 2016 19:48
Ease in and out on a continuously changing value
<!doctype html>
<head>
<style>
</style>
</head>
<body>
<div>
<canvas id="canvas" width="500" height="500">
</canvas>
{
"editor.fontFamily": "'Hasklig', 'Source code pro'",
"editor.fontSize": 15.4,
//"editor.fontSize": 12,
"editor.rulers": [
80,
120
],
"editor.minimap.enabled": false,
"editor.folding": false,