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 & HelpSyntax Questions › give me some advice,pls
Page Index Toggle Pages: 1
give me some advice,pls (Read 636 times)
give me some advice,pls
Jul 25th, 2007, 5:26am
 
following are codes ,there are some thing wrong beyond my comprehension when I run it.help me pls.


Eye e[];

int num=5;

void setup()
{
 size(500, 500);
  for(int i=1;i<=num;i++){
    e[i]=new Eye(i*50,i*50,50);
}
}

void draw()
{
 background(102);
 for(int i=1;i<=num;i++){
 e[i].update(mouseX,mouseY);
 e[i].display();
 }
}

class Eye
{
 int ex, ey;
 int size;
 float angle = 0.0;
 
 Eye(int x, int y, int s) {
   ex = x;
   ey = y;
   size = s;
}

 void update(int mx, int my) {
   angle = atan2(my-ey, mx-ex);
 }
 
 void display() {
   pushMatrix();
   translate(ex, ey);
   fill(255);
   ellipse(0, 0, size, size);
   rotate(angle);
   fill(153);
   ellipse(size/4, 0, size/2, size/2);
   popMatrix();
 }
}
Re: give me some advice,pls
Reply #1 - Jul 25th, 2007, 7:25am
 
Code:
Eye e[];

int num=5;

void setup()
{
size(500, 500);
e=new Eye[num]; // need to say how long Eye[] actually is
for(int i=0;i<num;i++){ // Arrays start from 0, so you want from 0 to num-1 for num entries.
e[i]=new Eye(i*50,i*50,50);
}
}

void draw()
{
background(102);
for(int i=0;i<num;i++){ // again i=0; i<num
e[i].update(mouseX,mouseY);
e[i].display();
}
}

class Eye
{
int ex, ey;
int size;
float angle = 0.0;

Eye(int x, int y, int s) {
ex = x;
ey = y;
size = s;
}

void update(int mx, int my) {
angle = atan2(my-ey, mx-ex);
}

void display() {
pushMatrix();
translate(ex, ey);
fill(255);
ellipse(0, 0, size, size);
rotate(angle);
fill(153);
ellipse(size/4, 0, size/2, size/2);
popMatrix();
}
}
Re: give me some advice,pls
Reply #2 - Jul 25th, 2007, 9:15am
 
to JohnG:
thx very very much,I understand what you said.
Page Index Toggle Pages: 1