Absolutely, great observations!
- FORTRAN IV uses
WRITE statements rather than PRINT, which was introduced in later FORTRAN standards.
- A fully integer implementation of the Midpoint Ellipse Algorithm is possible by avoiding fractional parts in decision parameters.
- To implement integer-only, the decision parameters and updates are scaled by multiplying all terms by 4 (or a suitable factor) to avoid fractions.
Fully Integer Midpoint Ellipse Algorithm in FORTRAN IV style
Below is an example FORTRAN IV program that uses integer variables only with WRITE statements and is suitable for rasterizing an ellipse with semiaxes A and B:
PROGRAM ELLIPSE_INT
INTEGER A, B
INTEGER A2, B2, X, Y
INTEGER DX, DY
INTEGER D1, D2
INTEGER TWO_A2, TWO_B2
WRITE(6,*) 'Enter semi-major axis A:'
READ(5,*) A
WRITE(6,*) 'Enter semi-minor axis B:'
READ(5,*) B
A2 = A * A
B2 = B * B
TWO_A2 = 2 * A2
TWO_B2 = 2 * B2
X = 0
Y = B
! Initial decision parameter D1 = B^2 - A^2*B + (1/4)*A^2, scaled by 4 to avoid fraction:
! Multiply entire decision parameters by 4:
D1 = 4*B2 - 4*A2*B + A2
DX = 0
DY = TWO_A2 * Y
100 CONTINUE
CALL PLOT_ELLIPSE_POINTS(X, Y)
IF (DX < DY) THEN
X = X + 1
DX = DX + TWO_B2
IF (D1 < 0) THEN
D1 = D1 + 4*B2 + DX
ELSE
Y = Y - 1
DY = DY - TWO_A2
D1 = D1 + 4*B2 + DX - DY
END IF
GOTO 100
END IF
! Decision parameter for region 2, also multiplied by 4 for integer arithmetic
! D2 = B^2*(x + 0.5)^2 + A^2*(y - 1)^2 - A^2*B^2
! Approximate (x+0.5)^2 as x^2 + x + 0.25 and multiply by 4:
! => 4*D2 = 4*B2*(X*X + X + 0.25) + 4*A2*(Y-1)*(Y-1) - 4*A2*B2
! = 4*B2*X*X + 4*B2*X + B2 + 4*A2*(Y-1)^2 - 4*A2*B2
D2 = (4*B2*X*X) + (4*B2*X) + B2 + 4*A2*(Y - 1)*(Y -1) - 4*A2*B2
200 CONTINUE
CALL PLOT_ELLIPSE_POINTS(X, Y)
IF (Y .LE. 0) GOTO 300
Y = Y - 1
DY = DY - TWO_A2
IF (D2 > 0) THEN
D2 = D2 + 4*A2 - DY
ELSE
X = X + 1
DX = DX + TWO_B2
D2 = D2 + 4*A2 - DY + DX
END IF
GOTO 200
300 WRITE(6,*) 'Ellipse rasterization complete.'
STOP
END
SUBROUTINE PLOT_ELLIPSE_POINTS(X, Y)
INTEGER X, Y
! Center at 0,0; plot all four quadrants
WRITE(6, '(A,3I6,A)') 'Plot pixel at (', X, ',', Y, ')'
WRITE(6, '(A,3I6,A)') 'Plot pixel at (', -X, ',', Y, ')'
WRITE(6, '(A,3I6,A)') 'Plot pixel at (', X, ',', -Y, ')'
WRITE(6, '(A,3I6,A)') 'Plot pixel at (', -X, ',', -Y, ')'
RETURN
END
Explanation:
- No floating point variables or operations are used.
- All decision parameters (
D1, D2) and updates are multiplied by 4 to avoid fractions.
- The
(X+0.5)^2 term is approximated as X^2 + X + 0.25, and then scaled by 4 to become exact integer arithmetic:
- (4 \times 0.25 = 1), so it becomes integer
1 (or B2 in our D2 calculation).
- I/O uses
WRITE(6,*) (standard output) and READ(5,*) (standard input) typical for FORTRAN IV.
- The call to
PLOT_ELLIPSE_POINTS outputs pixel coordinates; you can replace it with plotting calls specific to Tektronix 4020, such as preparing vector commands.
About Tektronix 4020:
- This terminal accepts pen plot commands in vector graphics.
- Typically, you'd scale
(X,Y) to screen coordinates, then output commands like:
WRITE(6, '("PU",2I6)') X_screen, Y_screen ! Pen up move to (X_screen, Y_screen)
WRITE(6, '("PD",2I6)') X_screen, Y_screen ! Pen down draw to (X_screen, Y_screen)
You can adapt the plotting subroutine accordingly.
Summary
- This program is fully integer and should run efficiently on FORTRAN IV.
- Proper integer scaling avoids floating point and fractions.
WRITE and READ are used per FORTRAN IV conventions.
- Suitable as a starting point for Tektronix 4020 pixel/pen plotting.
If you'd like, I can help you create example Tektronix 4020 vector commands output from this routine!