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?
Look at scale() in the reference
You can approach this problem in several ways:
- scale(), which scales everything drawn after it is called.
- PVector.mult() – if you store your points in PVectors, this will scale each point
- 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.