diff --git a/examples/SundarPichai.jpeg b/examples/SundarPichai.jpeg deleted file mode 100644 index 2dfe2f93..00000000 Binary files a/examples/SundarPichai.jpeg and /dev/null differ diff --git a/examples/red.jpg b/examples/red.jpg new file mode 100644 index 00000000..53148101 Binary files /dev/null and b/examples/red.jpg differ diff --git a/index.js b/index.js index 25b3e0c4..a327a0c2 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,10 @@ console.log('\x1b[31m%s\x1b[0m',"This is the output of the module"); -require('./src/ImageSequencerNode'); +require('./src/ImageSequencer'); sequencer = ImageSequencer(); -sequencer.loadImages({red:'../../red.jpg'}); +sequencer.loadImages({red:'examples/red.jpg'},function(){ + sequencer.addSteps(['do-nothing','do-nothing-pix','do-nothing']); + sequencer.run(); + sequencer.removeSteps(1); + sequencer.insertSteps(1,'do-nothing'); + sequencer.insertSteps(-1,'do-nothing'); +}); diff --git a/src/ImageSequencer.js b/src/ImageSequencer.js index c74a18ae..34143106 100644 --- a/src/ImageSequencer.js +++ b/src/ImageSequencer.js @@ -30,7 +30,7 @@ ImageSequencer = function ImageSequencer(options) { var image, steps = [], - modules = require('./ModulesNode'), + modules = require('./Modules'), images = {}; // if in browser, prompt for an image @@ -170,6 +170,24 @@ ImageSequencer = function ImageSequencer(options) { run = {}; this_ = this; + if (arguments.length==2 || arguments.length==3) { + if (typeof(arguments[0])=="number") { + if (typeof(arguments[1])=="string" || objTypeOf(arguments[1])=="Array") { + var p = arguments[0]; + var m = arguments[1]; + var o = arguments[2]; + arguments = []; + arguments[0] = {}; + for (image in this_.images) { + arguments[0][image] = { + index: p, + name: m, + o: o + }; + } + } + } // end if argument is string + } if(arguments.length==4 || arguments.length==3) { o = o || {}; size = this_.images[image].steps.length; @@ -182,13 +200,22 @@ ImageSequencer = function ImageSequencer(options) { if (objTypeOf(arguments[0])=='Object') { for (img in arguments[0]) { var details = arguments[0][img]; - if (objTypeOf(details) == "Object") - {insertStep(img,details.index,details.name,details.o); run[img]=details.index;} + if (objTypeOf(details) == "Object") { + size = this_.images[img].steps.length; + details.index = (details.index==size)?details.index:details.index%size; + if (details.index<0) details.index += size+1; + insertStep(img,details.index,details.name,details.o); + run[img]=details.index; + } else if (objTypeOf(details) == "Array") { details = details.sort(function(a,b){return b.index-a.index}); run[img] = details[details.length-1].index; - for (i in details) + for (i in details) { + size = this_.images[img].steps.length; + details[i].index = (details[i].index==size)?details[i].index:details[i].index%size; + if (details[i].index<0) details[i].index += size+1; insertStep(img,details[i].index,details[i].name,details[i].o); + } } } } // end if argument is object @@ -198,7 +225,7 @@ ImageSequencer = function ImageSequencer(options) { } function run(t_image,t_from) { - log('\x1b[31m%s\x1b[0m',"Running the Sequencer!"); + log('\x1b[32m%s\x1b[0m',"Running the Sequencer!"); this_ = this; runimg = {}; json_q = {}; diff --git a/test/image-sequencer.js b/test/image-sequencer.js index 7a5b6746..8b69db98 100644 --- a/test/image-sequencer.js +++ b/test/image-sequencer.js @@ -6,7 +6,7 @@ var test = require('tape'); // We should only test headless code here. // http://stackoverflow.com/questions/21358015/error-jquery-requires-a-window-with-a-document#25622933 -require('../src/ImageSequencerNode.js'); +require('../src/ImageSequencer.js'); var sequencer = ImageSequencer({ ui: "none" }); @@ -24,7 +24,7 @@ test('Image Sequencer has tests', function (t) { }); test('loadImages loads a step', function (t){ - sequencer.loadImages('test','examples/SundarPichai.jpeg'); + sequencer.loadImages('test','examples/red.jpg'); t.equal(sequencer.images.test.steps.length, 1, "It Does!"); t.end(); }); @@ -56,4 +56,3 @@ test('run creates output of steps', function (t) { t.equal(type,"object"); t.end(); }); -