https://scratch.mit.edu/discuss/topic/133890/?page=171#post-8495952 に対しての回答
@milpoyxkさんのプログラムを参考にしました。