Click green flag for description. Please read full description.
Link to example project: https://scratch.mit.edu/projects/167234677/#player Feel free to use this algorithm in your projects. If you have any questions, please ask me in the comments.