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 › Why isn't this working
Page Index Toggle Pages: 1
Why isn't this working? (Read 856 times)
Why isn't this working?
Nov 23rd, 2009, 9:01pm
 
I have this code for a flock of birds and it won't work. Is something typed in wrong?
Here's the code:

class Bird extends Particle {
 float birdSize = 5.0;
 int currentFrame = int(random(0, birdImg.length));

 int frameCounter = currentFrame;
 float headAngle, colorR, colorG, colorB, tcR, tcG, tcB, curR, curG, curB;
 int birdNum, shapeNum;
 color birdColor;
 float colorSpd = 0.01;

 Bird(float ix, float iy, float spd, int n) {
   super(ix, iy, spd);
   birdNum = n;
   shapeNum = birdNum%numBirdShapes;
   colorR = min(random(144, birdNum%255), 255);  // Create random colors
   colorG = min(random(birdNum%144, 255), 255);
   colorB = min(random(144, 255), 255);
   tcR = colorR;
   tcG = colorG;
   tcB = colorB;
   curR = colorR;
   curG = colorG;
   curB = colorB;
   birdColor = color(colorR, colorG, colorB);
 }

 void update() {
   super.update();
   headAngle = atan2(dy, dx);        // Make 'heads' follow the cursor
 }

 void display() {
   currentFrame = (frameCounter/4)%numBirdImages;  // Create looping animation
   frameCounter++;
   pushMatrix();
   translate(x, y);
   rotate(headAngle);
   if (showSkin==1) {                  // Skin 1: PImage
     if (xDir > 0) {
       image(birdImg[currentFrame], 0, 0);  // Draw images
     }
     else {
       pushMatrix();
       scale(1.0, -1.0);
       image(birdImg[currentFrame], 0, -birdImg[currentFrame].height); // Draw reflected images
       popMatrix();
     }
   }
   else if (showSkin==2) {            // Skin 2: PShape
     pushMatrix();
     scale(birdSize/min(dist(x, y, mouseX, mouseY)+1, 10));
     rotate(-HALF_PI);
     shape(birdShape[shapeNum], 0, 0);// Draw shapes
     popMatrix();
   }
   else {                             // Skin 3: drawing
     scale(birdSize);
     rotate(HALF_PI);
     if (mousePressed) {
       tcR = 255 - min(dist(x, y, mouseX, mouseY), 255);   // Make birds red
       tcG = 0;
       tcB = 0;
     }
     else {
       tcR = colorR;     // Reset to previous color
       tcG = colorG;
       tcB = colorB;
     }
     curR += (tcR - curR)*colorSpd;
     curG += (tcG - curG)*colorSpd;
     curB += (tcB - curB)*colorSpd;
     birdColor = color(curR, curG, curB);
     fill(birdColor, 204);
     rect(0, 0, 5, 5);                // Draw birds
   }
   popMatrix();
 }
}




Re: Why isn't this working?
Reply #1 - Nov 23rd, 2009, 10:09pm
 
What "doesn't work"? Doesn't compile? Do you have an error message? Which one? Where?
You provide code we cannot run, and it is a bit too long and complex to be scrutinized for logic errors...
Re: Why isn't this working?
Reply #2 - Nov 23rd, 2009, 10:15pm
 
It says it "cannot find a type or class labeled as 'Particle'"
Re: Why isn't this working?
Reply #3 - Nov 23rd, 2009, 10:18pm
 
so you extend a class called Particle. do you have one ?
Re: Why isn't this working?
Reply #4 - Nov 23rd, 2009, 10:19pm
 
no,
could you perhaps tell me how to do that?
Thanks
Re: Why isn't this working?
Reply #5 - Nov 24th, 2009, 1:56am
 
Perhaps start by saying where you got this code? I suppose the missing class is there as well.
Re: Why isn't this working?
Reply #6 - Nov 24th, 2009, 3:29am
 
is from here

http://www.openprocessing.org/visuals/?visualID=5245

you need the code from the other two tabs as well.

you also need to credit casper schipper as it's his code.
Page Index Toggle Pages: 1