Bitmap/Midpoint circle algorithm: Difference between revisions

Content added Content deleted
m (Regularize non-standard header markup)
m (→‎{{header|Phix}}: minor tidy)
Line 1,523: Line 1,523:
=={{header|Phix}}==
=={{header|Phix}}==
{{Trans|Go}}
{{Trans|Go}}
Requires new_image() from [[Bitmap#Phix|Bitmap]], write_ppm() from [[Bitmap/Write_a_PPM_file#Phix|Write_a_PPM_file]].
Requires new_image() from [[Bitmap#Phix|Bitmap]], write_ppm() from [[Bitmap/Write_a_PPM_file#Phix|Write_a_PPM_file]]. <br>
Included as demo\rosetta\Bitmap_Circle.exw, results may be verified with demo\rosetta\viewppm.exw
Results may be verified with demo\rosetta\viewppm.exw
<lang Phix>-- demo\rosetta\Bitmap_Circle.exw (runnable version)
<lang Phix>constant red = 0xff2020,
include ppm.e -- red, yellow, new_image(), write_ppm() -- (covers above requirements)
yellow = 0xffdf20


function SetPx(sequence img, atom x, atom y, integer colour)
function SetPx(sequence img, atom x, y, integer colour)
if x>=1 and x<=length(img)
if x>=1 and x<=length(img)
and y>=1 and y<=length(img[x]) then
and y>=1 and y<=length(img[x]) then
img[x][y] = colour
img[x][y] = colour
Line 1,536: Line 1,536:
end function
end function


function Circle(sequence img, atom x, atom y, atom r, integer colour)
function Circle(sequence img, atom x, y, r, integer colour)
atom x1 = -r,
atom x1 = -r,
y1 = 0,
y1 = 0,
err = 2-2*r
err = 2-2*r
if r>=0 then
if r>=0 then
-- Bresenham algorithm
-- Bresenham algorithm
Line 1,563: Line 1,563:


sequence img = new_image(400,300,yellow)
sequence img = new_image(400,300,yellow)
img = Circle(img, 200, 150, 100, red)
img = Circle(img, 200, 150, 100, red)
write_ppm("Circle.ppm",img)</lang>
write_ppm("Circle.ppm",img)</lang>


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==