Ok, great suggestions. I've reposted the code below cleaned up a bit. You are right, I was using classes where functions are more appropriate. What this code does is build a variable number of dollar bills onto the canvas. Each dollar bill is constructed in the Bill Class, which uses the image included in my original post. Every new Bill is placed in an Array. I used this method so I could hopefully call the array and in turn manipulate each Bill. This is where I am at a dead end. I do not know how to update each Bill after it is drawn. Basically, when someone hovers over a dollar bill it should tween to a new x and y position. The Easing Example is great, I just dont know how to apply that example to an object. Any help is greatly appreciated.
In Actionscript 3.0, you can add an event listener to a called object and then perform a function in the event that listener is triggered. This is what I meant by the one line of code.
This is the ActionScript 3.0 I basically want to translate to Processing but cant figure out how.
dol.addEventListener(MouseEvent.MOUSE_OVER, flyAway); // startup Interaction
}
public function flyAway(evt:MouseEvent): void {
trace ("move!");
var subX:uint = 0;
var subY:uint = 0;
newX = Math.random() * 850;
newY = Math.random() * 500;
trace("NewX + Y:");
trace(newX, newY);
var dolXTween:Tween = new Tween(dol, "x", Strong.easeOut, xPos, newX, 5, true);
xPos = newX;
var dolYTween:Tween = new Tween(dol, "y", Strong.easeOut, yPos, newY, 5, true);
yPos = newY;
var myTweenRotation1:Tween = new Tween(dol, "rotation", Strong.easeOut, rotate, Math.random()*365, Math.random()*2, true);
}
Thats the Actionscript, here's the new Processing Code without the described functionality I'm looking for, commented where I'm stuck:
- /**
- * Chasing the Almighty Dollar
- *
- * Dollar Bills are Displayed on the Canvas and the User Can try to Grab Them, But When They do The Bills Just Fly Away
- * by Steve Belovarich
- * To view Steve's Electronic Artwork, visit http://installationspace.com
- */
-
- PFont fontA;
- PImage a; // Declare variable "a" of type PImage
- int dolSize = 4;
- float angle = 0;
- float imgPosX = 0;
- float imgPosY = 0;
- int billNumber = 24;
- Bill[] billArray;
-
-
- void setup() {
- size(1000, 800);
-
- a = loadImage("100-dollar-bill.jpg"); // Load the image into the program
-
- fontA = loadFont("Georgia.vlw");
-
- // Set the font and its size (in units of pixels)
- textFont(fontA, 22);
-
- display(); // Displays the billNumber of Bills onto the Canvas
-
- smooth();
- //noLoop(); // Makes draw() only run once
- } //end of setup
- void draw() {
-
-
-
- for ( int i = 0; i < billNumber; i++ ) {
- // How Do I Find if the Mouse is Hovering Over billArray[1], billArray[2], etc? I assume this would call another function
- // How do I update an existing Bills position?
-
- }
-
- text("Chasing the Almighty Dollar", 16, 740);
- }
-
- void display() { // Creates an Array of Bills and Builds Them
- billArray = new Bill[billNumber]; //where the number is the same number as the one in your for-loop
- build();
- }
- void build() { // Feeds the variables for Each Bill into the Bill Class and Assigns a new Bill to a member of the billArray
- for ( int i = 0; i < billNumber; i++ ) {
-
- float rotin = random(PI);
- float xin = random(100,width-100);
- float yin = random(100,height-100);
-
- billArray[i] = new Bill(rotin,xin,yin);
-
- }
- }
-
- class Bill { // The Bill Class, Constructs Each Bill
-
- Bill(float ang, float x, float y) {
-
- angle = ang;
- imgPosX = x;
- imgPosY = y;
-
- pushMatrix();
- translate(imgPosX,imgPosY);
- rotate(angle);
- translate(-a.width/2, -a.height/2);
- stroke(0);
- fill(0);
- rect(imgPosX, imgPosY, (a.width/dolSize)+1, (a.height/dolSize)+1);
- image(a, imgPosX, imgPosY, a.width/dolSize, a.height/dolSize);
- popMatrix();
-
- }
- } //end Class Bill