mirror of
				https://github.com/irmen/prog8.git
				synced 2025-11-03 19:16:13 +00:00 
			
		
		
		
	fix monogfx.disc() inaccurracy
This commit is contained in:
		@@ -595,23 +595,12 @@ drawmode:               ora  cx16.r15L
 | 
			
		||||
            return
 | 
			
		||||
        ubyte @zp yy = 0
 | 
			
		||||
        word @zp decisionOver2 = (1 as word)-radius
 | 
			
		||||
        uword last_y3 = ycenter+radius
 | 
			
		||||
        uword last_y4 = ycenter-radius
 | 
			
		||||
        uword new_y3, new_y4
 | 
			
		||||
 | 
			
		||||
        while radius>=yy {
 | 
			
		||||
            horizontal_line(xcenter-radius, ycenter+yy, radius*$0002+1, draw)
 | 
			
		||||
            horizontal_line(xcenter-radius, ycenter-yy, radius*$0002+1, draw)
 | 
			
		||||
            new_y3 = ycenter+radius
 | 
			
		||||
            if new_y3 != last_y3 {
 | 
			
		||||
                horizontal_line(xcenter-yy, last_y3, yy*$0002+1, draw)
 | 
			
		||||
                last_y3 = new_y3
 | 
			
		||||
            }
 | 
			
		||||
            new_y4 = ycenter-radius
 | 
			
		||||
            if new_y4 != last_y4 {
 | 
			
		||||
                horizontal_line(xcenter-yy, last_y4, yy*$0002+1, draw)
 | 
			
		||||
                last_y4 = new_y4
 | 
			
		||||
            }
 | 
			
		||||
            horizontal_line(xcenter-yy, ycenter+radius, yy*$0002+1, draw)
 | 
			
		||||
            horizontal_line(xcenter-yy, ycenter-radius, yy*$0002+1, draw)
 | 
			
		||||
            yy++
 | 
			
		||||
            if decisionOver2>=0 {
 | 
			
		||||
                radius--
 | 
			
		||||
@@ -620,10 +609,6 @@ drawmode:               ora  cx16.r15L
 | 
			
		||||
            decisionOver2 += yy*$0002
 | 
			
		||||
            decisionOver2++
 | 
			
		||||
        }
 | 
			
		||||
        ; draw the final two spans
 | 
			
		||||
        yy--
 | 
			
		||||
        horizontal_line(xcenter-yy, last_y3, yy*$0002+1, draw)
 | 
			
		||||
        horizontal_line(xcenter-yy, last_y4, yy*$0002+1, draw)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    sub safe_disc(uword @zp xcenter, uword @zp ycenter, ubyte @zp radius, bool draw) {
 | 
			
		||||
@@ -634,23 +619,12 @@ drawmode:               ora  cx16.r15L
 | 
			
		||||
            return
 | 
			
		||||
        ubyte @zp yy = 0
 | 
			
		||||
        word @zp decisionOver2 = (1 as word)-radius
 | 
			
		||||
        uword last_y3 = ycenter+radius
 | 
			
		||||
        uword last_y4 = ycenter-radius
 | 
			
		||||
        uword new_y3, new_y4
 | 
			
		||||
 | 
			
		||||
        while radius>=yy {
 | 
			
		||||
            safe_horizontal_line(xcenter-radius, ycenter+yy, radius*$0002+1, draw)
 | 
			
		||||
            safe_horizontal_line(xcenter-radius, ycenter-yy, radius*$0002+1, draw)
 | 
			
		||||
            new_y3 = ycenter+radius
 | 
			
		||||
            if new_y3 != last_y3 {
 | 
			
		||||
                safe_horizontal_line(xcenter-yy, last_y3, yy*$0002+1, draw)
 | 
			
		||||
                last_y3 = new_y3
 | 
			
		||||
            }
 | 
			
		||||
            new_y4 = ycenter-radius
 | 
			
		||||
            if new_y4 != last_y4 {
 | 
			
		||||
                safe_horizontal_line(xcenter-yy, last_y4, yy*$0002+1, draw)
 | 
			
		||||
                last_y4 = new_y4
 | 
			
		||||
            }
 | 
			
		||||
            safe_horizontal_line(xcenter-yy, ycenter+radius, yy*$0002+1, draw)
 | 
			
		||||
            safe_horizontal_line(xcenter-yy, ycenter-radius, yy*$0002+1, draw)
 | 
			
		||||
            yy++
 | 
			
		||||
            if decisionOver2>=0 {
 | 
			
		||||
                radius--
 | 
			
		||||
@@ -659,10 +633,6 @@ drawmode:               ora  cx16.r15L
 | 
			
		||||
            decisionOver2 += yy*$0002
 | 
			
		||||
            decisionOver2++
 | 
			
		||||
        }
 | 
			
		||||
        ; draw the final two spans
 | 
			
		||||
        yy--
 | 
			
		||||
        safe_horizontal_line(xcenter-yy, last_y3, yy*$0002+1, draw)
 | 
			
		||||
        safe_horizontal_line(xcenter-yy, last_y4, yy*$0002+1, draw)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    sub plot(uword @zp xx, uword @zp yy, bool @zp draw) {
 | 
			
		||||
 
 | 
			
		||||
@@ -302,23 +302,11 @@ monogfx {
 | 
			
		||||
            return
 | 
			
		||||
        ubyte @zp yy = 0
 | 
			
		||||
        word @zp decisionOver2 = (1 as word)-radius
 | 
			
		||||
        uword last_y3 = ycenter+radius
 | 
			
		||||
        uword last_y4 = ycenter-radius
 | 
			
		||||
        uword new_y3, new_y4
 | 
			
		||||
 | 
			
		||||
        while radius>=yy {
 | 
			
		||||
            horizontal_line(xcenter-radius, ycenter+yy, radius*$0002+1, draw)
 | 
			
		||||
            horizontal_line(xcenter-radius, ycenter-yy, radius*$0002+1, draw)
 | 
			
		||||
            new_y3 = ycenter+radius
 | 
			
		||||
            if new_y3 != last_y3 {
 | 
			
		||||
                horizontal_line(xcenter-yy, last_y3, yy*$0002+1, draw)
 | 
			
		||||
                last_y3 = new_y3
 | 
			
		||||
            }
 | 
			
		||||
            new_y4 = ycenter-radius
 | 
			
		||||
            if new_y4 != last_y4 {
 | 
			
		||||
                horizontal_line(xcenter-yy, last_y4, yy*$0002+1, draw)
 | 
			
		||||
                last_y4 = new_y4
 | 
			
		||||
            }
 | 
			
		||||
            horizontal_line(xcenter-yy, ycenter+radius, yy*$0002+1, draw)
 | 
			
		||||
            horizontal_line(xcenter-yy, ycenter-radius, yy*$0002+1, draw)
 | 
			
		||||
            yy++
 | 
			
		||||
            if decisionOver2>=0 {
 | 
			
		||||
                radius--
 | 
			
		||||
@@ -327,10 +315,6 @@ monogfx {
 | 
			
		||||
            decisionOver2 += yy*$0002
 | 
			
		||||
            decisionOver2++
 | 
			
		||||
        }
 | 
			
		||||
        ; draw the final two spans
 | 
			
		||||
        yy--
 | 
			
		||||
        horizontal_line(xcenter-yy, last_y3, yy*$0002+1, draw)
 | 
			
		||||
        horizontal_line(xcenter-yy, last_y4, yy*$0002+1, draw)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    sub safe_disc(uword @zp xcenter, uword @zp ycenter, ubyte @zp radius, bool draw) {
 | 
			
		||||
@@ -340,23 +324,11 @@ monogfx {
 | 
			
		||||
            return
 | 
			
		||||
        ubyte @zp yy = 0
 | 
			
		||||
        word @zp decisionOver2 = (1 as word)-radius
 | 
			
		||||
        uword last_y3 = ycenter+radius
 | 
			
		||||
        uword last_y4 = ycenter-radius
 | 
			
		||||
        uword new_y3, new_y4
 | 
			
		||||
 | 
			
		||||
        while radius>=yy {
 | 
			
		||||
            safe_horizontal_line(xcenter-radius, ycenter+yy, radius*$0002+1, draw)
 | 
			
		||||
            safe_horizontal_line(xcenter-radius, ycenter-yy, radius*$0002+1, draw)
 | 
			
		||||
            new_y3 = ycenter+radius
 | 
			
		||||
            if new_y3 != last_y3 {
 | 
			
		||||
                safe_horizontal_line(xcenter-yy, last_y3, yy*$0002+1, draw)
 | 
			
		||||
                last_y3 = new_y3
 | 
			
		||||
            }
 | 
			
		||||
            new_y4 = ycenter-radius
 | 
			
		||||
            if new_y4 != last_y4 {
 | 
			
		||||
                safe_horizontal_line(xcenter-yy, last_y4, yy*$0002+1, draw)
 | 
			
		||||
                last_y4 = new_y4
 | 
			
		||||
            }
 | 
			
		||||
            safe_horizontal_line(xcenter-yy, ycenter+radius, yy*$0002+1, draw)
 | 
			
		||||
            safe_horizontal_line(xcenter-yy, ycenter-radius, yy*$0002+1, draw)
 | 
			
		||||
            yy++
 | 
			
		||||
            if decisionOver2>=0 {
 | 
			
		||||
                radius--
 | 
			
		||||
@@ -365,10 +337,6 @@ monogfx {
 | 
			
		||||
            decisionOver2 += yy*$0002
 | 
			
		||||
            decisionOver2++
 | 
			
		||||
        }
 | 
			
		||||
        ; draw the final two spans
 | 
			
		||||
        yy--
 | 
			
		||||
        safe_horizontal_line(xcenter-yy, last_y3, yy*$0002+1, draw)
 | 
			
		||||
        safe_horizontal_line(xcenter-yy, last_y4, yy*$0002+1, draw)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    sub plot(uword @zp xx, uword @zp yy, bool @zp draw) {
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,7 @@ TODO
 | 
			
		||||
====
 | 
			
		||||
 | 
			
		||||
check the accuracy of the various disc routines (filled circles), they seem less accurate than the circle routine  (virt monogfx)
 | 
			
		||||
check disc and circle draw in paint
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
LONG TYPE
 | 
			
		||||
 
 | 
			
		||||
@@ -1,42 +1,16 @@
 | 
			
		||||
%import graphics
 | 
			
		||||
%import monogfx
 | 
			
		||||
 | 
			
		||||
main {
 | 
			
		||||
    sub start() {
 | 
			
		||||
        graphics.enable_bitmap_mode()
 | 
			
		||||
        monogfx.lores()
 | 
			
		||||
 | 
			
		||||
        uword radius
 | 
			
		||||
        for radius in 1 to 10 {
 | 
			
		||||
            graphics.circle(30*radius, 100, lsb(radius))
 | 
			
		||||
            graphics.disc(30*radius, 130, lsb(radius))
 | 
			
		||||
            mydisc(30*radius, 160, lsb(radius))
 | 
			
		||||
            monogfx.circle(30*radius, 100, lsb(radius), true)
 | 
			
		||||
            monogfx.disc(30*radius, 130, lsb(radius), true)
 | 
			
		||||
            monogfx.safe_disc(30*radius, 160, lsb(radius), true)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        repeat {}
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    sub mydisc(uword xcenter, ubyte ycenter, ubyte radius) {
 | 
			
		||||
        ; Warning: NO BOUNDS CHECKS. Make sure circle fits in the screen.
 | 
			
		||||
        ; Midpoint algorithm.
 | 
			
		||||
        if radius==0
 | 
			
		||||
            return
 | 
			
		||||
        ubyte @zp ploty
 | 
			
		||||
        ubyte @zp yy = 0
 | 
			
		||||
        word @zp decisionOver2 = (1 as word)-radius
 | 
			
		||||
 | 
			
		||||
        while radius>=yy {
 | 
			
		||||
            graphics.horizontal_line(xcenter-radius, ycenter+yy, radius*2+1)
 | 
			
		||||
            graphics.horizontal_line(xcenter-radius, ycenter-yy, radius*2+1)
 | 
			
		||||
            graphics.horizontal_line(xcenter-yy, ycenter+radius, yy*2+1)
 | 
			
		||||
            graphics.horizontal_line(xcenter-yy, ycenter-radius, yy*2+1)
 | 
			
		||||
 | 
			
		||||
            yy++
 | 
			
		||||
            if decisionOver2>=0 {
 | 
			
		||||
                radius--
 | 
			
		||||
                decisionOver2 -= radius*$0002
 | 
			
		||||
            }
 | 
			
		||||
            decisionOver2 += yy*$0002
 | 
			
		||||
            decisionOver2++
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user