04-21-2021, 07:34 AM
The new Python interpreter graphics are fast!
I ran three programs to draw a green hat, Here are the runtimes:
HPPL: 7.793 sec
CAS with Python syntax: 25.436 sec
Python (Apr 16 Beta): 0.926 sec
Here's the Python version:
I ran three programs to draw a green hat, Here are the runtimes:
HPPL: 7.793 sec
CAS with Python syntax: 25.436 sec
Python (Apr 16 Beta): 0.926 sec
Here's the Python version:
Code:
#PYTHON EXPORT pyhat
from hpprime import *
from math import *
t0 = eval("ticks()") # Save the current clock count for timing program
# Clear screen
fillrect(0,0,0,320,240,0,0)
# 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
pixon(0,x1,230-y1,65280)
if y1!=0:
line(0,x1,230-y1+1,x1,230,0) # Erase points below current point
t = eval("ticks()")-t0
# Wait for key and print elapsed time
eval("wait()")
t = t/1000
print(t," seconds")
#end