Bitmap/Midpoint circle algorithm: Difference between revisions
Content added Content deleted
(Opps) |
(→{{header|zkl}}: update) |
||
Line 1,550: | Line 1,550: | ||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
Image cribbed from the BBC BASIC entry. Algorithm from Wikipedia article. |
Image cribbed from the BBC BASIC entry. Algorithm from Wikipedia article.<br/> |
||
Uses the PPM class from http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#zkl |
|||
[[Image:circle_bbc.gif|right]] |
[[Image:circle_bbc.gif|right]] |
||
This is the code from the PPM class: |
|||
<lang zkl>class PPM{ |
|||
fcn |
<lang zkl> fcn circle(x0,y0,r,rgb){ |
||
sz:=width*height; |
|||
var [const] |
|||
data=sz.pump(Data(sz*3),T(Void,rgb.toBigEndian(3))), // initialize to Black (RGB=000) |
|||
w=width, h=height; |
|||
} |
|||
fcn fill(rgb){ |
|||
sz:=data.len()/3; |
|||
data.clear(); sz.pump(data,T(Void,rgb.toBigEndian(3))); |
|||
} |
|||
fcn __sGet(x,y) { data.toBigEndian(3*y*w + 3*x,3); } //ppm[x,y] |
|||
fcn __sSet(rbg,x,y){ data[3*y*w + 3*x,3]=rbg.toBigEndian(3); } //ppm[x,y]=rgb |
|||
fcn write(out){ |
|||
out.write("P6\n#rosettacode PPM\n%d %d\n255\n".fmt(w,h)); |
|||
out.write(data); |
|||
} |
|||
fcn circle(x0,y0,r,rgb){ |
|||
x:=r; y:=0; radiusError:=1-x; |
x:=r; y:=0; radiusError:=1-x; |
||
while(x >= y){ |
while(x >= y){ |
||
Line 1,584: | Line 1,569: | ||
else{ x-=1; radiusError+=2*(y - x + 1); } |
else{ x-=1; radiusError+=2*(y - x + 1); } |
||
} |
} |
||
} |
}</lang> |
||
}</lang> |
|||
<lang zkl>ppm:=PPM(200,200,0xFF|FF|FF); |
<lang zkl>ppm:=PPM(200,200,0xFF|FF|FF); |
||
ppm.circle(100,100,40,00); // black circle |
ppm.circle(100,100,40,00); // black circle |