Can I use 12V voltage regulator and a variable 0 to 30V DC power supply to control my 12V DC motor speed?
(source: robotroom.com)
Here is a simple example of how to drive DC motor with Transistor and PWN.
The diode is to protect the circuit while the motor is free spinning and to stop fail gating the transistor.
The resistor is protection for the pulse generator i.e. micro controller or 555 chip or the many other ways to make PWN signal.