Increasing the size of an object made up of two triangles

Hi, I am relatively new to coding and I’ve encountered a small issue. I have diamond shape made up of two triangle shapes, I’ve turned the shape in to an object that includes x & y properties, I can move it round the screen no problem but when I try to increase the overall size of the shape by multiplication the points stretch across the screen in every direction.

is there anyway to increase the overall size of a triangle with a property instead of painstakingly altering every point?


1 Like

Look at scale() in the reference

1 Like

You can approach this problem in several ways:

  1. scale(), which scales everything drawn after it is called.
  2. PVector.mult() – if you store your points in PVectors, this will scale each point
  3. saving the points as individual x,y variables or float[] etc. and manipulating them directly.

However, a common thing if you are trying to scale up a group of points is to want the scaling be centered. So, you don’t want a triangle with one point at (0,0) – this causes the other two points to scale up, and the center of the triangle to shift. Instead, you want the triangle centered around 0,0. Then, when you scale the three points, they all scale equally and the center stays the same – this is what people usually want when they resize something.

1 Like