How to control DC motor forward and reverse with one potentiometer

the code I wrote will work.

Maybe, but it isn't an analogue solution, as requested in the original post (though what it is doing in this forum beats me XD )