Taken from https://js13kgames.com/games/re-wire/index.html