HP Forums
Hat Program in Python - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: HP Prime Software Library (/forum-15.html)
+--- Thread: Hat Program in Python (/thread-15516.html)



Hat Program in Python - toml_12953 - 08-31-2020 03:26 AM

Here's an example of the infamous Green Hat program I translate for and run on any calculator that has graphics. I also run this in HPPL but it's a lot faster in Python.
PHP Code:
#cas
def pyhat():
  
t0 ticks # Save the current clock count for timing program
  # Black out background
  
rect_p(0,0,320,240,rgb(0,0,0))
  
# Start program proper
  
p=160q=120
  xp
=144xr=1.5*3.1415927
  yp
=56yr=1zp=64
  xf
=xr/xpyf=yp/yrzf=xr/zp
  
for zi in range(-q,q+1):
    if 
zi>=-zp and zi<=zp:
      
zt=zi*xp/zpzz=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)*xfxx=xi
        yy
=(sin(xt)+.4*sin(3*xt))*yf
        x1
=xx+zz+p
        y1
=yy-zz+q
        pixon_p
(x1,230-y1,rgb(0,255,0))
        if 
y1!=0:
          
Line_p(x1,230-y1+1,x1,230# Erase points below current point
  
ticks-t0
  
# Wait for key and print elapsed time
  
wait
  
print(approx(t/1000)+" seconds")
#end 



RE: Hat Program in Python - compsystems - 09-01-2020 09:17 PM

nice graphic, I have presented it to my students =). Although now I am teaching with SmallBasic

Similar image
[Image: 661711]
Source: https://social.msdn.microsoft.com/Forums/es-ES/1e8c53bb-7974-47ef-9d48-7367931b4fac/small-basic-graphic-and-animations-and-more?forum=smallbasic