I am completely lost - changing size according to Mouse position

Hello, I need some serious help…

I want my tennis racquet in this code to change size according to the mouse position. When my mouse is at the bottom of the canvas, I want it to be double the size and when the mouse is at the top of the canvas I want it to be half the size.

Can anybody point me in the right direction?

Here is my code…

/**************
 * INFO
 **************/

//declare some constants
float RACQUET_HEIGHT = mouseY; //this controls the length of the tennis racquet shaft (0 is default)
float RACQUET_X = 250; //move the raquet left ot right
float RACQUET_Y = 250; //move the raquet up or down
 
void setup(){
  //set canvas size
  size (500, 500);
}

void draw(){
  background(250);
  
if (mouseY == height){
    RACQUET_HEIGHT = 50;}
  
		//draw the racquet shaft
  fill(0, 0, 255); //the racquet shat will be the colour blue
  rect(RACQUET_X-10, RACQUET_Y-RACQUET_HEIGHT, 20, RACQUET_HEIGHT+100); //this is the middle section that attatches the face to the handle

  //complete the shaft by adding the handle
  fill(150); //set the colour to light grey
  rect(RACQUET_X-15, RACQUET_Y+100, 30, 75); //this is the actual handle
  
  //the grip tape on the handle will be made of three triangles
  fill (100); //set the colour to dark grey
  triangle(RACQUET_X-15, RACQUET_Y+100, RACQUET_X+15, RACQUET_Y+125, RACQUET_X-15, RACQUET_Y+125); //represents the grip tape on the handle
  triangle(RACQUET_X-15, RACQUET_Y+125, RACQUET_X+15, RACQUET_Y+150, RACQUET_X-15, RACQUET_Y+150); //represents the grip tape on the handle
  triangle(RACQUET_X-15, RACQUET_Y+150, RACQUET_X+15, RACQUET_Y+175, RACQUET_X-15, RACQUET_Y+175); //represents the grip tape on the handle
  
  //draw the racquet face last so that it overlaps the shaft
  fill(0,0,255); //the colour blue will be used for the outside portion of the face
  ellipse(RACQUET_X, RACQUET_Y-75-RACQUET_HEIGHT, 125, 175); //this is the outside of the portion
  fill(255); //the colour white will be used for the inner section of the racquet face
  ellipse(RACQUET_X, RACQUET_Y-75-RACQUET_HEIGHT, 115, 165); //this represents the strings of the racquet face
}
1 Like
//declare some constants
float RACQUET_HEIGHT = mouseY; //this controls the length of the tennis racquet shaft (0 is default)
float RACQUET_X = 250; //move the raquet left ot right
float RACQUET_Y = 250; //move the raquet up or down

void setup() {
  //set canvas size
  size (500, 500);
}

void draw() {
  background(250);

  scale(map(mouseY,0,height,.5,2));

  //draw the racquet shaft
  fill(0, 0, 255); //the racquet shat will be the colour blue
  rect(RACQUET_X-10, RACQUET_Y-RACQUET_HEIGHT, 20, RACQUET_HEIGHT+100); //this is the middle section that attatches the face to the handle

  //complete the shaft by adding the handle
  fill(150); //set the colour to light grey
  rect(RACQUET_X-15, RACQUET_Y+100, 30, 75); //this is the actual handle

  //the grip tape on the handle will be made of three triangles
  fill (100); //set the colour to dark grey
  triangle(RACQUET_X-15, RACQUET_Y+100, RACQUET_X+15, RACQUET_Y+125, RACQUET_X-15, RACQUET_Y+125); //represents the grip tape on the handle
  triangle(RACQUET_X-15, RACQUET_Y+125, RACQUET_X+15, RACQUET_Y+150, RACQUET_X-15, RACQUET_Y+150); //represents the grip tape on the handle
  triangle(RACQUET_X-15, RACQUET_Y+150, RACQUET_X+15, RACQUET_Y+175, RACQUET_X-15, RACQUET_Y+175); //represents the grip tape on the handle

  //draw the racquet face last so that it overlaps the shaft
  fill(0, 0, 255); //the colour blue will be used for the outside portion of the face
  ellipse(RACQUET_X, RACQUET_Y-75-RACQUET_HEIGHT, 125, 175); //this is the outside of the portion
  fill(255); //the colour white will be used for the inner section of the racquet face
  ellipse(RACQUET_X, RACQUET_Y-75-RACQUET_HEIGHT, 115, 165); //this represents the strings of the racquet face
}

1 Like