fix circle and disc geometry, added rect and line routines

This commit is contained in:
Irmen de Jong 2020-12-29 23:46:48 +01:00
parent e09b65ea94
commit 64c89f1c8f

View File

@ -36,6 +36,24 @@ graphics {
cx16.GRAPH_draw_line(x1, y1, x2, y2)
}
sub fillrect(uword x, uword y, uword width, uword height) {
cx16.GRAPH_draw_rect(x, y, width, height, 0, 1)
}
sub rect(uword x, uword y, uword width, uword height) {
cx16.GRAPH_draw_rect(x, y, width, height, 0, 0)
}
sub horizontal_line(uword x, uword y, uword length) {
if length
cx16.GRAPH_draw_line(x, y, x+length-1, y)
}
sub vertical_line(uword x, uword y, uword height) {
if height
cx16.GRAPH_draw_line(x, y, x, y+height-1)
}
sub circle(uword xcenter, ubyte ycenter, ubyte radius) {
;cx16.r0 = xcenter - radius/2
;cx16.r1 = ycenter - radius/2
@ -48,7 +66,7 @@ graphics {
return
ubyte @zp xx = radius
ubyte @zp yy = 0
byte @zp decisionOver2 = 1-xx as byte
word @zp decisionOver2 = (1 as word)-xx
while xx>=yy {
cx16.r0 = xcenter + xx
@ -81,56 +99,50 @@ graphics {
cx16.FB_set_pixel(1)
yy++
if decisionOver2<=0 {
decisionOver2 += 2*yy+1
decisionOver2 += (yy as word)*2+1
} else {
xx--
decisionOver2 += 2*(yy-xx)+1
decisionOver2 += (yy as word -xx)*2+1
}
}
}
sub disc(uword xcenter, ubyte ycenter, ubyte radius) {
; cx16.r0 = xcenter - radius/2
; cx16.r1 = ycenter - radius/2
; cx16.r2 = radius*2
; cx16.r3 = radius*2
; cx16.GRAPH_draw_oval(true) ; currently this call is not implemented on cx16, does a BRK
if radius==0
return
ubyte @zp xx = radius
ubyte @zp yy = 0
byte decisionOver2 = 1-xx as byte
word decisionOver2 = (1 as word)-radius
while xx>=yy {
while radius>=yy {
ubyte ycenter_plus_yy = ycenter + yy
ubyte ycenter_min_yy = ycenter - yy
ubyte ycenter_plus_xx = ycenter + xx
ubyte ycenter_min_xx = ycenter - xx
ubyte ycenter_plus_radius = ycenter + radius
ubyte ycenter_min_radius = ycenter - radius
uword @zp plotx
cx16.FB_cursor_position(xcenter-xx, ycenter_plus_yy)
repeat xx*2+1
; cx16.GRAPH_draw_line(xcenter-radius, )
cx16.FB_cursor_position(xcenter-radius, ycenter_plus_yy)
repeat radius*2+1
cx16.FB_set_pixel(1)
cx16.FB_cursor_position(xcenter-xx, ycenter_min_yy)
repeat xx*2+1
cx16.FB_cursor_position(xcenter-radius, ycenter_min_yy)
repeat radius*2+1
cx16.FB_set_pixel(1)
cx16.FB_cursor_position(xcenter-yy, ycenter_plus_xx)
cx16.FB_cursor_position(xcenter-yy, ycenter_plus_radius)
repeat yy*2+1
cx16.FB_set_pixel(1)
cx16.FB_cursor_position(xcenter-yy, ycenter_min_xx)
cx16.FB_cursor_position(xcenter-yy, ycenter_min_radius)
repeat yy*2+1
cx16.FB_set_pixel(1)
yy++
if decisionOver2<=0
decisionOver2 += 2*yy+1
decisionOver2 += (yy as word)*2+1
else {
xx--
decisionOver2 += 2*(yy-xx)+1
radius--
decisionOver2 += (yy as word -radius)*2+1
}
}
}