@ Generate a surface of revolution and display it in slices. @ See https://udel.edu/~mm/hat/index.html for information and history. @ @ Before running choose a block below, depending on what device the code will @ run on. Convert to .raw and then put it on the Plus42 or DM42. @ https://technical.swissmicros.com/decoders/dm42/ is easy to use. @ @ To run, choose values for NSLICES and HATX, push 'R/S' and eventually a @ hat will appear. @ @ Mike Markowski, mike.ab3ap@gmail.com @ Mar 2024 LBL "HAT" @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ Important: Comment out all but one block below. @ Block 1: Use for Plus42. 32 STO "NSLICES" @ Default. 90 STO "HATX" @ Default. 64 STO "RESY" @ Rows on screen 131 STO "RESX" @ Columns on screen. @ Block 2: Use for DM42 400x240 resolution. @3 @STO "GrMod" @ DM42 hi-res graphics @64 @STO "NSLICES" @ Default. @320 @STO "HATX" @ Default. @240 @STO "RESY" @ Rows on screen @400 @STO "RESX" @ Columns on screen. @ Block 3: Use for DM42 200x120 resolution. @2 @STO "GrMod" @ DM42 medium-res graphics @32 @STO "NSLICES" @ Default. @200 @STO "HATX" @ Default. @120 @STO "RESY" @ Rows on screen @200 @STO "RESX" @ Columns on screen. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ See if user wants to change defaults. LBL "VARS" MVAR "NSLICES" @ Make hat with 2*NSLICES slices. MVAR "HATX" @ Width in pixels of hat. VARMENU "VARS" STOP EXITALL @ Given hatX, use original screen ratio to calculate hatY. 200 @ y0, Y res in 1981 ad 320 @ x0, X res in 1981 ad / RCL* "HATX" STO "HATY" @ hatY=hatX*y0/x0, height,using old screen ratio. @ From original hat height, recalculate it for chosen hat size. 56 @ h0, Height of hat in 1981 ad. 200 @ y0 / RCL* "HATY" STO "HATHGT" @ hatHgt=h0/y0*hatY, new hat height. @ From original hat radius, recalculate it for chosen hat size. 144 @ r0, radius of 1981 hat. 320 @ x0 / RCL* "HATX" STO "HATRAD" @ hatRad=r0/x0*hatX, new hat radius. @ From original slice stagger (fake 3d), recalculate for chosen hat size. 64 @ n0, stagger amount 320 @ x0 / RCL* "HATX" STO "STAGGER" @ stagger=n0/x0*hatX, scale layer stagger for fake 3d. @ Calculate xf fraction of period to plot. 1.5 PI * @ a0 = 3 pi/2, fraction of period. RCL/ "HATRAD" STO "XF" @ xf=a0/hatRad, radians per vertical point on hat. CLLCD @ Clear LCD -1 STO "ZSLICE" LBL 01 @ Plot each zSlice in arange(-1,1,1/nSlices) RCL "ZSLICE" RCL* "HATRAD" STO "Z" @ z=zSlice*hatRad, from -hatRad to hatRad. RCL "HATRAD" X^2 RCL "Z" X^2 - SQRT STO "XL" @ xl=srqt(hatRad**2 - z**2), length of hat on x axis. CHS STO "X" @ -xl LBL 02 @ for x in range(-xl,xl+1) @ Calculate distance, xt, along hat's sinusoid. RCL "X" X^2 RCL "Z" X^2 + SQRT RCL* "XF" STO "XT" @ xt=xf*sqrt(x**2 + z**2) @ Calculate point, y, above x on surface of hat. SIN @ sin(xt) 3 RCL* "XT" SIN 0.4 * + RCL* "HATHGT" STO "Y" @ y=(sin(xt) + 0.4*sin(xt*3))*hatHgt @ Stagger x to x1, of slice to create 3d effect. 0.5 RCL* "HATX" RCL "STAGGER" RCL* "ZSLICE" + RCL+ "X" STO "X1" @ x1=x + stagger*zSlice + hatX/2 @ Stagger y to y1, of slice to create 3d effect. 0.5 RCL* "HATY" RCL "STAGGER" RCL* "ZSLICE" - RCL+ "Y" STO "Y1" @ y1=y - stagger*zSlice + hatY/2 RCL "HATY" RCL- "Y1" STO "Y1" @ y1=hatY - y1, flip vertically. @ Center small hat horizontally on screen. RCL "RESX" @ Screen horizontal resolution. RCL- "HATX" 2 / STO+ "X1" @ x1+=(x0 - hatX)/2 @ Center small hat vertically on screen. RCL "RESY" @ Number of rows on screen. RCL- "HATY" 2 / STO "YOFFSET" @ yOffset=(y0 - hatY)/2 STO+ "Y1" @ y1+=(y0 - hatY)/2. RCL "Y1" RCL "X1" PIXEL @ Light pixel (x1,y1). XEQ "LINEOFF" @ Erase vertical line below (x1,y1). 1 STO+ "X" @ Increment loop variable x += 1. RCL "XL" @ Y: x axis length of this slice. RCL "X" @ X: this x coord. X<=Y? @ Are we at end of slice? GTO 02 1 RCL/ "NSLICES" STO+ "ZSLICE" 1 RCL "ZSLICE" X