Changing the size of a triangle depending on mouseY

Hey,

So I was trying to do a program that, among other things, changed the size of a triangle depending on how high the mouse was. What I wanted to do is start with the triangle at size 0 at a point and gradually make it bigger as I move my mouse downwards.

I came up with a solution, which is calculating a variable that goes from 0 to 1 depending on where the mouse was, and then multiplying that value to the number I added or subtracted to the mouse to make a coordinate for the triangle, here’s the code:

void setup()
{
  size(1530,800);
}

void draw()
{
 background(255,255,255);
 float postriangulo=((mouseY-600)/200);
 triangle(mouseX,(mouseY-(postriangulo*70)),(mouseX-(postriangulo*61)),(mouseY+(postriangulo*35)),(mouseX+(postriangulo*61)),(mouseY+(postriangulo*35)));
}

The problem is, everytime I execute it, the triangle just doesn’t show up

Edit: Forgot to say, this is part of a bigger code, and only works with the Y coordinates bigger than 600.
It is meant to go from 600 to 800, so the variable postriangulo goes from 0 at 600 to 1 at 800

1 Like

Use the map() function! If you want it to go from 0 at 600 to 1 at 800, then:

float postriangulo=map(mouseY,600,800,0,1);

2 Likes

Nice, it worked,
Thanks!