From: Christopher De Cairos Date: Mon, 6 Jun 2011 14:36:24 +0000 (-0400) Subject: better test sketches, fixed toggle so that it waits for canvas to be defined. X-Git-Tag: v0.7^2~31^2~15 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=c8f31461d67d3fc617cc0e77faa7711ffe4c4702;p=popcorn-js.git better test sketches, fixed toggle so that it waits for canvas to be defined. --- diff --git a/plugins/processing/popcorn.processing.js b/plugins/processing/popcorn.processing.js index 89f7c15..5ed38b8 100644 --- a/plugins/processing/popcorn.processing.js +++ b/plugins/processing/popcorn.processing.js @@ -22,12 +22,18 @@ var scriptLoadingFired = false, var sketchInstance, toggle = function( on ) { - if ( on ) { - canvas.style.display = "inline"; - processingInstance.loop(); + if (canvas) { + if ( on ) { + canvas.style.display = "inline"; + processingInstance.loop(); + } else { + canvas.style.display = "none"; + processingInstance.noLoop(); + } } else { - canvas.style.display = "none"; - processingInstance.noLoop(); + setTimeout ( function () { + toggle ( on ); + }, 10 ); } }; diff --git a/plugins/processing/test.pjs b/plugins/processing/test.pjs index 589068f..6729f19 100644 --- a/plugins/processing/test.pjs +++ b/plugins/processing/test.pjs @@ -1,38 +1,20 @@ -var w = 100; -var h = 100; -float r = 0.0; -var colour = "white"; - -void setup() { - size(width, height); +// All Examples Written by Casey Reas and Ben Fry +// unless otherwise stated. +float a = 100; - // Frame rate - frameRate(8); -} - -void draw() { - background(#000000); - if(colour=="white"){ - fill(#ffffff); - }else{ - fill(#151B8D); - } - translate(width/2, height/2); - for(int i = 0; i= width-cellRadius[i]/2 || px[i] <= cellRadius[i]/2){ + radiiX[i]*=-1; + cellRadius[i] = random(1, 40); + frequency[i]= random(-13, 13); + } + if (py[i] >= height-cellRadius[i]/2 || py[i] <= cellRadius[i]/2){ + radiiY[i]*=-1; + cellRadius[i] = random(1, 40); + frequency[i]= random(-9, 9); + } + } + // draw puff + ellipse(px[i], py[i], cellRadius[i], cellRadius[i]); + // set speed of body + angle[i]+=frequency[i]; + } + + // set velocity of head + headX+=speedX; + headY+=speedY; + + //check boundary collision of head + if (headX >= width-cellRadius[0]/2 || headX <=cellRadius[0]/2){ + speedX*=-1; + } + if (headY >= height-cellRadius[0]/2 || headY <= cellRadius[0]/2){ + speedY*=-1; + } +}