Skip to content

Instantly share code, notes, and snippets.

@jessefulton
Created March 6, 2012 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jessefulton/1983475 to your computer and use it in GitHub Desktop.
Save jessefulton/1983475 to your computer and use it in GitHub Desktop.
Kapi Text Transform (current)
(function () {
if (!(document.getElementsByTagName("canvas").length)) {
return;
}
(function () {
var myKapi,
myText;
myKapi = kapi(document.getElementById('demo1'), {
fps: 30,
// Set up some basic styles for the canvas
styles: {
height: '400px',
width: '500px',
background: '#333'
}
}).play(); // Start the animation
myText = myKapi.add(new stringActor(), {
name: 'circle1',
text: 'foobar',
x: 70,
y: 70,
color: '#00ffaa',
easing: 'easeInOutQuint',
m11: 1,
m12: 0,
m21: 0,
m22: 1,
dx: 0,
dy: 0
}).keyframe(0, { })
.to('2s', {
x: '+=100',
y: 50,
m11: 1,
m12: .1,
m21: .1,
m22: 1,
dx: 0,
dy: 0
}, {
'start': function () {
console.log('Immediate action started!', this);
},
'complete': function () {
console.log('Immediate action completed!', this);
}
});
}());
})();
var stringActor = function() {
this.setup = function (kapiInst, actorInst, params) {
if (window.console) {
console.log('Setting up: ' + this.id)
}
}
this.draw = function (ctx, kapiInst, actorInst){
ctx.save();
ctx.transform(this.m11, this.m12, this.m21, this.m22, this.dx, this.dy)
ctx.font = '50px arial,sans-serif' ;
ctx.fillStyle = 'black' ;
ctx.fillText (this.text, this.x || 0, this.y || 0);
ctx.restore();
return this;
}
this.teardown = function (actorName, kapiInst) {
if (window.console) {
console.log('Tearing down ' + actorName);
console.dir(kapiInst);
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment