diff --git a/Kaleidoscope/Kaleidoscope.js b/Kaleidoscope/Kaleidoscope.js index 0392673..ac337bf 100644 --- a/Kaleidoscope/Kaleidoscope.js +++ b/Kaleidoscope/Kaleidoscope.js @@ -3,7 +3,7 @@ * Visit http://createjs.com/ for documentation, updates and examples. * * Copyright (c) 2013 gskinner.com, inc. -* +* * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without @@ -12,10 +12,10 @@ * copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following * conditions: -* +* * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. -* +* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND @@ -35,88 +35,41 @@ * @class Kaleidoscope * @param radius {Number} The radius of the kaleidoscope. * @param source {DisplayObject} The DisplayObject to use as the source. + * The DisplayObject that will be drawn into each slice. Any transformations on the + * source display object will be applied when the slice is drawn. + * The source will be drawn multiple times (ex. 20 times for a 10 slice kaleidoscope). + * If the source is expensive to draw (a complex Shape, or Container with + * many children), then you may wish to pre-render the source a single time using + * the cache() method. * @param [slices=8] {Number} The number of slices to draw. * @param [pattern] {Array} Pattern of relative ratios for the slice sizes. For example, passing [1,2] would result in every second slice being twice as large as it's neighbors. + * @param [pad=0] {Number} + * Specifies the amount to overlap each slice with its neighbours to reduce seams + * between them. Generally a value of 0.6 works well, but you may wish to adjust this + * for sources with transparency. + * You may still see seams if your source draws multiple times into each slice. For + * example, a Container with multiple children. Pre-rendering the source by using the + * cache() method should resolve this. * @extends DisplayObject * @constructor **/ -var Kaleidoscope = function(radius, source, slices, pattern) { - this.initialize(radius, source, slices, pattern); +function Kaleidoscope (radius, source, slices, pattern, pad) { + this.DisplayObject_constructor(); + if (!pattern) { pattern = [1]; } + if (!slices) { slices = 8; } + if (!pad) { pad = 0; } + this.radius = radius; + this.source = source; + this.pad = pad; + var l = pattern.length; + if (slices/pattern.length%1 != 0) { throw "slices must be divisible by pattern length"; } + var ttl = 0; + for (var i=0; i 0 && this.scaleX != 0 && this.scaleY != 0 && hasContent); + return !!(this.visible && this.alpha > 0 && this.scaleX != 0 && this.scaleY != 0 && hasContent); } - /** - * @property DisplayObject_draw - * @type Function - * @private - **/ - p.DisplayObject_draw = p.draw; - /** * Draws the display object into the specified context ignoring it's visible, alpha, shadow, and transform. * Returns true if the draw was handled (useful for overriding functionality). @@ -158,10 +104,10 @@ var p = Kaleidoscope.prototype = new createjs.DisplayObject(); this._drawSlice(ctx, r-a, a, false, pad); r += a*2; } - + return true; } - + /** * Returns a string representation of this object. * @method toString @@ -171,11 +117,10 @@ var p = Kaleidoscope.prototype = new createjs.DisplayObject(); return "[Kaleidoscope]"; } - // private methods: p._drawSlice = function(ctx, r, a, mirror, pad) { ctx.save(); - + ctx.rotate(r+a); if (mirror) { ctx.scale(1,-1); } ctx.beginPath(); @@ -184,12 +129,12 @@ var p = Kaleidoscope.prototype = new createjs.DisplayObject(); ctx.lineTo(-this.pad,this.pad); ctx.closePath(); ctx.clip(); - + this.source.updateContext(ctx); this.source.draw(ctx); - + ctx.restore(); } - -window.Kaleidoscope = Kaleidoscope; -}()); \ No newline at end of file + +window.Kaleidoscope = createjs.promote(Kaleidoscope, "DisplayObject"); +}()); diff --git a/Kaleidoscope/demo.html b/Kaleidoscope/demo.html index 48ad745..56c8f72 100644 --- a/Kaleidoscope/demo.html +++ b/Kaleidoscope/demo.html @@ -16,28 +16,28 @@
Nebula image by NASA. - - + + - \ No newline at end of file +