How Do I Make the Objects Tween Based on Collision with Mouse?
in
Programming Questions
•
2 years ago
When I originally wrote this in Actionscript 3.0 that line of code was rather beautiful, now I'm wondering how to accomplish the same with Processing. I've come a long way with my first Processing Sketch, but I am up against a wall with figuring out how to make the objects move based on mouse input. I would like the dollar bills to translate to a new position over time (tween) on mouseover. I have the Tween library, but I plan on porting this sketch over to processing.js so I'm guessing that option is out. Am I correct that processing.js can't rely on external libraries? I was thinking a for loop that updates translation over time would work, but how do I write a conditional that asks if each objects area is equal to mouse position then tween?
DIE FLASH! DIE!
Electronic Artist
Los Angeles, CA
Los Angeles, CA
- /**
- * 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;
- void setup() {
- size(1000, 800);
- // The file "jelly.jpg" must be in the data folder
- // of the current sketch to load successfully
- a = loadImage("100-dollar-bill.jpg"); // Load the image into the program
- Display myDisplay = new Display();
- translate(width/2, height/2);
- fontA = loadFont("Georgia.vlw");
- // Set the font and its size (in units of pixels)
- textFont(fontA, 22);
- smooth();
- //noLoop(); // Makes draw() only run once
- } //end of setup
- void draw() {
- // text("Chasing the Almighty Dollar", 16, 740);
- }
- class Display {
- Bill[] billArray;
- Display() {
- billArray = new Bill[24]; //where 4 is the same number as the one in your for-loop
- build();
- }
- void build() {
- for ( int i = 0; i < 24; 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 {
- Bill(float ang, float x, float y) {
- float angle = ang;
- float imgPosX = x;
- float imgPosY = y;
- pushMatrix();
- translate(imgPosX,imgPosY);
- rotate(angle);
- translate(-a.width/2, -a.height/2);
- //translate((a.width/dolSize)/2, (a.height/dolSize)/2);
- //line(0, 0, width, 0);
- //line(0, 0, 0, height);
- //ellipse(0, 0, 30, 30);
- //ellipse((a.width/dolSize), 0, 30, 30);
- //ellipse(0, (a.height/dolSize), 30, 30);
- //ellipse((a.width/dolSize), (a.height/dolSize), 30, 30);
- stroke(0);
- fill(0);
- rect(0, 0, (a.width/dolSize)+1, (a.height/dolSize)+1);
- image(a, 0, 0, a.width/dolSize, a.height/dolSize);
- //ellipse((a.width/dolSize)/2,(a.height/dolSize)/2, 100, 100);
- popMatrix();
- }
- } //end Class Bill
- void mouseMoved() {
- println("MouseX =" + mouseX);
- println("MouseY =" + mouseY);
- } // end void MouseMoved
POP THIS IMAGE IN THE SAME LOCATION AS THE SKETCH:
1