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 › Problem ! cant display more than 1 object
Poll Poll
Question: Cant display more than 1 object

1    
  0 (0%)
2    
  0 (0%)




Total votes: 0
« Created by: Jorik on: May 7th, 2009, 4:31pm »

Page Index Toggle Pages: 1
Problem ! cant display more than 1 object (Read 682 times)
Problem ! cant display more than 1 object
May 7th, 2009, 4:31pm
 
Hi,

i cant find the error in the following program. I wrote a class and i want to creat 2 objects from this class that behave the same way but havent the same size an postiton.
Unfortunatly only one of the objects is displayed. I hope anyone can help me here and find the failure.

the program:


Zoog zoog1;
Zoog zoog2;

void setup(){
 size(400,400);
 smooth();

 zoog1 =  new Zoog(100,100,60,60,16,125);
 zoog2 = new Zoog (50,50,60,60,16,231);
 
}
void draw(){

 float kanne = constrain (mouseX/10,0,7);
 float nalos= zoog1.augenfarbe();

 zoog1.drawZoog(nalos);
 zoog2.drawZoog(nalos);
 zoog1.jiggleZoog(kanne);
 zoog2.jiggleZoog(kanne);
}

Re: Problem ! cant display more than 1 object
Reply #1 - May 7th, 2009, 4:31pm
 
and here the class:

class Zoog{

 float x;
 float y;
 float w;
 float h;
 int eyeSize;
 int farbe;
 
 Zoog(float tempX,float tempY, float tempW, float tempH, int tempEyeSize, int tempFarbe){
   x= tempX;
   y= tempY;
   w= tempW;
   h= tempH;
   farbe = tempFarbe;
   eyeSize= tempEyeSize;

 }

 void drawZoog(float eyeColor){
   background(255);

   ellipseMode(CENTER);
   rectMode(CENTER);

   for (float i=y+5; i<y+h; i+=10){
     stroke(0);
     line(x-20,i,x+20,i);
   }

   stroke(0);
   fill(0);
   rect(x,y,w/6,h*2);
 
   fill(farbe);
   ellipse(x,y-h/2,w,h);

   fill(eyeColor);
   ellipse(x-w/3,y-h/2,eyeSize,eyeSize*2);
   ellipse(x+w/3,y-h/2,eyeSize,eyeSize*2);

   stroke(0);
   line (x-w/12,y+h,x-w/4,y+h+10);
   line (x+w/12,y+h,x+w/4,y+h+10);  
 }

 void jiggleZoog(float speed){

   x=x+random(-1,1)*speed;
   y =y+random(-1,1)*speed;

   x=constrain(x,0,width);
   y=constrain(y,0,height);


 }

 float augenfarbe(){
 float d = dist(x,y,mouseX,mouseY);          
 

   return d;

}

}
Re: Problem ! cant display more than 1 object
Reply #2 - May 7th, 2009, 4:39pm
 
remove background(255) from the class and put it at the beginning of draw. you are not only drawing eyes you are drawing a background and overdraw the first Zoog
Re: Problem ! cant display more than 1 object
Reply #3 - May 7th, 2009, 6:41pm
 
thank you Smiley

this looping conditions are somethimes wired stuff for a beginner like me.
Page Index Toggle Pages: 1