Menu

MidPoint Circle Formula

kent_twt4
2014-04-18
2014-04-18
  • kent_twt4

    kent_twt4 - 2014-04-18

    This is a port of Midpoint Circle formula discussed in a previous post. Please don't ask me to explain, too far removed from doing the maths. And here is an example:

    'Midpoint Circle algorithm
    'Chip model
    #chip 16f1783,8
    #include <GLCD.h>
    
    #define GLCD_RW  PortA.1     'Read/Write pin connection
    #define GLCD_RESET  PortA.5  '‘Reset pin connection
    #define GLCD_CS1  PortA.4    'Swap CS1/CS2 pin connections
    #define GLCD_CS2  PortA.3
    #define GLCD_RS  PortA.0     'RS pin connection
    #define GLCD_ENABLE  PortA.2 'Enable pin Connection
    #define GLCD_DB0  PortC.0    'Data pin 0 Connection
    #define GLCD_DB1  PortC.1    'Data pin 1 Connection
    #define GLCD_DB2  PortC.2    'Data pin 2 Connection
    #define GLCD_DB3  PortC.3    'Data pin 3 Connection
    #define GLCD_DB4  PortC.4    'Data pin 4 Connection
    #define GLCD_DB5  PortC.5    'Data pin 5 Connection
    #define GLCD_DB6  PortC.6    'Data pin 6 Connection
    #define GLCD_DB7  PortC.7    'Data pin 7 Connection
    
    dir PortA out
    dir PortC out
    
    dim  xradius, yordinate , radiusErr as Integer
    InitGLCD
    
    Start:
    GLCDCLS
    Set GLCD_CS1 Off        'Temporary Pset bug in glcd.h
    Set GLCD_CS2 Off
    wait 1 s
    GLCDCircle (64,32,5,0)
    GLCDCircle (64,32,10,0)
    GLCDCircle (64,32,20,0)
    GLCDCircle (64,32,31,0)
    wait 10 s
    goto start
    
    sub GLCDCircle (xoffset, yoffset, xradius, yordinate)
    'radiusErr = 1 - xradius
    radiusErr = -(xradius/2)
    Do While xradius >=  yordinate
       Pset ((xoffset + xradius), (yoffset + yordinate), on)
       Pset ((xoffset + yordinate), (yoffset + xradius), on)
       Pset ((xoffset - xradius), (yoffset + yordinate), on)
       Pset ((xoffset - yordinate), (yoffset + xradius), on)
       Pset ((xoffset - xradius), (yoffset - yordinate), on)
       Pset ((xoffset - yordinate), (yoffset - xradius), on)
       Pset ((xoffset + xradius), (yoffset - yordinate), on)
       Pset ((xoffset + yordinate), (yoffset - xradius), on)
       yordinate ++
       If radiusErr < 0 Then
          radiusErr = radiusErr + 2 * yordinate + 1
       else
          xradius --
          radiusErr = radiusErr + 2 * (yordinate - xradius + 1)
       end if
    Loop
    end sub
    
     
    ❤️
    1
  • kent_twt4

    kent_twt4 - 2014-04-18

    Add Attachment

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.