Task

Using the data storage type defined on this page for raster images,
write an implementation of the midpoint circle algorithm   (also known as Bresenham's circle algorithm).

(definition on Wikipedia).




      Width% = 200
      Height% = 200
 
      REM Set window size:
      VDU 23,22,Width%;Height%;8,16,16,128
 
      REM Draw circles:
      PROCcircle(100,100,40, 0,0,0)
      PROCcircle(100,100,80, 255,0,0)
      END
 
      DEF PROCcircle(cx%,cy%,r%,R%,G%,B%)
      LOCAL f%, x%, y%, ddx%, ddy%
      f% = 1 - r% : y% = r% : ddy% = - 2*r%
      PROCsetpixel(cx%, cy%+r%, R%,G%,B%)
      PROCsetpixel(cx%, cy%-r%, R%,G%,B%)
      PROCsetpixel(cx%+r%, cy%, R%,G%,B%)
      PROCsetpixel(cx%-r%, cy%, R%,G%,B%)
      WHILE x% < y%
        IF f% >= 0 THEN
          y% -= 1
          ddy% += 2
          f% += ddy%
        ENDIF
        x% += 1
        ddx% += 2
        f% += ddx% + 1
        PROCsetpixel(cx%+x%, cy%+y%, R%,G%,B%)
        PROCsetpixel(cx%-x%, cy%+y%, R%,G%,B%)
        PROCsetpixel(cx%+x%, cy%-y%, R%,G%,B%)
        PROCsetpixel(cx%-x%, cy%-y%, R%,G%,B%)
        PROCsetpixel(cx%+y%, cy%+x%, R%,G%,B%)
        PROCsetpixel(cx%-y%, cy%+x%, R%,G%,B%)
        PROCsetpixel(cx%+y%, cy%-x%, R%,G%,B%)
        PROCsetpixel(cx%-y%, cy%-x%, R%,G%,B%)
      ENDWHILE
      ENDPROC
 
      DEF PROCsetpixel(x%,y%,r%,g%,b%)
      COLOUR 1,r%,g%,b%
      GCOL 1
      LINE x%*2,y%*2,x%*2,y%*2
      ENDPROC