Tweening Help
in
Programming Questions
•
1 year ago
Hello, all. I'm having trouble with some tweening that i'm trying to do.
My goal is to have random circles move across the screen. I want them to start at random locations, move across the screen, and end at a random location. The problem is I can't control the speed and the tweening like I want to. Could you guys help me at all? Thanks!
- float x;
- float y;
- float myX= 50;
- float myY=35;
- float easing =.1;
- float r=random(100);
- float damping = 0.09;
- void setup () {
- frameRate(60);
- noCursor();
- size (600, 600);
- smooth();
- ellipseMode(CENTER);
- }
- void draw() {
- background(51);
- myX=mouseX;
- float dx=myX -x;
- if (abs(dx) > 1) {
- x+=dx * easing;
- }
- myY=mouseY;
- float dy=myY -y;
- if (abs(dy) > 1) {
- y += dy * easing;
- }
- fill(65, 255, 41);
- ellipse(x, y, 33, 33);
- float startX = random(600); // random start X location
- float stopX = random(600); //random stop X location
- float startY = random(600); // random start Y location
- float stopY= random(600); // random stop Y location
- float x = startX; // sets up X coord
- float y =startY; // sets up y coord
- float step = .005; //line speed
- float pct = 0; // percent
- float badThingX=startX;
- float badThingY=startY;
- //end variables
- //constructor
- if (pct<1.0) {
- x = startX + ((stopX-startX)*pct);
- y=startY+((stopY-startY)*pct);
- pct += step;
- }
- fill(255,0,0);
- ellipse(badThingX,badThingY,33,33);
- float distanceToEachOther= sqrt(sq(myX-badThingX)+sq(myY-badThingY));
- if (distanceToEachOther <=33) {
- println("FAIL");
- }
- else {
- println("WIN");}
- }
1