In a previous post I discussed my problem with changing the direction of objects in processing. I have since worked out this problem. The solution was actually quite simple once I found out what to do. To work this out I looked on processing.org and used this example to work out what I needed to do to achieve my intended outcome.
Firstly I had to create another variable for the velocity (in this example adirection etc). The reason for this is that the other variables are for the position of the points, so it makes it easier to have two different variables for both the position and the velocity. Secondly when changing directions I had to subtract the amount from the current direction of the shape, so for example if a point is travelling down by 1 pixel, to make it go up it has to be set to the value of -1 (0 makes the object inanimate), but also if one point is travelling down by 1, if you want another point to travel up instead of it being -1, (as I had previously thought) it has to be -2 to compensate for the current velocity of the centre point (adding the value -1 means the point will remain static).
What I discovered through experimenting to try and get the speed of the points right was that the previous movement of the shapes had to be taken into consideration when trying to make the points move at the same speed when changing direction. This is something I hadn’t previously conceived as being a problem and I wouldn’t have worked this out if I hadn’t have asked “How do I get each point to travel in opposite directions from one another at the same speed?” I found that having a clear intention of what I wanted to achieve was useful because in order for me to do it I had to overcome my unfamiliarity with programming and I realised that my speculation on how I would achieve it was different from how processing actually works. This is useful because it’s helping me to become more familiar with computer logic and realise that sometimes programming does not work the way I expect. It has also further cemented the fact that persistence is the key to solving problems.
See the output of the above code here.