Used p5py to show how a laser works

I used the p5py package to explain and simulate how a laser obtains population inversion. Article is here on medium.

5 Likes

Thanks for sharing! I’m a big fan of these visual-explanation-type of articles, with animated (and sometimes interactive elements) interspersed among the text. Great to see somebody using Python+Processing for this.

Thanks glad you liked it @tabreturn

Great article! Was it a lot of work to render those gifs?

Some of them seem like the animations I see people using to encourage social distancing.

Great article! Was it a lot of work to render those gifs?

Thank you (: And no it was easy - I just implemented a make-gif function. Then I wrote the article in markdown which medium could import fro github.

Some of them seem like the animations I see people using to encourage social distancing.

Ah yeah now that you say it - it do. I remember those (:

Great article @renec112! I have a question. What is the difference between p5py and processing.py?

Thank you very much @edwin_isensee.

I’m not 100% but I think p5py is the only actual native python build of processing. Proccesing.py only runs an old python version and will have to run on the native editor only. You cannot pip install Proccesing.py as a normal python package, because it isn’t one.

@jeremydouglass is an expert on this one, pelase corrcet me if I’m wrong :smiley:

1 Like

@renec112 – that is correct. To provide a bit more detail:

Processing.py (Python mode) allows you to write Python2 syntax, and then run it as a Java program on the JVM (using Jython). This means that Processing.py is able to access Processing (Java) libraries directly, as well as non-CPython Python2 libraries (it cannot run most compiled libraries, although that might change in the future). It is mature – the API is fully covered and it has been used for years.

On the other hand, p5py is Python 3 running on python3. This means that none of the Java library ecosystem works, but it works with anything python. It is in rapid development right now – things are changing, including the syntax, how the API is covered, which renderer is used and what the requirements are, et cetera.

Both are great projects, depending on your needs. Yet another option is pyp5js, a Python to p5.js transcriptor / transpiler – this is python syntax that targets JavaScript in the browser. https://github.com/berinhard/pyp5js.

5 Likes

@jeremydouglass Appreciating you for taking the time to elaborate on this. I didn’t know that was how Processing.py worked or pyp5js existed :grinning: