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).




 
//  Draw a circle using Bresenham's circle algorithm.
//  #21 = center x, #22 = center y; #23 = radius
 
:DRAW_CIRCLE:
#30 = 1 - #23		// f
#31 = 0			// ddF_x
#32 = -2 * #23		// ddF_y
#41 = 0			// x
#42 = #23		// y
 
while (#41 <= #42) {
    #1 = #21+#41; #2 = #22+#42; Call("DRAW_PIXEL")
    #1 = #21-#41; #2 = #22+#42; Call("DRAW_PIXEL")
    #1 = #21+#41; #2 = #22-#42; Call("DRAW_PIXEL")
    #1 = #21-#41; #2 = #22-#42; Call("DRAW_PIXEL")
    #1 = #21+#42; #2 = #22+#41; Call("DRAW_PIXEL")
    #1 = #21-#42; #2 = #22+#41; Call("DRAW_PIXEL")
    #1 = #21+#42; #2 = #22-#41; Call("DRAW_PIXEL")
    #1 = #21-#42; #2 = #22-#41; Call("DRAW_PIXEL")
    if (#30 >= 0) {
	#42--
	#32 += 2
	#30 += #32
    }
    #41++
    #31 += 2
    #30 += #31 + 1
}
 
return
 