HiResHat

Date: 198x
Type: Program
Platform(s): TS 2068
Tags: Demo, Software

This program draws a high-resolution 3D hat-shaped surface using the PLOT command. Lines 20 draws a full-screen border rectangle, then the main nested loop (lines 60–160) iterates over a circular domain in the k and t variables to compute a parametric surface where height is defined by a sum-of-sines formula: SIN(xt) + 0.4·SIN(3·xt). The x and y screen coordinates are derived via an oblique isometric-style projection using scaling factors xs=0.78 and ys=0.85, with centre point p=128, q=95. No machine code is used; the program relies entirely on BASIC floating-point maths, making it computationally intensive but straightforward to follow.


Program Structure

The program is divided into three logical phases:

  1. Border drawing (line 20): uses PLOT/DRAW to trace a rectangle around the full 256×176 pixel screen area.
  2. Parameter initialisation (lines 35–50): pre-computes all scaling and frequency factors to avoid repeated arithmetic inside the loops.
  3. Surface rendering (lines 60–160): a double nested loop iterates over the circular domain and plots each surface point individually.

Mathematical Surface Definition

The surface is a classic “sombrero” or hat function. For each column slice k (ranging from -zp to zp, i.e. −64 to 64), the half-width of the circular cross-section is computed at line 80:

xl = INT(0.5 + SQR(xp*xp - zt*zt))

where zt = k * xq scales k into the same coordinate space as the x-axis radius xp=144. This enforces a circular boundary on the (t, k) domain. The height at each point is then:

yy = (SIN(xt) + 0.4 * SIN(3*xt)) * yf

where xt = SQR(t*t + zt*zt) * xf is the radial distance scaled by frequency factor xf = xr/xp (with xr = 1.5*PI). The second harmonic term 0.4*SIN(3*xt) adds a secondary ripple ring around the central peak.

Projection and Scaling

The 3D-to-2D projection is an oblique parallel (cabinet-style) projection rather than true isometric. Screen coordinates are computed as:

VariableFormulaPurpose
xxs*(t+k) + pHorizontal screen position; t+k gives the oblique axis blend
yys*(yy-k) + qVertical screen position; yy is height, -k recedes into the screen

The factors xs=0.78 and ys=0.85 compress the axes to keep the image within the bordered area. The centre offsets p=128 and q=95 place the origin near the middle of the screen.

Pre-computed Constants

All derived constants are computed once in lines 35–50 rather than inside the loops, which is good practice for BASIC performance:

  • xf = xr/xp — radial-to-angle frequency scale
  • yf = yp/yr — height amplitude scale (evaluates to 56 since yr=1)
  • zf = xr/zp — defined but never used (see anomalies below)
  • xq = xp/zp — ratio used to scale k relative to xp

Notable Techniques

  • Using INT(0.5 + SQR(...)) at line 80 is a standard rounding idiom, avoiding a dedicated ROUND function.
  • The circular loop limit (FOR t=-xl TO xl) ensures only points inside the circular base are plotted, keeping the rendered surface geometrically clean.

Content

Appears On

Related Products

Related Articles

Related Content

Image Gallery

HiResHat

Source Code

    5 SAVE "HI RES HAT"
   10 REM HI RES HAT
   20 PLOT 0,0: DRAW 0,175: DRAW 255,0: DRAW 0,-175: DRAW -255,0:
   30 REM Lines 40 to 130 calcu X and Y for Plotting
   35 LET xs=.78: LET ys=.85
   40 LET p=128: LET q=95: LET xp=144: LET xr=1.5*PI: LET yp=56: LET yr=1
   50 LET zp=64: LET xf=xr/xp: LET yf=yp/yr: LET zf=xr/zp: LET xq=xp/zp
   60 FOR k=-zp TO zp
   70 LET zt=k*xq
   80 LET xl=INT (.5+SQR (xp*xp-zt*zt))
   90 FOR t=-xl TO xl
  100 LET xt=SQR (t*t+zt*zt)*xf
  110 LET yy=(SIN (xt)+.4*SIN (3*xt))*yf
  120 LET x=(xs*(t+k))+p
  130 LET y=(ys*(yy-k))+q
  140 PLOT x,y
  150 NEXT t
  160 NEXT k
  170 STOP

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

People

No people associated with this content.

Scroll to Top