Today I added all my towers to processing (although these are just test images) to see how it would work. I also managed to get different objects moving at different speeds and moving up and down depending on the colours of specific pixels that the camera is capturing.
I did this by progressing from my previous post where I discussed how I got a square to move up and down depending on the colour value of a single pixel. But this time I created new color variables and assigned them different rgb values. I then used separate if statements for different images.
As you can see from this video the square is moving up at a different pace to the other towers and sometimes when it moves down the towers continue to move upwards.
These are the global variables at the top of the document which set the colours and starting y positions of the towers and rectangle.
This is a function called grabPixel which contains all of the towers (the function gets called in the draw section).
These are the if and else statements that make the images move upwards or downwards depending on if the rgb value the camera is picking up is greater or less than the rgb value declared at the start of the document.
The problem with this is that I will have to create an if statement for each image and assign each image slightly different colours to make the towers move up and down at different times, this can probably be done easier by creating classes and using object orientated programming like I explored in this post. However because I’ve set the rgb value to the colours of the background of my room the idea will probably not work as effectively in the foyer of Weymouth house (for example) because the colours in the background will be different to where I am doing the testing. One way I would be able to overcome this is by having something in the backround, such as a white sheet, so the value of the background is always the same, though this isn’t that suitable for a location such as Weymouth house.
Another problem I have is making sure that the towers don’t go too high so that their height exceeds the rectangle that is ‘in front’ of them, as you can see from the video I just showed the towers continue to rise and there is no point in which they stop, I have tried to resolve this by creating another if statement which states that when the int move is equal to 200 then add 1 pixel instead of take away one pixel, which makes it not go passed 200 pixels down from 0 on the y axis.