From: ScottDowne Date: Mon, 16 May 2011 02:56:49 +0000 (-0400) Subject: [#t383] initial gml commit, no tests yet, need to do something about external file X-Git-Tag: v0.6~2^2~5^2~4 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=cd6b5ad4890841a44c34efda6e9012388d059b68;p=popcorn-js.git [#t383] initial gml commit, no tests yet, need to do something about external file --- diff --git a/plugins/gml/gmlplayer.js b/plugins/gml/gmlplayer.js new file mode 100644 index 0000000..451cf30 --- /dev/null +++ b/plugins/gml/gmlplayer.js @@ -0,0 +1,103 @@ +var _stroke = 0; // current stroke +var onPt = 0; // current point on stroke +var onStroke = 0; // current point on stroke +var start = +(new Date()); +var x, y, rotation = false; +var strokes=0; +var data = {}; +var toggle = 0; +var ready = false; +var play = function(){}; +var dur = 0; +var options = {}; +var video = document.getElementById("video"); + +// empty on purpose +void setup() {} +void draw() { + + play(); +} + +void construct( data, options ) { + + size(640,640); + frameRate(60); + smooth(); + reset(); + noLoop(); + + dur = (options.end - options.start); + drawingDur = (options.endDrawing - options.start); + + this.options = options; + + var si = setInterval(function() { + + if (!data) return; + clearInterval(si); + + this.data = data; + strokes = this.data.gml.tag.drawing.stroke; + var tag = this.data.gml.tag; + var app_name = tag.header && tag.header.client && tag.header.client.name; + rotation = app_name == 'Graffiti Analysis 2.0: DustTag' || + app_name == 'DustTag: Graffiti Analysis 2.0' || + app_name == 'Fat Tag - Katsu Edition'; + + + play = function() { + + if ( video.currentTime < options.endDrawing ) { + seek( ( video.currentTime - options.start ) / dur * strokes.pt.length ); + } + + }; + }, 50); +} + + +void reset() { + background( 0 ); + onPt = onStroke = 0; + x = y = null; +} + +function drawLine(x,y,x2,y2) { + _x = rotation ? y*height : x*width; + _y = rotation ? width-(x*width) : y*height; + _x2 = rotation ? y2 * height : x2*width; + _y2 = rotation ? width - (x2 * width) : y2*height; + stroke(0); + strokeWeight(13); + strokeCap(SQUARE); + line(_x,_y,_x2,_y2); + stroke(255); + strokeWeight(12); + strokeCap(ROUND); + line(_x,_y,_x2,_y2); + //ol = { x: _x, y: _y, x2: _x2, y2: _y2 }; +} + +function seek( point ) { + if ( point < onPt ) reset(); + + var start; var hyp; + while (onPt <= point) { + if (!strokes) return; + _stroke = strokes.length ? strokes[onStroke] : strokes; + pt = _stroke.pt[onPt]; + var p = onPt; + if (x !== null ) drawLine(x,y,pt.x,pt.y); + /*if (onPt) { +if (++onPt >= _stroke.pt.length) { +//if (!strokes.length || ++onStroke >= strokes.length) return reset(); +//onPt = 0; +} +}*/ + x = pt.x; + y = pt.y; + if (onPt==p) onPt++; //went back to 0 + } +} + diff --git a/plugins/gml/popcorn.gml.html b/plugins/gml/popcorn.gml.html new file mode 100644 index 0000000..8a19bc9 --- /dev/null +++ b/plugins/gml/popcorn.gml.html @@ -0,0 +1,59 @@ + + + + Popcorn attribution Plug-in Demo + + + + + + +

Popcorn Attribution Plug-in Demo

+

A attribution displaying 'A Shared Culture, Jesse Dylan, license: CC-BY-N6' will appear at 0 seconds and disappear at 10 seconds.

+

A attribution displaying 'Internet, The Computer Chronicles' will appear at 5 seconds and disappear at 15 seconds.

+
+ +
+
+
+ + diff --git a/plugins/gml/popcorn.gml.js b/plugins/gml/popcorn.gml.js new file mode 100644 index 0000000..aa12d19 --- /dev/null +++ b/plugins/gml/popcorn.gml.js @@ -0,0 +1,78 @@ +// PLUGIN: GML + +(function (Popcorn) { + + var processingLoaded = false; + + var ajax = function ajax(url) { + + var xhr = new XMLHttpRequest(); + xhr.open("GET", url, false); + xhr.setRequestHeader("If-Modified-Since", "Fri, 1 Jan 1960 00:00:00 GMT"); + xhr.send(null); + // failed request? + if (xhr.status !== 200 && xhr.status !== 0) { throw ("XMLHttpRequest failed, status code " + xhr.status); } + return xhr.responseText; + }; + + Popcorn.getScript( "http://processingjs.org/content/download/processing-js-1.1.0/processing-1.1.0.js", function() { + + processingLoaded = true; + }); + + /** +*/ + Popcorn.plugin( "gml" , { + + /** +*/ + _setup : function( options ) { + + var self = this; + + options.endDrawing = options.endDrawing || options.end; + // create a canvas to put in the target div + options.container = document.createElement( 'canvas' ); + + options.container.style.display = "none"; + options.container.setAttribute( 'id', 'canvas' + options.gmltag ); + + if ( document.getElementById( options.target ) ) { + document.getElementById( options.target ).appendChild( options.container ); + } + + + // makes sure both processing.js and the gml player are loaded + var readyCheck = setInterval(function() { + + if ( !processingLoaded ) { + + return; + } + + clearInterval(readyCheck); + Popcorn.getJSONP( "http://000000book.com/data/" + options.gmltag + ".json?callback=", function( data ) { + + new Processing( options.container, ajax( "gmlplayer.js" ) ); + options.pjsInstance = Processing.getInstanceById( 'canvas' + data.id ); + options.pjsInstance.construct( data, options ); + options._running && options.pjsInstance.loop(); + }, false ); + }, 5); + }, + /** +*/ + start: function( event, options ) { + + options.pjsInstance && options.pjsInstance.loop(); + options.container.style.display = "block"; + }, + /** +*/ + end: function( event, options ) { + + options.pjsInstance && options.pjsInstance.noLoop(); + options.container.style.display = "none"; + } + }); +})( Popcorn );