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 › taking input from other java class
Page Index Toggle Pages: 1
taking input from other java class (Read 470 times)
taking input from other java class
Mar 22nd, 2010, 9:03pm
 
Dear prople,
  i am new to processing. i am developing a java application and had decided to use processing to display the structure.

I want to know how is it possible to pass values into the processing program from other java classes.

Like in this case i want to pass the values of the number of circles in each column of the sketch  from a Main class which has the main function...

here is my code....

I need a way to set  to set ni,nh,no from outside...
also later i will be needing a way to pass a 1d array.
Am using netbeans as the ide.

import processing.core.*;


public class sketch_mar20b extends PApplet {


public void setup()
{
size(600,600) ;
}
 
public void draw()
{
 background(0,0,0);
 stroke(0,120,255,120) ;
 line(0,height/2,width,height/2);
 line(width/2,0,width/2,height);
 fill(0,255,248);
 getTheEllipses(2,2,1) ;
}

public void getTheEllipses(int ni,int nh,int no)
{
  anyEllipse(width/2,height,ni) ;
  anyEllipse(width,height,nh) ;
  anyEllipse(PApplet.parseInt(width/2*3),height,no) ;
}


public void anyEllipse(int w,int h,int n)
{
 int dN = PApplet.parseInt(h/(n+2));

 if(n%2!=0)
 {
    circle(w/2,h/2);

         for(int i=1;i<=PApplet.parseInt(n/2);i++){
         circle(w/2,(h/2)-(dN*i));
         circle(w/2,(h/2)+(dN*i));
         }
 }
 else
 {
   for(int i=1;i<n;i++)
   {
     if(i%2!=0)
     {
     circle(w/2,(h/2)-((dN/2)*i));
     circle(w/2,(h/2)+((dN/2)*i));
     }
   }
 }
}

public void circle(int x,int y)
{
 ellipse(x,y,20,20) ;
}

}
-----------------------------------------
import processing.core.PApplet;


public class Main {

    public static void main(String[] args ){

/* to get num of circles from user */

                       PApplet.main(new String[] { "--bgcolor=#ECE9D8",                                sketch_mar20b" });
  }
}

thanks...

Re: taking input from other java class
Reply #1 - Mar 23rd, 2010, 1:48am
 
I suggest to start by reading the Objects tutorial.
Page Index Toggle Pages: 1