You forgot to format using ctrl-T in the IDE and then post using code tags. You have two sketches, so put each one in separate code tags.
Also we need a more detailed update than, "I didn't get the results I was expecting".
Your code is not self-explanatory. Could you please post a plain language explanation of how it works, or some pseudocode?