Skip to content

Instantly share code, notes, and snippets.

@imakewebthings
Created May 20, 2012 03:18
Show Gist options
  • Save imakewebthings/2739276 to your computer and use it in GitHub Desktop.
Save imakewebthings/2739276 to your computer and use it in GitHub Desktop.
One possible way to run/destroy processing sketches on deck.change
$(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