From 632b81137afba5a7af5e5aa99f9b5d21d8f87582 Mon Sep 17 00:00:00 2001 From: ippo615 Date: Tue, 3 Dec 2013 18:34:24 -0500 Subject: [PATCH] Added tweening to HSV filter --- src/filters/ColorPack.js | 64 +++++++++++ test/unit/filters/ColorPack-test.js | 165 +++++++++++++++++++++++++++- 2 files changed, 226 insertions(+), 3 deletions(-) diff --git a/src/filters/ColorPack.js b/src/filters/ColorPack.js index 6c18f43f..ad0742d8 100644 --- a/src/filters/ColorPack.js +++ b/src/filters/ColorPack.js @@ -72,6 +72,70 @@ Kinetic.Filters.HSV = Kinetic.Util._FilterWrapSingleBuffer(HSV); + Kinetic.Factory.addFilterGetterSetter(Kinetic.Image, 'filterHue', 0); + Kinetic.Factory.addFilterGetterSetter(Kinetic.Image, 'filterSaturation', 1); + Kinetic.Factory.addFilterGetterSetter(Kinetic.Image, 'filterValue', 1); + + Kinetic.Filters.HSV = function(src,dst,opt){ + if( this === Kinetic.Filters ){ + HSV(src, dst||src, opt ); + }else{ + HSV.call(this, src, dst||src, opt || { + hue: this.getFilterHue(), + saturation: this.getFilterSaturation(), + value: this.getFilterValue() + }); + } + }; + + /** + * get filter hue. Returns the hue shift for the HSV filter. + * 0 is no change, 359 is the maximum shift. + * @name getFilterHue + * @method + * @memberof Kinetic.Image.prototype + */ + + /** + * set filter hue. Sets the hue shift for the HSV filter. + * 0 is no change, 359 is the maximum shift. + * @name setFilterHue + * @method + * @memberof Kinetic.Image.prototype + */ + + /** + * get filter saturation. Returns the saturation scale for the HSV + * filter. 1 is no change, 0.5 halves the saturation, 2.0 doubles, etc.. + * @name getFilterSaturation + * @method + * @memberof Kinetic.Image.prototype + */ + + /** + * set filter saturation. Set the saturation scale for the HSV + * filter. 1 is no change, 0.5 halves the saturation, 2.0 doubles, etc.. + * @name setFilterSaturation + * @method + * @memberof Kinetic.Image.prototype + */ + + /** + * get filter value. Returns the value scale for the HSV + * filter. 1 is no change, 0.5 halves the value, 2.0 doubles, etc.. + * @name getFilterValue + * @method + * @memberof Kinetic.Image.prototype + */ + + /** + * set filter value. Set the value scale for the HSV + * filter. 1 is no change, 0.5 halves the value, 2.0 doubles, etc.. + * @name setFilterValue + * @method + * @memberof Kinetic.Image.prototype + */ + })(); (function() { diff --git a/test/unit/filters/ColorPack-test.js b/test/unit/filters/ColorPack-test.js index 3bd1243c..d1052b56 100644 --- a/test/unit/filters/ColorPack-test.js +++ b/test/unit/filters/ColorPack-test.js @@ -108,14 +108,100 @@ suite('Color Pack', function() { layer.add(darth); stage.add(layer); - darth.setFilter(Kinetic.Filters.ShiftHue); - darth.setFilterHueShiftDeg(360); + darth.setFilter(Kinetic.Filters.HSV); + darth.setFilterHue(360); layer.draw(); var tween = new Kinetic.Tween({ node: darth, duration: 5.0, - filterHueShiftDeg: 0, + filterHue: 0, + easing: Kinetic.Easings.EaseInOut + }); + + darth.on('mouseover', function() { + tween.play(); + }); + + darth.on('mouseout', function() { + tween.reverse(); + }); + + done(); + }; + imageObj.src = 'assets/lion.png'; + + }); + + // ====================================================== + test('saturation tween transparancy', function(done) { + var stage = addStage(); + + var imageObj = new Image(); + imageObj.onload = function() { + + var layer = new Kinetic.Layer(); + darth = new Kinetic.Image({ + x: 10, + y: 10, + image: imageObj, + draggable: true + }); + + layer.add(darth); + stage.add(layer); + + darth.setFilter(Kinetic.Filters.HSV); + darth.setFilterSaturation(2.0); + layer.draw(); + + var tween = new Kinetic.Tween({ + node: darth, + duration: 5.0, + filterSaturation: 0.001, + easing: Kinetic.Easings.EaseInOut + }); + + darth.on('mouseover', function() { + tween.play(); + }); + + darth.on('mouseout', function() { + tween.reverse(); + }); + + done(); + }; + imageObj.src = 'assets/lion.png'; + + }); + + // ====================================================== + test('value tween transparancy', function(done) { + var stage = addStage(); + + var imageObj = new Image(); + imageObj.onload = function() { + + var layer = new Kinetic.Layer(); + darth = new Kinetic.Image({ + x: 10, + y: 10, + image: imageObj, + draggable: true + }); + + layer.add(darth); + stage.add(layer); + + darth.setFilter(Kinetic.Filters.HSV); + darth.setFilterValue(2.0); + layer.draw(); + + var tween = new Kinetic.Tween({ + node: darth, + duration: 5.0, + filterValue: 0.001, easing: Kinetic.Easings.EaseInOut }); @@ -279,4 +365,77 @@ suite('Color Pack', function() { done(); }); + // ====================================================== + test('value gradient', function (done) { + var stage = addStage(); + + var shapesLayer = new Kinetic.Layer(); + + // The important line! + shapesLayer.on('draw', function () { + var src, dst, i, w=40; + var ctx = this.getContext(); + var ctxWidth = this.getCanvas().width; + var ctxHeight = this.getCanvas().height; + var xSize = Math.floor(ctxWidth/w); + var ySize = Math.floor(ctxHeight); + for( i=0; i