Copyright covers original expression. If you wrote your own original computer program, whether open source or not, it is a copyrighted work, similar to a painting, novel or music recording.
Copyright protects expression, not ideas. If an idea is patented, then all expressions of that idea, whether or original or not, infringe on that patent, unless they are expressions by the patent holder or a licensee.
If an algorithm is patented, then any unlicensed third-party implementation of that algorithm infringes on the patent, even though, paradoxically, the developer maintains the copyright.
An idea which is not patented can be borrowed by anyone and expressed in their own work.
If you think you have an idea which is patentable, it behooves you to keep it a secret. If, prior to obtaining a patent, you publish an idea so that it passes into use, you may lose eligibility to have it patented, at least in some countries. For instance, take a look at this sciencemag.com article entitled "Patent First, Publish Later: How Not to Ruin Your Chances of Winning a Patent" which claims that:
"According to U.S. law, a patent cannot be obtained if an invention was previously known or used by other people in the U.S., or was already patented or published anywhere in the world. Furthermore, publicly using or selling an invention more than 1 year prior to filing a patent application completely bars you from ever winning a patent on that invention."