I'm independently developing a physics-based game using HTML5 canvas and JavaScript; I've used no external code at all (including physics or game engines), and my code is about 5000 lines in length. The development is almost complete, and now I want to release it.

I am planning to release the game as a paid app on the Chrome, Android, and Apple app stores, but I also want to release the code under an open source license - one which allows free reading and gleaning of ideas from my code, but does not allow more than a couple lines to be copied. Basically I want people who know where to look and how to use to find free code, and the general public to buy it, while preventing piracy or the development of a near copy.

This question came from our site for professional and enthusiast programmers.

7

Note that "does not allow more than a couple lines to be copied" automatically means that your software will not be open source.. All OSI-approved licenses (which is pretty much what "open source" means) require that the code may be re-used. Of course you can license it exactly the way you want, but please avoid using the phrase "open source" for such a license, it would only lead to confusion.
–
Joachim SauerFeb 22 '12 at 7:51

allows free reading and gleaning of ideas from my code, but does not allow more than a couple lines to be copied. Basically I want people who know where to look and how to use to find free code, and the general public to buy it, while preventing piracy or the development of a near copy."

... does not qualify as "open source" according to the OSI definition, violating the "free distribution" clause.

So I think the answer to your question is that what you ask is not possible, but you could have a liberal commercial license. Check out Microsoft's Shared Source licensing as a model, specifically Microsoft Reference Source License (Ms-RSL).

If you're concerned about protecting the code (legally), you should contact an attorney to craft a license that meets your somewhat non-typical needs, to make certain your application and code is properly protected. Creative Commons as a commenter above mentioned, isn't a good fit for software. If you feel like a CC license is right, you need to read the details of the license carefully and understand it. Don't rely only on the summaries provided.

Better though, I'd suggest that instead of (just) doing that, you'd consider creating a blog/web site that discusses the more interesting points of what you've done and why you think they were novel or interesting. I'd read it (as would likely others), whereas I wouldn't think to try to dive through your ideally minimized JavaScript code.