# Changing the size of a triangle depending on mouseY

**URL:** <https://discourse.processing.org/t/changing-the-size-of-a-triangle-depending-on-mousey/18841>\
**Category:** Coding Questions\
**Created:** [March 20, 2020, 2:20pm UTC](https://discourse.processing.org/t/changing-the-size-of-a-triangle-depending-on-mousey/18841 "2020-03-20T14:20:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PixelVolt38](https://avatars.discourse-cdn.com/v4/letter/p/3e96dc/32.png) [@PixelVolt38](https://discourse.processing.org/u/PixelVolt38)\
**Post date:** [March 20, 2020, 2:20pm UTC](https://discourse.processing.org/t/changing-the-size-of-a-triangle-depending-on-mousey/18841/1 "2020-03-20T14:20:12Z")

</div>

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:

```auto
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

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [March 20, 2020, 3:01pm UTC](https://discourse.processing.org/t/changing-the-size-of-a-triangle-depending-on-mousey/18841/2 "2020-03-20T15:01:28Z")

</div>

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);`

---

<div class="post-metadata">

**Author:** ![PixelVolt38](https://avatars.discourse-cdn.com/v4/letter/p/3e96dc/32.png) [@PixelVolt38](https://discourse.processing.org/u/PixelVolt38)\
**Post date:** [March 20, 2020, 3:29pm UTC](https://discourse.processing.org/t/changing-the-size-of-a-triangle-depending-on-mousey/18841/3 "2020-03-20T15:29:02Z")

</div>

Nice, it worked,  
Thanks!
