From f3c2bd5c01ced2907192d3a97c01325817da4dd7 Mon Sep 17 00:00:00 2001 From: ippo615 Date: Mon, 6 Jan 2014 19:27:47 -0500 Subject: [PATCH] Changed Kaleidoscope parameters: power and angle --- src/filters/Kaleidoscope.js | 59 +++++++++++++++++--------- test/unit/filters/Kaleidoscope-test.js | 31 +++++++------- 2 files changed, 54 insertions(+), 36 deletions(-) diff --git a/src/filters/Kaleidoscope.js b/src/filters/Kaleidoscope.js index e7d901dd..4ba08a54 100644 --- a/src/filters/Kaleidoscope.js +++ b/src/filters/Kaleidoscope.js @@ -231,10 +231,11 @@ Kinetic.Filters.Kaleidoscope = function(imageData){ var xSize = imageData.width, ySize = imageData.height; - var nCopies = Math.round( this.kaleidoscopeSides() ); - var size = Math.round( this.kaleidoscopeSides() ); - var offset = this.kaleidoscopeOffset() || 0; - if( nCopies < 1 ){return;} + var power = Math.round( this.kaleidoscopePower() ); + var angle = Math.round( this.kaleidoscopeAngle() ); + var offset = Math.floor(xSize*(angle%360)/360); + + if( power < 1 ){return;} // Work with our shared buffer canvas tempCanvas.width = xSize; @@ -247,15 +248,29 @@ polarCenterY:ySize/2 }); - // Copy/repeat a section along the r axis for effect - //var sectionSize = size; //Math.floor(xSize/nCopies); - //var nCopies = xSize/sectionSize; - var sectionSize = Math.ceil(xSize/nCopies); - var x,y,xoff,i, r,g,b,a, srcPos, dstPos; + // Determine how big each section will be, if it's too small + // make it bigger + var minSectionSize = xSize / Math.pow(2,power); + while( minSectionSize <= 8){ + minSectionSize = minSectionSize*2; + power -= 1; + } + minSectionSize = Math.ceil(minSectionSize); + var sectionSize = minSectionSize; // Copy the offset region to 0 + // Depending on the size of filter and location of the offset we may need + // to copy the section backwards to prevent it from rewriting itself + var xStart = 0, + xEnd = sectionSize, + xDelta = 1; + if( offset+minSectionSize > xSize ){ + xStart = sectionSize; + xEnd = 0; + xDelta = -1; + } for( y=0; y