Post Reply 
Why Doesn't This Python Program Work?
07-25-2024, 04:56 AM (This post was last modified: 07-25-2024 04:57 AM by toml_12953.)
Post: #1
Why Doesn't This Python Program Work?
The following program works when I put it in a PPL wrapper but not from the Python app. In the Python app, it doesn't draw anything, it just prints the elapsed time. I can't figure out why. Can you?

Code:
from hpprime import *
from math import *
from graphic import *
t0=eval("ticks")
set_cartesian(0,0,320,200)
# Clear screen 
fillrect_c(0,0,0,320,200,black,black)
# Start program proper   
p=160; q=100
xp=144; xr=1.5*3.1415927
yp=56; yr=1; zp=64
xf=xr/xp; yf=yp/yr; zf=xr/zp
for zi in range(-q,q):
   if zi>=-zp and zi<=zp:
      zt=zi*xp/zp; zz=zi
      xl=int(.5+sqrt(xp*xp-zt*zt))
      # Draw one cross-section of figure     
      for xi in range(-xl,xl+1):     
         xt=sqrt(xi*xi+zt*zt)*xf; xx=xi
         yy=(sin(xt)+.4*sin(3*xt))*yf
         x1=xx+zz+p      
         y1=yy-zz+q
         pixon_c(0,x1,y1,green)
         if y1!=0:
            line_c(0,x1,y1-1,x1,0,black)
t0 = eval("ticks")-t0
# Wait for key and print elapsed time
eval("wait")
t0 = t0/1000
print()
print(t0," seconds")

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
07-25-2024, 11:39 AM
Post: #2
RE: Why Doesn't This Python Program Work?
It seems that the graphic functions for Cartesian coordinates do not work directly from the Python application. Removing the '_c' suffix from fillrect_c and pixon_c makes the graphics appear.

Piotr Kowalewski
Find all posts by this user
Quote this message in a reply
07-25-2024, 12:52 PM
Post: #3
RE: Why Doesn't This Python Program Work?
(07-25-2024 11:39 AM)komame Wrote:  It seems that the graphic functions for Cartesian coordinates do not work directly from the Python application. Removing the '_c' suffix from fillrect_c and pixon_c makes the graphics appear.

That's a pity. Thanks for the tip. It's working fine now. I also had to reverse the Y-Axis manually.

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
07-26-2024, 02:53 AM
Post: #4
RE: Why Doesn't This Python Program Work?
I've found out that, in the latest Betas, set_cartesian has no effect and the cartesian versions of the graphics commands don't work. This is both in the Python app and a PPL wrapper. My code worked perfectly before the Beta but now I'll have to wait for more fixes. This is a fairly major issue. It's very handy to define your own coordinates rather than have to calculate pixel positions on your own.

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
07-26-2024, 03:47 PM (This post was last modified: 07-26-2024 04:07 PM by komame.)
Post: #5
RE: Why Doesn't This Python Program Work?
(07-26-2024 02:53 AM)toml_12953 Wrote:  I've found out that, in the latest Betas, set_cartesian has no effect and the cartesian versions of the graphics commands don't work. [...] My code worked perfectly before the Beta but now I'll have to wait for more fixes.

I just downgraded my G2 to the latest public firmware 14730, and it also doesn't work there, both through the PPL wrapper and in the Python app. I also checked the Virtual Calculator for Windows, and it doesn't work there either. Are you sure this ever worked in Python on Prime (I haven't checked on versions older than 14730)?

EDIT:
Here are also Günter's tests for an earlier beta version, and as you can see, fillrect_c was already not working properly at that time.

Piotr Kowalewski
Find all posts by this user
Quote this message in a reply
08-09-2024, 06:34 AM
Post: #6
RE: Why Doesn't This Python Program Work?
(07-26-2024 02:53 AM)toml_12953 Wrote:  ... the cartesian versions of the graphics commands don't work. ... It's very handy to define your own coordinates rather than have to calculate pixel positions on your own.

Thanks for bringing this up. A few tickets have been filed regarding the Cartesian versions (the “_c” variants) of hpprime Python drawing commands ... and those bugs got fixed! Big Grin
Find all posts by this user
Quote this message in a reply
08-09-2024, 07:18 AM
Post: #7
RE: Why Doesn't This Python Program Work?
(08-09-2024 06:34 AM)jte Wrote:  ... and those bugs got fixed! Big Grin

This was the most frustrating sentence I've read here quite a few times in the past. Fortunately, the promised update awaits us by the end of August, so hopefully we won't have to wait years for fixes to be published again. :-)

Prime G2, 15C CE
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 3 Guest(s)