Problem with NApplet ..
in
Contributed Library Questions
•
2 years ago
I want to run my processing sketch into another sketch.I used NApplet for that.But when I pasted my code in the NApplet following exception occured :
java.lang.RuntimeException: Too many calls to pushMatrix().
at processing.core.PGraphics2D.pushMatrix(Unknown Source)
at processing.core.PApplet.pushMatrix(Unknown Source)
at napplet.NAppletManager.draw(Unknown Source)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at processing.core.PApplet$RegisteredMethods.handle(Unknown Source)
at processing.core.PApplet$RegisteredMethods.handle(Unknown Source)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:619)
and the code is :
java.lang.RuntimeException: Too many calls to pushMatrix().
at processing.core.PGraphics2D.pushMatrix(Unknown Source)
at processing.core.PApplet.pushMatrix(Unknown Source)
at napplet.NAppletManager.draw(Unknown Source)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at processing.core.PApplet$RegisteredMethods.handle(Unknown Source)
at processing.core.PApplet$RegisteredMethods.handle(Unknown Source)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:619)
and the code is :
- import napplet.*;
- NAppletManager nappletManager;
- int App_status;
- String sketch;
- void setup()
- {
- size(500, 500,P2D);
- App_status =1;
- sketch = "MouseFollow";
- nappletManager = new NAppletManager(this);
- }
- void draw()
- {
- background(50);
- stroke(255);
- fill(255);
- if(App_status ==1)
- sketch = "MouseFollow";
- else
- sketch = "try_app";
- }
- void mousePressed()
- {
- if(App_status ==1)
- App_status =2;
- else
- App_status =1;
- nappletManager.createNApplet(sketch, 25, 200);
- }
- public class MouseFollow extends NApplet
- {
- import TUIO.*;
- int num = 200; //no of worms..
- float r;
- TuioProcessing tuioClient;
- worm[] worms = new worm[num];
- float X1,Y1 ;
- PImage bg;
- boolean touchDown=false,touchRemove=false,init=true,flag;
- PImage img;
- int q =1000;
- void setup()
- {
- size(screen.width,screen.height);
- smooth();
- img = loadImage("6.jpg");
- img.resize(width,height);
- frameRate(60);
- background(img);
- for(int i=0;i<worms.length;i++)
- {
- worms[i] = new worm(new PVector(random(0,width),random(0,height)),color(random(0,255),random(0,255),random(0,255)));
- }
- tuioClient = new TuioProcessing(this);
- frameRate(60);
- }
- void draw()
- {
- noStroke();
- background(img);
- Vector tuioCurList = tuioClient.getTuioCursors();
- float X=0,Y=0;
- if(tuioCurList.size() ==0)
- {
- touchDown =false;
- for(int j=0 ; j<worms.length ; j++)
- {
- worms[j].forces(1,1,true);
- worms[j].display();
- }
- }
- else
- {
- for(int j=0 ; j<worms.length ; j++)
- {
- worms[j].processed = false;
- for(int i=0 ; i<tuioCurList.size() ;i++)
- {
- touchDown = true;
- TuioCursor tcur = (TuioCursor)tuioCurList.elementAt(i);
- X = tcur.getScreenX(width);
- Y = tcur.getScreenY(height);
- boolean done =false;
- float mdist = dist(X, Y, worms[j].loc.x, worms[j].loc.y);
- if (mdist < 100)
- {
- worms[j].forces(X,Y,true);
- worms[j].processed = true;
- break;
- }
- }
- }
- for(int j=0 ; j<worms.length ; j++)
- {
- if(worms[j].processed == false)
- worms[j].forces(X,Y,false);
- worms[j].display();
- }
- }
- }
- class worm
- {
- PVector loc;
- PVector preLoc,vec;
- PVector acc,vel;
- int wcol;
- int velocityLim =15;
- float angle,tv;
- float speed =.6;
- boolean processed =false;
- int walpha ;
- int wsize;
- worm(PVector _loc,int _col )
- {
- loc = _loc.get();
- preLoc = new PVector(loc.x-6,loc.y-6);
- vel = new PVector(0,0);
- acc = new PVector(0,0);
- int j = (int)random(0,4);
- if(j ==1)
- _col = color(5,26,85);
- else if(j ==2)
- _col = color(211,55,131);
- else
- _col = color(241,250,13);
- wcol = _col;
- walpha = 255;//(int)random(150,255);
- wsize = (int) random(5,7);
- angle = random(0,2*PI);
- }
- void display()
- {
- stroke(255);
- PVector pre=new PVector();
- pre.x = preLoc.x;
- pre.y = preLoc.y;
- PVector curr = new PVector(loc.x,loc.y);
- float slope = atan2((loc.y-preLoc.y),(loc.x-preLoc.x));
- for (int i = 1; i < wsize; i++)
- {
- strokeWeight(sq(wsize - i) / (wsize-2));
- stroke(wcol,walpha);
- line(curr.x,curr.y,pre.x,pre.y);
- curr.x = pre.x;
- curr.y = pre.y;
- slope -=radians(tv+1);
- pre.x = pre.x -5* cos(slope);
- pre.y = pre.y -5* sin(slope);
- }
- }
- void bounds()
- {
- if(loc.y>height || loc.y<0)
- r = random(-3,-1);
- if(loc.x>width || loc.x<0)
- r = random(-3,-1);
- }
- void forces(float tx,float ty,boolean attract)
- {
- flag =false;
- float theta = atan2((loc.y-ty),(loc.x-tx));
- preLoc.x = loc.x;
- preLoc.y = loc.y;
- if(touchDown)
- {
- if(attract ==true)
- {
- flag=true;
- loc.x = loc.x-10*cos(theta);
- loc.y = loc.y-10*sin(theta);
- }
- }
- if(flag == false)
- {
- if(tv >=1.5)
- tv=0;
- tv += 0.3 * (random(10) - random(10)) / 10.0;
- // tv += 0.5*random(2);
- angle += tv;
- loc.x+=speed;
- loc.y+=speed;
- loc.x += 10*cos(radians(angle));
- loc.y += 10*sin(radians(angle));
- //boundory check...
- if(loc.x<0 )
- {
- loc.x = width-20;
- preLoc.x = width-16;
- }
- else if(loc.x >width)
- {
- loc.x =20;
- preLoc.x = 16;
- }
- else if(loc.y<0)
- {
- loc.y = height-20;
- preLoc.y =height-16;
- }
- else if(loc.y >width)
- {
- loc.y =20;
- preLoc.y = 16;
- }
- }
- }
- }
- // called when an object is added to the scene
- void addTuioObject(TuioObject tobj)
- {
- }
- // called when an object is removed from the scene
- void removeTuioObject(TuioObject tobj)
- {
- }
- // called when an object is moved
- void updateTuioObject (TuioObject tobj)
- {
- }
- // called when a cursor is added to the scene
- void addTuioCursor(TuioCursor tcur)
- {
- println("X,Y:"+tcur.getScreenX(width)+ " "+tcur.getScreenY(height));
- touchDown=true;
- touchRemove=false;
- init = false;
- X1 = tcur.getScreenX(width);
- Y1 = tcur.getScreenY(height);
- }
- // called when a cursor is moved
- void updateTuioCursor (TuioCursor tcur)
- {
- }
- // called when a cursor is removed from the scene
- void removeTuioCursor(TuioCursor tcur)
- {
- touchRemove =true;
- Vector tuioCurList = tuioClient.getTuioCursors();
- if(tuioCurList.size() ==0)
- touchDown=false;
- }
- // called after each message bundle
- // representing the end of an image frame
- void refresh(TuioTime bundleTime) {
- redraw();
- }
- }
- public class try_app extends NApplet
- {
- int x, y;
- void setup() {
- size(200, 200);
- x = width/2;
- y = height/2;
- }
- void draw()
- {
- println("Mouse2");
- background(255,0,0);
- fill(0,255,0);
- ellipse(mouseX,mouseY,10,10);
- }
- }
1