Post Reply 
Python oddities
05-05-2021, 10:24 PM
Post: #3
RE: Python oddities
(05-05-2021 08:56 PM)toml_12953 Wrote:  Where is PPL-Changes + python.odt?

When I try to export the program name (hat), I get an error at

Export hat()

It was in Tim's announcement

https://www.hpcalc.org/prime/beta/betanotes.zip

I think the syntax is not really obvious, could you post your code? Perhaps I can help. There are two distinct structures in the mentioned document, either one works, but don't mix them.

BTW, I took the freedom to tailor your Pyhat a bit. There is no improvement, I just played a little bit with Python things.
Code:
#PYTHON EXPORT name(c)
from hpprime import *
from math import *
mache=pixon
t0 = eval("ticks()") # Save the current clock count for timing program
fg=0xa0a0a0
# Clear screen
bg=0
fillrect(0,0,0,320,240,bg,bg)
# Start program proper
p=160; q=120
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+1):
  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
      mache(0,x1,230-y1,fg)
#      eval("wait(0.001)")
      if y1!=0:
        line(0,x1,230-y1+1,x1,230,bg) # Erase points below current point
#    eval("wait(0.001)")
t = eval("ticks()")-t0
# Wait for key and print elapsed time
eval("wait()")
t = t/1000
print(t," seconds")
#end
Export pyhat(a)
Begin
  name(a);
End;

This has to be copied into an PPL program to work. Then it can be called by "pyhat(0)", any number instead of "0" will do.

G√ľnter
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Python oddities - Guenter Schink - 05-05-2021, 07:41 PM
RE: Python oddities - toml_12953 - 05-05-2021, 08:56 PM
RE: Python oddities - Guenter Schink - 05-05-2021 10:24 PM
RE: Python oddities - toml_12953 - 05-06-2021, 12:28 AM



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