Cornu's Spiral

Discussions related to graphics (2D and 3D), animation and games programming
Richard Russell
Posts: 272
Joined: Tue 18 Jun 2024, 09:32

Cornu's Spiral

Post by Richard Russell »

I'm not sure why this wasn't posted here at the time (perhaps it was when the forum was temporarily out of action) but back in April I transcribed what was probably the first program I ever wrote (!) - a Fortran program written more than 50 years ago - to BBC BASIC.

The program was originally written for an IBM 1130 mainframe, on punched cards which I have kept ever since. I initially recreated the Fortran code by reading the statements printed along the top of the cards (not easy, because they were hard to read and there were some misleading character substitutions). Having got something close to the original Fortran in machine-readable form I then translated it to BASIC, which was relatively straightforward.

The program plots Cornu's Spiral, on a pen-plotter back in 1970 or thereabouts but on the screen now of course. I don't claim to understand how it works, although there are evidently some iterative calculations there. I've listed the code below.

Code: Select all

      SIZE = 720
      VDU 23,22,SIZE;SIZE;16,20,16,0
      ORIGIN SIZE,SIZE

      GCOL 1
      FOR X =-1.0 TO 1.0 STEP 0.1
        LINE X*SIZE,-SIZE,X*SIZE,SIZE
      NEXT
      FOR Y =-1.0 TO 1.0 STEP 0.1
        LINE -SIZE,Y*SIZE,SIZE,Y*SIZE
      NEXT

      GCOL 15
      V1=0.001
      CIRCLE FILL 0,0,4
      FOR J=1 TO 2
        K=0
        V=0
        MOVE 0,0
        REPEAT
          D=V/100
          X2=0
          X3=0
          Y2=0
          Y3=0
          X1=1
          Y1=0
          Z=D
          FOR I=1 TO 99 STEP 2
            X2=X2+COS(PI*Z*Z/2)
            Y2=Y2+SIN(PI*Z*Z/2)
            Z=Z+2*D
          NEXT
          Z=2*D
          FOR I=2 TO 98 STEP 2
            X3=X3+COS(PI*Z*Z/2)
            Y3=Y3+SIN(PI*Z*Z/2)
            Z=Z+2*D
          NEXT
          X4=COS(PI*V*V /2)
          Y4=SIN(PI*V*V /2)
          X=(D/3)*(X1+X4+4*X2+2*X3)
          Y=(D/3)*(Y1+Y4+4*Y2+2*Y3)
          DRAW X*SIZE,Y*SIZE
          V=V+V1
          K=K-1
          IF K<-100 THEN
            CIRCLE FILL X*SIZE,Y*SIZE,4
            K=0
          ENDIF
        UNTIL ABS(V)>=5
        V1=-0.001
      NEXT J
      ORIGIN 0,0
      END
cornu.png
You do not have the required permissions to view the files attached to this post.
Richard Russell
Posts: 272
Joined: Tue 18 Jun 2024, 09:32

Re: Cornu's Spiral

Post by Richard Russell »

Richard Russell wrote: Tue 24 Sep 2024, 11:44 The program was originally written for an IBM 1130 mainframe, on punched cards which I have kept ever since.
Here's the Fortran program, and a picture of the card stack:

Code: Select all

      <binary cold start card>
      // JOB
      // FOR
      *IOCS CARD,TYPEWRITER,PLOTTER
      // * R.RUSSELL. HERTFORD COLL.
      IPLOT=7
      K=0
      CALL FGRID(0,-9.,0,1.,16)
      CALL FGRID(1,0,-9.,1.,16)
      CALL FCHAR(-4.,-10.,0.9,0)
      WRITE(IPLOT,9100)
 9100 FORMAT(15HCORNU'S SPIRAL)
      CALL FCHAR(9.,-6.,0.3,0.4,0)
      WRITE(IPLOT,9200)
 9200 FORMAT('R.T.R.')
      CALL FCHAR(9.,1.,0.9,0.4,0)
      WRITE(IPLOT,9300)
 9300 FORMAT('X=0.8')
      CALL FCHAR(1.,9.,0.3,0.4,0)
      WRITE(IPLOT,9400)
 9400 FORMAT('Y=0.9')
      V=0
      V1=0.02
    5 CALL FPLOT(1,0,0)
      CALL FPLOT(-2,0,0)
   10 D=V/100
      Z=0
      X2=0
      X3=0
      Y2=0
      Y3=0
      X1=1
      Y1=0
      DO 20 I=1,99,2
      X2=X2+COS(3.141596*Z*Z /2)
      Y2=Y2+SIN(3.141596*Z*Z /2)
      Z=Z+2*D
   20 CONTINUE
      Z=2*D
      DO 30 I=2,98,2
      X3=X3+COS(3.141596*Z*Z /2)
      Y3=Y3+SIN(3.141596*Z*Z /2)
      Z=Z+2*D
   30 CONTINUE
      X4=COS(3.141596*V*V /2)
      Y4=SIN(3.141596*V*V /2)
      X=(D/3)*(X1+X4+4*X2+2*X3)
      Y=(D/3)*(Y1+Y4+4*Y2+2*Y3)
      X=X*10
      Y=Y*10
      CALL FPLOT(0,X,Y)
      IF(-(K+5))35,32,32
   32 CALL POINT(0)
      K=0
   35 V=V+V1
      K=K-1
      IF(4-ABS(V))40,10,10
   40 IF(V)60,50,50
   50 V=0
      K=0
      V1=-0.02
      GOTO 5
   60 CALL FPLOT(1,0,0)
      CALL EXIT
      END
      // XEQ
Cornu.jpg
You do not have the required permissions to view the files attached to this post.
User avatar
hellomike
Posts: 184
Joined: Sat 09 Jun 2018, 09:47
Location: Amsterdam

Re: Cornu's Spiral

Post by hellomike »

Ah, good old FORTRAN. Brings back memories.
Thanks for sharing.