A melody is a line of notes heard as one shape, and much of its effect comes from expectation. A listener who has grown up on a repertoire half-knows which note comes next, and feels it when the melody agrees or departs. Draw a melody on the grid, read its contour and its interval profile, and then compare it with what a small corpus of German folksongs would have predicted at every step.
Things to try: draw a melody that is all leaps and watch the surprise climb, then smooth it into steps and watch it fall. Make a melody that avoids the tonic, or ends on the note just above it, and feel the lack of closure; then let the last note land on the tonic and hold it. Place any note and look at the bars: the corpus most often predicts a repeat or a step, and after the leading note it predicts the tonic strongly. Play the game in another key and notice that the predictions follow the tonic, because the model, like a listener, hears relative pitch.