punchik
Junior Member
Offline
Posts: 74
wierd behaivor
Apr 1st , 2006, 1:33pm
hello people, theres something wierd with some processing code i been working this afternoon maybe somebody can help me.... i dont know why when i run the exe file (exported application) it runs very slow, but when i run the code from the processing environment it runs fast... can anybody tell me what is happening? here is the code: int div = 20; int num = 10; float gX =10; float gY = 10; float grax =500; float gray = 500; Ball[] balls; void setup() { size(500,500); smooth(); framerate(60); reset(); } void draw() { background(141,63,158); if ( mousePressed == true ) { gX = 500; gY = 100; } for ( int i=0; i<num; i++ ) { balls[i].gravitate(gX, gY); // balls[i].repulse(); balls[i].move(); balls[i].display(); balls[i].tiempol(); } } void reset() { balls = new Ball[num]; for ( int i=0; i<num; i++ ) { balls[i] = new Ball(random(0,width), random(0,height),"A",grax,gray); } } class Ball { float vmax; float amax; float rmax; float x; float y; float vX; float vY; String type; int xo; int yo; int xxx; int yyy; float tiempo = 3000; int lastRun= 0; // lastRun=0; Ball(float X, float Y, String Type, float grax, float gray) { float xf=random(grax); float yf=random(gray); xxx= int(xf); yyy= int(yf); //print(x); type = Type; if ( type == "A" ) { vmax = 3; } else { vmax = 1; } amax = 0.4; rmax = 0.14; x = X; y = Y; vX = 0; vY = 0; } void tiempol(){ int m=millis(); // print(m); if(m>=(lastRun+3000)) { lastRun=m; tiempo= random(3000); // print(tiempo); float xf=random(500); float yf=random(500); xxx= int(xf); yyy= int(yf); } } void display() { if ( type == "A" ) { stroke(255,255,255); } else { stroke(0,0,0); } strokeWeight(vmax+1); point(x,y); strokeWeight(1); // line(x,y,x-2*vX,y-2*vY); } void gravitate(float gX, float gY) { // float xf=random(gX); // float yf=random(gY); // xo= int(xf); // yo= int(yf); // print(yo); float theta = atan((yyy-y)/(xxx-x)); float aX = abs(xxx-x)/(xxx-x)*amax*cos(theta)*abs(xxx-x)/1000; float aY = abs(yyy-y)/(yyy-y)*sqrt(pow(amax,2)-pow(aX,2))*abs(yyy-y)/1000; vX = aX + vX; vY = aY + vY; truncate(); } void truncate() { if ( sqrt(pow(vX,2)+pow(vY,2)) > vmax ) { float theta = atan(vY/vX); vX = abs(vX)/vX*vmax*cos(theta); vY = abs(vY)/vY*sqrt(pow(vmax,2)-pow(vX,2)); } } void move() { x = vX + x; y = vY + y; } }