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.
Page Index Toggle Pages: 1
Bird Help?? (Read 392 times)
Bird Help??
Nov 17th, 2009, 12:16am
 
Hello, I am trying to make a flying, somewhat glowing bird that will somehow react to a mouse click or keyboard. I don't really know how to apply either of these. Also, I wanted to add an image in the background, but where exactly in the code to I put the code for the image??
I'm very confused about this!
Here is what I have:

float ang = 0, ang2 = 0, ang3 = 0, ang4 = 0;
float px = 0, py = 0, pz = 0;
float flapSpeed = 0.2;

void setup(){
 size(640, 360, P3D);
 noStroke();
}

void draw(){
 background(0);
 lights();

 // Flight
 px = sin(radians(ang3)) * 170;
 py = cos(radians(ang3)) * 300;
 pz = sin(radians(ang4)) * 500;
 translate(width/2 + px, height/2 + py, -700+pz);
 rotateX(sin(radians(ang2)) * 120);
 rotateY(sin(radians(ang2)) * 50);
 rotateZ(sin(radians(ang2)) * 65);
 
 // Body
 fill(153);
 box(20, 100, 20);

 
 // Left wing
 fill(204);
 pushMatrix();
 rotateY(sin(radians(ang)) * -20);
 rect(-75, -50, 75, 100);
 popMatrix();

 // Right wing
 pushMatrix();
 rotateY(sin(radians(ang)) * 20);
 rect(0, -50, 75, 100);
 popMatrix();

 // Wing flap
 ang += flapSpeed;
 if (ang > 3) {
   flapSpeed *= -1;
 }
 if (ang < -3) {
   flapSpeed *= -1;
 }

 // Increment angles
 ang2 += 0.01;
 ang3 += 2.0;
 ang4 += 0.75;
}


...Just a basic bird. But I would like to change the background to an image and make the bird react somehow to the mouse. I am making this to go with "blackbird" the song.
If I could get help or suggestions, that would be absolutely wonderful!
thankyou!
Re: Bird Help??
Reply #1 - Nov 17th, 2009, 1:45am
 
First, the background image, it is easy: replace the background(0) call with an img() call. You must declare a PImage at global level, and load the image in setup().

Next, the user interaction. It isn't hard either. You have the mousePressed() and the keyPressed() functions (and similar) which are called automatically when user does the corresponding action. You can then set global variables according to the action (like recording the mouse click coordinates) and use them in draw().
Page Index Toggle Pages: 1