Skip to content

Instantly share code, notes, and snippets.

View iaincarsberg's full-sized avatar

Iain Carsberg iaincarsberg

View GitHub Profile
@iaincarsberg
iaincarsberg / rafExample.js
Created November 14, 2012 09:20
MT Tech-Talk: A Discussion About Canvas 2
var lastTime;
function render (time) {
if (! lastTime) {
lastTime = time;
}
var delta = time - lastTime;
actor.update(delta);
ctx.drawImage(
@iaincarsberg
iaincarsberg / drawImageSpec.js
Created November 13, 2012 10:29
MT Tech-Talk: A Discussion About Canvas
void drawImage(
(HTMLImageElement or HTMLCanvasElement or HTMLVideoElement) image
,unrestricted double destinationX
,unrestricted double destinationY
);
void drawImage(
(HTMLImageElement or HTMLCanvasElement or HTMLVideoElement) image
,unrestricted double destinationX
,unrestricted double destinationY
,unrestricted double destinationW
(function() {
/**
* From: http://code.this.com/mobile/articles/fast_buttons.html
* Also see: http://stackoverflow.com/questions/6300136/trying-to-implement-googles-fast-button
*/
/** For IE8 and earlier compatibility: https://developer.mozilla.org/en/DOM/element.addEventListener */
function addListener(el, type, listener, useCapture) {
if (el.addEventListener) {
el.addEventListener(type, listener, useCapture);
(function() {
/**
* From: http://code.this.com/mobile/articles/fast_buttons.html
* Also see: http://stackoverflow.com/questions/6300136/trying-to-implement-googles-fast-button
*/
/** For IE8 and earlier compatibility: https://developer.mozilla.org/en/DOM/element.addEventListener */
function addListener(el, type, listener, useCapture) {
if (el.addEventListener) {
el.addEventListener(type, listener, useCapture);
<image>
<source src="kitten-2x.png" density="2x"></source>
<source src="kitten-100.png" density="100h"></source>
<img src="kitten.png" />
</image>
@iaincarsberg
iaincarsberg / hasglobals.js
Created March 15, 2012 11:51
Using Use.js to expose global functions form a non-amd script
function helloWorld () {
return "Hello, World!";
}
function lorem () {
return "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
}
@iaincarsberg
iaincarsberg / mersenne-twister.js
Created February 15, 2012 17:34 — forked from banksean/mersenne-twister.js
a Mersenne Twister implementation in javascript. Makes up for Math.random() not letting you specify a seed value.
/*
I've wrapped Makoto Matsumoto and Takuji Nishimura's code in a namespace
so it's better encapsulated. Now you can have multiple random number generators
and they won't stomp all over eachother's state.
If you want to use this as a substitute for Math.random(), use the random()
method like so:
var m = new MersenneTwister();
@iaincarsberg
iaincarsberg / use.js
Created January 27, 2012 14:23 — forked from tbranyen/use.js
A RequireJS compatible plugin to provide shimming capabilities declaratively.
/* RequireJS Use Plugin v0.1.0
* Copyright 2012, Tim Branyen (@tbranyen)
* use.js may be freely distributed under the MIT license.
*/
define({
version: "0.1.0",
// Invoked by the AMD builder, passed the path to resolve, the require
// function, done callback, and the configuration options.
//
@iaincarsberg
iaincarsberg / use.js
Created January 16, 2012 17:46 — forked from tbranyen/use.js
A RequireJS compatible plugin to provide shimming capabilities declaratively.
/* RequireJS Use Plugin v0.1.0
* Copyright 2012, Tim Branyen (@tbranyen)
* use.js may be freely distributed under the MIT license.
*/
define({
version: "0.1.0",
// Invoked by the AMD builder, passed the path to resolve, the require
// function, done callback, and the configuration options.
//
Entity = Compose(
function () {
// fake a unique id
this.id = Math.floor(Math.random() * 1000);
},
{
a: function () {
return this.id;
}
}