|
Documentation
Documentation portal for CAKE.
IntroductionI'll be pasting and linking the API documentation from cake.js here. And probably writing some sort of introductory tutorial. What CAKE code looks likeAn example with a rotating rectangle: var c = E.canvas(500, 500) // create a new canvas element
var canvas = new Canvas(c) // create a CAKE [Canvas] for the element
canvas.fill = [255,255,255,0.8] // set the Canvas background to 0.8 opacity white
canvas.clear = false // show the previous frame behind the current one
var rect = new Rectangle(100, 100) // create a CAKE [Rectangle] object
rect.x = 250 // move the Rectangle to (250, 250)
rect.y = 250
rect.fill = 'green' // fill the Rectangle with green color
// rotate the Rectangle on every frame
rect.addFrameListener(function(t) {
this.rotation = ((t / 3000) % 1) * Math.PI * 2
})
canvas.append(rect) // append the Rectangle to the Canvas
document.body.appendChild(c) // append the canvas element to document bodyUsing CAKE with Internet ExplorerThe easiest way is to use Google Chrome Frame. See an example in this canvas animation demo. Add <meta http-equiv="X-UA-Compatible" content="chrome=1"> to the head of your document and the following snippet to your page. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/chrome-frame/1/CFInstall.min.js"> </script>
<div id="placeholder"></div>
<script>CFInstall.check({ node: "placeholder" });</script> If you have way too much free time on your hands, you could hypothetically write a SilverLight implementation of the Canvas API. ExplorerCanvas doesn't work at all well for CAKE. Last I checked, ExplorerCanvas's VML renderer chokes on the animations and will likely make IE hang or crash or both. How CAKE's inheritance model works: the Klass objectThe Klass object is used to do inheritance in a less cumbersome fashion than unaugmented JavaScript. To create a new class, you do MyClass = Klass(superclass, class_body). Calling Klass returns a new constructor function created from the parameters to Klass. The prototypes of the parameters (or the parameters themselves) are merged with the new constructor's prototype. Finally, the constructor's prototype is merged with the constructor itself, so that you can write Shape.getArea.call(this) instead of Shape.prototype.getArea.call(this). The constructor calls the class's #initialize with the constructor's arguments, so you can easily derive a class from another and customize its initialization procedure, as you can see from the example below. Shape = Klass({
getArea : function() {
raise('No area defined!')
}
})
Rectangle = Klass(Shape, {
initialize : function(x, y) {
this.x = x
this.y = y
},
getArea : function() {
return this.x * this.y
}
})
Square = Klass(Rectangle, {
initialize : function(s) {
Rectangle.initialize.call(this, s, s)
}
})
new Square(5).getArea()
//=> 25Main classes
Scene graph node classes
Fills and strokes
Examples of possible fill / stroke settings.null // use the inherited value and on/off setting true // turn on fill / stroke and use the inherited value false // turn off fill / stroke 'none' // turn off fill / stroke 'white' // CSS color name '#fff' // short CSS hex color '#ffffff' // long CSS hex color 'rgba(255,255,255, 1.0)' // CSS RGBA color. RGB and HSLA colors work too, if your browser supports them. [255, 255, 255, 1.0] // color component array new Gradient(...) // gradient fill / stroke new Pattern(myImage, 'no-repeat') // pattern fill / stroke SVGParserSVGParser is an SVG parser for simple documents. Converts SVG DOM to CAKE scene graph. SVGParser has an emphasis on importing graphical images, not on the "HTML-killer" features of SVG. Some of the several missing features: |
► Sign in to add a comment