Post Reply 
Python: Lindenmayer Fractals
08-29-2023, 09:50 PM
Post: #1
Python: Lindenmayer Fractals
Years ago Patrice published a program to create Lindenmayer Fractals . What is it? I thought that should be a good exercise for Python on the PRIME. It is! I used his code as a program logic for my approach, so thank you Patrice.

Warning! This app is a real memory hog. As Python on the Prime is terribly unstable you risk a full reset of your calculator including wiping out all memory. So if you are interested in this program make sure your precious work is saved and you're able to restore the calculator as needed. Let's hope that we'll get a stable version some day Smile

In this program I've tried to show some Python specifics to highlight the principle differences to PPL. For those of you who are new to Python I'll elaborate a bit on the structure.

1. Object orientation. In the main routine you select the fractal you wish to be created. Doing so, the fractal is created with it's properties and methods outlined in the module "Lsystem". Perhaps it needs some clean up, but for now I leave it as it is. The principle data for the specific fractal are provided by the dictionary in the module "Catalog".

2. Dictionary: The module "Catalog" contains a dictionary "Fractals". Here each fractal is identified by its name and has a list of basic properties. Adding a new fractal therefor doesn't need any change of code, only an entry in this list with the right description.

3. Generator: The method "NextAxiom" creates a new string by first creating a "generator object" thus avoiding continous garbage collections. At the end of this procedure the "generator object" is made a real string.

4. Exceptions: The app will always be out of memory eventually. In order to prevent the app from terminating the "memory overflow" is taken care of by a "MemoryError". Terminating the app by <ESC> or <ON> will also raise an exception, which gives you some statistical information befor terminating finally.

5. Interfacing with PPL: The input and output possibilities of Python are rather limited. Therefor I'm using the module "hpprime" to get rid of this deficiency. You'll find them in the module "Util", e.g. "TextOut","TxtRight","TxtCenter" ... Or the method "Select" in module "Lsystem"

When running the program, press <HELP> for the keys.

For those experienced Python programmers, please forgive my naive approach. But perhaps some, new as I am at 76, can gather something from it.

Comments are welcome, of course
Günter


Attached File(s)
.zip  L-Systems.hpappdir.zip (Size: 21.11 KB / Downloads: 16)
Find all posts by this user
Quote this message in a reply
08-30-2023, 03:27 PM
Post: #2
RE: Python: Lindenmayer Fractals
Thanks for sharing this Günter !

I think an overview about to use Python on the Prime would be a great presentation at HHC, and you seem to be the best guy to do that.... Wink

Even though the current Python implementation is unstable and has serious flaws, many have concluded that it is still the best handheld Python tool available, and the chief thing that prevents it's wider use is the utter lack of documentation about how to get started using it.

IMHO a long and fully complete presentation is not needed, anyone using Python is likely willing to explore as they go, so just a quick overview of how to create, access and run a 'Hello Prime Python World' program (and maybe a bit more like how to access other Prime features) is good enough.

Looking forward to seeing you in Orlando!

--Bob Prosperi
Find all posts by this user
Quote this message in a reply
08-30-2023, 06:44 PM
Post: #3
RE: Python: Lindenmayer Fractals
(08-30-2023 03:27 PM)rprosperi Wrote:  IMHO a long and fully complete presentation is not needed, anyone using Python is likely willing to explore as they go, so just a quick overview of how to create, access and run a 'Hello Prime Python World' program (and maybe a bit more like how to access other Prime features) is good enough.

Looking forward to seeing you in Orlando!

Bob, thanks for your comment. I must admit that I'm not really keen to prepare a presentation, even less as I'll be traveling a lot throughout September. But if the committee, specifically Richard, is content with a casual talk about Python on Prime without prepared slides, I could agree to elaborate on some Python specifics mostly along this program. If it's agreed upon not receiving anything in advance, give me a go and I'm going to babble about half an hour on this subject. Some additional time should be available for Q&A.

But please remember and accept , I'm a beginner myself still!

How is that? Günter

Hope Orlando will smoothly recover until then
Find all posts by this user
Quote this message in a reply
08-31-2023, 02:50 AM
Post: #4
RE: Python: Lindenmayer Fractals
That's more than fair Günter, I'll run it thru the committee and confirm more formally, but I'm sure this will be OK. Once confirmed, I'll have Dave add a topic, something like "Python Fractals on the Prime - observations and discussion" on the Attendee page of the HHC site.

Much appreciated, I will get back to you with more formal approval.

--Bob Prosperi
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: