Writing music takes time, there are many ways a person can go about doing it, and there are a few different steps involved. Mood, setting, and choice of instrument can all affect greatly the sound of the song. Then, taking into account my lack of music theory, I'll just pay around on a guitar, experimenting with different tunings, chords, and rhythms until I hear something I like, and then expand on the idea.
Depending on a persons mood, the sound of the music they create fluctuates quite a bit. When happy, at least when I write, what I write tends to sound bright and upbeat, when sad though, it's usually the exact opposite. Where you write also can have an effect on the song. If you're in the corner of a crowded room with an acoustic guitar, filled with a lot of laughter and noise, if you manage to get any writing done at all, it will usually reflect on the atmosphere of the room. What you write may be very happy sounding if you're having a good time, but if you're counting the moments until you can get as far away as possible from wherever you are, that anger, boredom, or sadness will likely carry over into the song.
If a few different instruments are at your disposal, the first step in writing music is choosing which instrument you're going to write on, these can range anywhere from a guitar (my instrument of choice), to a flute, or piano. With a seemingly infinite number of ways to tune a guitar, from standard E-A-D-G-B-e, to more unusual tunings such as D-G-C-G-C-D. This tuning is what Jimmy Page used in 1973 to write Led Zeppelin's "Rain Song".
On a guitar at least, there are also a massive amount of chords that can be played, some even tying into, and being specific to certain tunings. Chords can range from simple three-note chords such as G, C, and D. To far more complex chord shapes such as the F#min6, or the Eb7sus. One of the most obvious instrument choice decisions in writing music, especially in writing with a guitar is whether you're going to write on an electric or acoustic guitar. Acoustic guitars have a very stripped down, raw sound. While electric guitars are louder, and can be set up with many different sound effects projected through the amplifier through the use of foot pedals. With practice, creativity, and the magic of studio recording, both types of guitars can be used in the same song at different times.
I don't do a whole lot more thinking at first, once I've chosen a guitar and a tuning. I have almost no music compositional knowledge. Once I stumble upon a chord, guitar riff, or a progression of a couple different chords, I'll take the idea and toy with it until I get it sounding like however I hear it in my head. Then I just play around the neck of the guitar until I find something else I like the sound of that blends well with what I'd originally started with. Once I have a few guitar riffs or chord progressions (and a guitar solo if I'm having a good day), I write out the arrangement they'll go in for the song, and how many times each part will be played.
I don't write a lot of lyrics, I mainly write instrumental music. Once I've completed writing a song, and I decide I want to remember it, I write out tablature. Tablature is a far more simplistic version of sheet music. It doesn't require the ability to read music at all. If you know the names of the strings (E-A-D-G-B-e, D-G-C-G-C-D, etc. etc), and know what fret you're putting your finger on to play a certain note, then you can read tablature easily with a bit of practice. I tab out the song and save it as a text document on my computer, thus ending my songwriting process.
Writing music can be a lot of fun with a bit of creativity and determination. Inspiration can come from anywhere. Maybe you hum a melody walking down the sidewalk? Perhaps you hear a noise in your everyday life that you find has a good rhythm? (These new heavy metal bands must be around jackhammers all the time). An idea for a song can come from anything. It's up to the musician to turn an idea into their next sonic masterpiece.