We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Problems with slow rendering (JMyron)
Page Index Toggle Pages: 1
Problems with slow rendering (JMyron) (Read 1520 times)
Problems with slow rendering (JMyron)
Feb 17th, 2010, 9:07am
 
I dont know why, but my code is running insanely slow.  Here it is, dont know how to fix the slow down:

Code:
import fullscreen.*;
import japplemenubar.*;

import JMyron.*;

FullScreen fs;
PShape featherSVG;
float thisScale = 10;
float cols, rows;
Feather feather1;
ArrayList featherList;
JMyron m;

float randomSpeed = random(-5,5);

int[][] a;
int arrayCounter;
void setup()
{
 int widthVar = 1440;
 int heightVar = 900;

 size(widthVar,heightVar);
 m = new JMyron();
 m.start(widthVar,heightVar);
 m.findGlobs(1);
 println("Myron " + m.version());
 fs = new FullScreen(this);
 fs.enter();
 smooth();
 cols = width/thisScale;
 rows = height/thisScale;
 feather1 = new Feather(0,0);
 featherList = new ArrayList();
 for(int i=0;i<widthVar;i+=50)
 {
   for(int j=0;j<heightVar;j+=50){
     featherList.add(new Feather(i,j));
   }
 }



}

void mousePressed(){
 m.settings();
}

void draw()
{
 m.trackColor(255,255,0,255);
 //pushMatrix();
 //translate(10,5);
 featherSVG = loadShape("feather.svg");
 background(255);
 //image(m.cameraImage(),0,0);



 for(int i=0;i<featherList.size();i++)
 {
   Feather feathers = (Feather) featherList.get(i);
   feathers.moveFeather();
   feathers.displayFeather();

 }

 m.update();
 a = m.globCenters();

}





class Feather
{
 float xpos;
 float ypos;
 float xspeed;
 float yspeed;
 float[] pcompare;
 

 Feather(float tempXPos, float tempYPos/*, float tempXSpeed, float tempYSpeed*/)
 {
   xpos = tempXPos;
   ypos = tempYPos;
   /*xspeed = tempXSpeed;
   yspeed = tempYSpeed;*/
 }


 void makeLines(){
   stroke(0,0,0);
     for(int i=0;i<a.length;i++){
       int[] p = a[i];
       point(p[0],p[1]);
     }
   

 }
 


 void moveFeather()
 {/*
 if(a!=null) {
 for(int i=0;i<a.length;i++)
 {
   if(a != null){
   int[] p = a[i];
  if(pcompare[i] != p[0] && pcompare[i] != p[1])
  {
    if(((p[0]-pcompare[i]) > 0))
   {
    xspeed = xspeed+(p[0]+pcompare[i]);
    yspeed = yspeed+(p[1]+pcompare[i]);
   }
  }
 } }}*/
   
   if(a!=null){
   makeLines();
   }
 
   if(a!=null){
   for(int i=0; i<a.length;i++){  
       int[] p = a[i];
    xpos = xpos+xspeed;
    ypos = ypos+yspeed;
   
   
    if(abs(dist(p[0],p[1],xpos,ypos))<80){
     if(xpos<p[0] && xpos>p[0]-80) {
       xspeed -= randomSpeed;
     }

     if(xpos<p[0] && xpos>p[0]-50) {
       xspeed -=randomSpeed;
     }
     if(xpos>p[0] && xpos<p[0]+80) {
       xspeed +=randomSpeed;
     }
     if(xpos>p[0] && xpos<p[0]+50) {
       xspeed +=randomSpeed;
     }

     if(xpos >= width){
       xspeed =-abs(randomSpeed);
     }
     if(xpos <= 0){
       xspeed = randomSpeed;
     }
     if(p[0] == 0)
     {
       xspeed = randomSpeed;
     }
    }
     
   
   
    if(abs(dist(p[0],p[1],xpos,ypos))<80){
     
     
     
     if(ypos<p[1] && ypos>p[1]-80) {
       yspeed -= randomSpeed;
     }

     if(ypos<p[1] && ypos>p[1]-50) {
       xspeed -=randomSpeed;
     }
     if(ypos>p[1] && ypos<p[1]+80) {
       yspeed +=randomSpeed;
     }
     if(ypos>p[1] && ypos<p[1]+50) {
       yspeed +=randomSpeed;
     }

     if(ypos >= height){
       yspeed =-abs(randomSpeed);
     }
     if(ypos <= 0){
       yspeed = randomSpeed;
     }
     if(p[1] == 0)
     {
       yspeed = randomSpeed;
     }
     
     }}}
   
 }

 void displayFeather()
 {
   shape(featherSVG,xpos,ypos,thisScale,thisScale);
   //fill(#000000);
   //noStroke();
   //rect(xpos,ypos,10,10);
 }





}

public void stop(){
 m.stop();
 super.stop();
}



Re: Problems with slow rendering (JMyron)
Reply #1 - Feb 17th, 2010, 1:46pm
 
loadShape() in draw() loop. move it to setup().
Re: Problems with slow rendering (JMyron)
Reply #2 - Feb 18th, 2010, 3:47am
 
I moved that (which makes sense), but it's still running god-awful slow.
Re: Problems with slow rendering (JMyron)
Reply #3 - Feb 18th, 2010, 4:09am
 
what is feather.svg like? is it complicated? displaying 28*18 (>500) svgs is going to take some time, even without running the whole thing through globcenters afterwards.

some things just can't be done in realtime.
Re: Problems with slow rendering (JMyron)
Reply #4 - Feb 18th, 2010, 4:27am
 
its a tiny tiny basic vector, pretty much a solid.  I changed it to a rect of size 10, and it still is slow.
Re: Problems with slow rendering (JMyron)
Reply #5 - Feb 18th, 2010, 6:24am
 
ok, then try putting some debug in the code, around the various blocks, that reports how long that block took.

something like:

long start;

start = System.nanoTime();

// code being timed here

println("Identifier: " + (System.nanoTime() - start));

but i imagine it'll be the globCenter thing.
Re: Problems with slow rendering (JMyron)
Reply #6 - Mar 6th, 2010, 9:50pm
 
Could also be frameRate() -- that makes a big difference on the old clunker of a DELL 9100 I'm running processing on --  I have to run at 15fps if I want the 9100 to be able to follow my mouse around.
Page Index Toggle Pages: 1