From 9aff280d10496be1bac3d76f45bb6799942f6ecc Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sun, 5 Oct 2025 23:03:53 +0200 Subject: [PATCH] fix monogfx.disc() inaccurracy --- compiler/res/prog8lib/cx16/monogfx.p8 | 38 +++------------------- compiler/res/prog8lib/virtual/monogfx.p8 | 40 +++--------------------- docs/source/todo.rst | 1 + examples/test.p8 | 36 +++------------------ 4 files changed, 14 insertions(+), 101 deletions(-) diff --git a/compiler/res/prog8lib/cx16/monogfx.p8 b/compiler/res/prog8lib/cx16/monogfx.p8 index bff9d8b49..b23f489bc 100644 --- a/compiler/res/prog8lib/cx16/monogfx.p8 +++ b/compiler/res/prog8lib/cx16/monogfx.p8 @@ -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) { diff --git a/compiler/res/prog8lib/virtual/monogfx.p8 b/compiler/res/prog8lib/virtual/monogfx.p8 index 30e1772ab..0b43d0e41 100644 --- a/compiler/res/prog8lib/virtual/monogfx.p8 +++ b/compiler/res/prog8lib/virtual/monogfx.p8 @@ -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) { diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 8d74f2710..6df36f9ee 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -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 diff --git a/examples/test.p8 b/examples/test.p8 index 0fad7cc27..d55f61056 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -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++ - } - } - }