]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
better test sketches, fixed toggle so that it waits for canvas to be defined.
authorChristopher De Cairos <chris.decairos@gmail.com>
Mon, 6 Jun 2011 14:36:24 +0000 (10:36 -0400)
committerChristopher De Cairos <chris.decairos@gmail.com>
Mon, 6 Jun 2011 14:36:24 +0000 (10:36 -0400)
plugins/processing/popcorn.processing.js
plugins/processing/test.pjs
plugins/processing/test2.pjs

index 89f7c15757392718cda997375ab19161a381a3bd..5ed38b871fe3bd6bb7b94b2cc3de7dbda9e9b046 100644 (file)
@@ -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 ); 
       }
     };
     
index 589068f7b170aa73a2ca377e5ce45965477dc7e1..6729f1959fadcd1d7db67cdcf91a81c645c83e0a 100644 (file)
@@ -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<r; i++){
-       rotate(PI/4);
-  }
-  rect(-26, -26, 52, 52);
-
-  r++;
+void setup()   
+{  
+  size(200, 200);  
+  stroke(255);  
+  frameRate(30);  
+}  
   
-  if(r == 5){
-       r=0;
-  }
-}
-void switch_status(){
-       if(colour=="white"){
-               colour = "blue";
-       }else{
-               colour = "white";
-       }
-}
+void draw()   
+{  
+  background(51);  
+  a = a - 1;  
+  if (a < 0) {   
+    a = height;   
+  }  
+  line(0, a, width, a);    
+}  
index 4141d56bd47cd2e1f077e7b4a18724f1175f875b..686692bcf55d822392c087f020103ef84ad94a85 100644 (file)
@@ -1,27 +1,81 @@
-
-var w    = 100;
-var h    = 100;
-float r = 0.0;
-
-void setup() {
-  size(width, height);
-  
-  // Frame rate
-  frameRate(8);
+// All Examples Written by Casey Reas and Ben Fry  
+// unless otherwise stated.  
+// for puff head  
+float headX;  
+float headY;  
+float speedX = .7;  
+float speedY = .9;  
+  
+// for puff body  
+int cells = 1000;  
+float[]px= new float[cells];  
+float[]py= new float[cells];  
+float[]radiiX = new float[cells];  
+float[]radiiY = new float[cells];  
+float[]angle = new float[cells];  
+float[]frequency = new float[cells];  
+float[]cellRadius = new float[cells];  
+  
+void setup(){  
+    
+  size(200, 200);  
+  // begin in the center  
+  headX = width/2;  
+  headY = height/2;  
+  
+  //fill body arrays  
+  for (int i=0; i< cells; i++){  
+    radiiX[i] = random(-7, 7);   
+    radiiY[i] = random(-4, 4);  
+    frequency[i]= random(-9, 9);  
+    cellRadius[i] = random(16, 30);  
+  }  
+  frameRate(30);  
   noLoop();
-}
-
-void draw() {
-  background(#ff0000);
-  translate(width/2, height/2);
-  for(int i = 0; i<r; i++){
-       rotate(PI/4);
-  }
-  rect(-26, -26, 52, 52);
-
-  r++;
-  
-  if(r == 5){
-       r=0;
-  }
-}
+}  
+  
+void draw(){  
+  background(0);  
+  noStroke();  
+  fill(255, 255, 255, 5);  
+  
+  //follow the leader  
+  for (int i =0; i< cells; i++){  
+    if (i==0){  
+      px[i] = headX+sin(radians(angle[i]))*radiiX[i];  
+      py[i] = headY+cos(radians(angle[i]))*radiiY[i];  
+    }   
+    else{  
+      px[i] = px[i-1]+cos(radians(angle[i]))*radiiX[i];  
+      py[i] = py[i-1]+sin(radians(angle[i]))*radiiY[i];  
+  
+      //check collision of body  
+      if (px[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;  
+  }  
+}