Python: some practice, questions and #%§'
|
05-12-2021, 09:10 PM
Post: #1
|
|||
|
|||
Python: some practice, questions and #%§'
Now with Python I was curious what it is after all. So I decided to play a little bit around. You're of course invited to play with me. Subject is: drawing the Mandelbrot set
WARNING If you play with this, your Prime will reboot when you access an APP, definitely. BUT this is not a great deal, you'll only lose the stack. To prevent from this, switch the Prime on and off. this will preserve the stack, but won't prevent from a reboot. That's what the "#%§'" is about. Really annoying. I hope the moderators leave this here, because it's not meant as a great program but a playing field, to explore and exploit the capabilities of the implementation of Python on the Prime. Specifically LISTS, SETS and Drawing. Copy this code to a PPL-program. The name doesn't matter. Look at the top of the code for input syntax. Code: #PYTHON name I'm a complete newbie to Python and inexperienced in programming, so bear with me if I talk about the obvious, but I hope to get some input as well. Ref: #%§'
Next step should be zooming. Therefore MOUSE or KEY events would be very helpful. Günter |
|||
05-15-2021, 01:04 AM
Post: #2
|
|||
|
|||
RE: Python: some practice, questions and #%§'
I seem to have some success with the following snippet in PPL:
Code:
The snippet prints the y-coord of the mouse pointer for a two-point touch, or the key code for a clicked calculator key and can be exited by pressing 'On'. Both mouse() and keyboard() don't seem to accept any parameters. As noted in one of your previous posts, I haven't had any luck making a Python script file work (using the More>Files>New Program feature of the Editor). Thanks for your invaluable contributions to the knowledge base. Your posted have been very helpful in trying to figure things out. Jim |
|||
05-15-2021, 11:05 PM
(This post was last modified: 05-16-2021 10:19 AM by Guenter Schink.)
Post: #3
|
|||
|
|||
RE: Python: some practice, questions and #%§'
(05-15-2021 01:04 AM)jkor Wrote: I seem to have some success with the following snippet in PPL:Thanks for your comment, and the code snipped, that helped a lot. Now I have a routine for mouse, at least on the virtual Prime, that seems to work reliably and easy to use. Checking out on the real Prime will follow. For now I call it a day, although I should call it a night at 1 hour past midnight here. Code: from hpprime import * We'll continue to play with Python, no? Günter |
|||
05-16-2021, 12:06 AM
Post: #4
|
|||
|
|||
RE: Python: some practice, questions and #%§'
Yes we definitely should continue. Like you, I am relatively new to Python, picking it up about a week ago. So, I see this as a golden learning opportunity, through actually trying to make things work.
I can't wait for the stable release, having many PPL programs that I am looking forward to revamping. Playing with the Prime has become an somewhat of an obsession, currently . Of particular interest is coming up with generic framework for a GUI (cascading menus, dialog boxes and the like). Again, thank you for the inspiration provided, and many thanks to the HP Prime team for a compelling product that ensures I don't get too much (enough) sleep. Until the next hurtle, very best, Jim |
|||
05-16-2021, 10:17 AM
Post: #5
|
|||
|
|||
RE: Python: some practice, questions and #%§'
Another trap:
in your snipped: Quote: print('key= '+str(int(log2(k))))doesn't always return the correct key code due to the binary nature of floats. This can be avoided by replacing <int> by <round>. In this case <round> even doesn't need a second argument. For positive numbers it works like <ceil> from the math module. Quote: print('key= '+str(round(log2(k)))) Things like this could drive you crazy. Günter |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: