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 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 |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
Python: Lindenmayer Fractals - Guenter Schink - 08-29-2023 09:50 PM
RE: Python: Lindenmayer Fractals - rprosperi - 08-30-2023, 03:27 PM
RE: Python: Lindenmayer Fractals - Guenter Schink - 08-30-2023, 06:44 PM
RE: Python: Lindenmayer Fractals - rprosperi - 08-31-2023, 02:50 AM
|
User(s) browsing this thread: 1 Guest(s)