Gregory - H

By Gregory Batha
//exercise H //Greg Batha DESMA 28 Interactivity //the gray square is a curious cat and the cursor is an insect //when the cat sees the insect, it becomes curious and //comes to check it out, but gets more cautious as it approaches //if the bug inflates and deflates rapidly, it scares the cat away //if the bug just inflates, the cat becomes more cautious float x = 0.0; float y = 0.0; float targetX; float targetY; float easing = 0.003; float speed = 0.0; //cursor size variable int cursorWidth; void setup(){ size(400, 400); smooth(); fill(150); noStroke(); //more about the cursor cursorWidth = 10; noCursor(); } void draw(){ background(0); //square's target position targetX = mouseX; targetY = mouseY; //distance from position and target float dx = targetX - x; float dy = targetY - y; //if mouse is too far away, square's //easing becomes slower if(dist(mouseX, mouseY, x, y) < 300){ //assures efficiency by stopping the square //when it reaches its destination if(abs(dx) > 1.0){ x += (targetX - x) * easing; } if(abs(dy) > 1.0){ y += (targetY - y) * easing; } } else{ //assures efficiency by stopping the square //when it reaches its destination easing = 0.0005; if(abs(dx) > 1.0){ x += (targetX - x) * easing; } if(abs(dy) > 1.0){ y += (targetY - y) * easing; } } rect(x-20, y-20, 40, 40); ellipse(mouseX, mouseY, cursorWidth, cursorWidth); } //changes the easing depending on the speed of the mouse void mouseMoved(){ speed += (dist(pmouseX, pmouseY, mouseX, mouseY) - speed) * easing; easing = 1 / (speed*10); //makes sure lazy square can't move too fast if(easing > 0.01){ easing = 0.01; } println(easing); } //when the user releases the mouse, easing goes back to 0.005 void mouseReleased(){ cursorWidth -= 5; } void mouseDragged(){ //distance from position and target float dx = targetX - x; float dy = targetY - y; //if the user holds the mouse, //the square eases very slowly if(mousePressed == true){ easing = 0.001; if(abs(dx) > 1.0){ x += (targetX - x) * easing; } if(abs(dy) > 1.0){ y += (targetY - y) * easing; } rect(x-20, y-20, 40, 40); } } void mousePressed(){ easing -= 0.001; cursorWidth += 5; }

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*