What changes do I need to make to my algorithm to make this scene from a different angle?
Can you try replacing the original condition i % j == 0 with the following conditions? They work for me.


For a perspective coming from the top right, (w-i) %j == 0  
For a perspective coming from the bottom left, i %(h-j) == 0  
For a perspective coming from the bottom right, (w-i) % (h-j) == 0  
For a perspective coming from the the top centre, (w/2-i) % j == 0