Developing a melody

Writing a melody feels like magic at times. However, many melodies simply take a motif and then use motivic variations to make it into something larger, like a phrase.