Skip to content

Instantly share code, notes, and snippets.

@chbrown
Created May 14, 2011 19:33
Show Gist options
  • Save chbrown/972544 to your computer and use it in GitHub Desktop.
Save chbrown/972544 to your computer and use it in GitHub Desktop.
UseCSSTransforms = false;
ShowPivots = false;
M = {
rotation : function(rotation) {
return CanvasSupport.tRotationMatrix(rotation)
},
scaling : function(x, y) {
return CanvasSupport.tScalingMatrix(x, y)
},
translation : function(x, y) {
return CanvasSupport.tTranslationMatrix(x, y)
}
}
V = {
rotate : function(v, rotation) {
return V.multiply(v, M.rotation(rotation))
},
add : function(v, u) {
return [u[0] + v[0], u[1] + v[1]]
},
multiply : function(v, matrix) {
return CanvasSupport.tMatrixMultiplyPoint(matrix, v[0], v[1])
}
}
ERectangle = Klass(ElementNode, {
initialize : function(w,h, config) {
var d = E('div');
d.style.width = w+'px';
d.style.height = h+'px';
d.style.backgroundColor = config.fill;
ElementNode.initialize.call(this, d, config);
if (config.centered) this.align = this.valign = 'center';
}
});
if (!UseCSSTransforms)
ERectangle = Rectangle;
Explosion = Klass(CanvasNode, {
catchMouse : false,
cursor : 'default',
circleGradient : new Gradient({
type : 'radial',
endRadius : 15,
colorStops : [
[ 0.0, "rgba(255,255,255,1)" ],
[ 0.1, "rgba(255,205,80,1)" ],
[ 0.25, "rgba(200,60,20,0.5)" ],
[ 1, "rgba(10,10,20,0.2)" ]
]
}),
initialize : function(size, config) {
CanvasNode.initialize.call(this, config)
var main = new Circle(15)
main.fill = this.circleGradient
// main.compositeOperation = 'normal'
this.zIndex = 10
this.main = main
this.append(main)
this.size = size
this.addFrameListener(this.blowup)
this.after(500, this.removeSelf)
},
blowup : function(t, dt) {
if (this.startTime == null)
this.startTime = t
var elapsed = Math.min(500, t - this.startTime)
var fac = 0.48 * 0.003 * Math.PI
this.main.scale = 1 + this.size * Math.tan(elapsed * fac)
}
})
EndCredits = Klass(CanvasNode, {
initialize : function() {
CanvasNode.initialize.call(this);
var txt = E('div', 'The End');
txt.className = 'theEnd';
var e = new ElementNode(txt);
e.align = e.valign = 'center';
this.append(e);
this.x = 512-1000;
this.y = 384-1000;
this.addFrameListener(this.spin);
},
spin: function(t,dt) {
if (this.startTime == null)
this.startTime = t;
var elapsed = t - this.startTime;
if (elapsed >= 1000) {
this.x = 502 - 0.06*(500-Math.max(0, 1500-elapsed));
this.y = 334 + 0.01*(500-Math.max(0, 1500-elapsed));
this.rotation = -0.1;
this.scale = 1 + (0.0001*Math.max(0, 1500-elapsed)*Math.abs(Math.sin((elapsed-1000)/100)));
} else {
var angle = -(1000-elapsed) / 500;
var r = 2*(1000-elapsed);
this.rotation = -0.1 + angle;
this.x = 502 + Math.cos(angle)*r;
this.y = 334 + Math.sin(angle)*r;
this.scale = 1 + r/800;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment