Created
May 20, 2012 03:18
One possible way to run/destroy processing sketches on deck.change
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).bind('deck.init', function() { | |
$.each(Processing.instances, function(i, instance) { | |
instance.exit(); // Exit all drawings to start | |
}); | |
}); | |
$(document).bind('deck.change', function(event, from, to) { | |
var $exitingCanvases = $.deck('getSlide', from).find('canvas[data-processing-sources]'); | |
var $enteringCanvases = $.deck('getSlide', to).find('canvas[data-processing-sources]'); | |
$enteringCanvases.each(function(i, canvas) { | |
var method = $(canvas).data('loop') ? 'loop' : 'redraw'; | |
// Add data-loop to the canvas element if you want it to loop instead of redraw once | |
Processing.getInstanceById(canvas.id)[method](); | |
}); | |
$exitingCanvases.each(function(i, canvas) { | |
Processing.getInstanceById(canvas.id).exit(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment