Bitmap/Midpoint circle algorithm: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (BASIC256 moved to the BASIC section.)
m (→‎{{header|Wren}}: Changed to Wren S/H)
(5 intermediate revisions by 3 users not shown)
Line 329:
360 FOR I = 0 TO 1: IF F > = 0 THEN Y = Y - 1:DY = DY + 2:F = F + DY
370 X = X + 1:DX = DX + 2:F = F + DX + 1: HLIN CX - X,CX + X AT CY + Y: HLIN CX - X,CX + X AT CY - Y: HLIN CX - Y,CX + Y AT CY + X: HLIN CX - Y,CX + Y AT CY - X:I = X > = Y: NEXT I: RETURN</syntaxhighlight>
=={{header|ATS}}==
See [[Bresenham_tasks_in_ATS]].
 
=={{header|bash}}==
<syntaxhighlight lang="bash">#! /bin/bash
Line 409 ⟶ 412:
----##---------##----
------#########------</pre>
 
=={{header|BASIC}}==
==={{header|BASIC256}}===
Line 908 ⟶ 912:
.......##.......##.......
.........#######.........</pre>
 
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
[[File:DelphiBrezCircle.png|frame|none]]
 
 
<syntaxhighlight lang="Delphi">
 
 
procedure DrawCircle(Image: TImage; Radius: integer; Center: TPoint);
var T1,T2: integer;
var X,Y: integer;
var Cnt: integer;
 
procedure DrawPixels(X,Y: integer);
{Draw pixel into all 8 octents}
begin
Image.Canvas.Pixels[Center.X + x, Center.Y + y]:=clRed;
Image.Canvas.Pixels[Center.X - X, Center.Y + Y]:=clRed;
Image.Canvas.Pixels[Center.X + X, Center.Y - Y]:=clRed;
Image.Canvas.Pixels[Center.X - X, Center.Y - Y]:=clRed;
Image.Canvas.Pixels[Center.X + Y, Center.Y + X]:=clRed;
Image.Canvas.Pixels[Center.X - Y, Center.Y + X]:=clRed;
Image.Canvas.Pixels[Center.X + y, Center.Y - X]:=clRed;
Image.Canvas.Pixels[Center.X - Y, Center.Y - X]:=clRed;
end;
 
begin
Cnt:=0;
T1:= Radius div 32;
{Start on X-axis}
X:= Radius; Y:= 0;
repeat
begin
DrawPixels(X, Y);
Y:=Y + 1;
T1:=T1 + Y;
T2:=T1 - X;
if T2 >= 0 then
begin
T1:=T2;
X:=X - 1;
end;
Inc(Cnt);
end
until x < y;
Form1.Caption:=IntToStr(Cnt);
end;
 
 
 
procedure ShowBrezCircle(Image: TImage);
begin
{Draw three times to make line thicker}
DrawCircle(Image,100,Point(200,200));
DrawCircle(Image,99,Point(200,200));
DrawCircle(Image,98,Point(200,200));
Image.Invalidate;
end;
 
 
</syntaxhighlight>
{{out}}
<pre>
Elapsed Time: 7.341 ms.
</pre>
 
=={{header|ERRE}}==
<syntaxhighlight lang="erre">PROGRAM BCircle
Line 947 ⟶ 1,020:
END PROGRAM
</syntaxhighlight>
 
=={{header|Evaldraw}}==
Gives slightly faster (in some cases), but more importantly prettier circles than the builtin drawsph(x,y,-rad) function.
<syntaxhighlight lang="C">()
{
cls(0);
setcol(0xffffff);
srand(1234);
for(i=0; i<1000; i++) {
rad = int( abs(nrnd*10) );
x=rnd*xres;
y=rnd*yres;
drawcircle(x,y,rad);
//drawsph(x,y,-rad);
}
}
 
drawcircle(cx,cy,r) {
if (cx+r < 0 || cy+r < 0) return;
if (cx-r > xres || cy-r > yres) return;
r = int(r);
if (r<=0) return;
r2 = r+r;
x = r; y = 0;
dy = -2; dx = r2+r2 - 4;
d = r2-1;
while(y<=x) {
setpix(cx-x, cy-y);
setpix(cx+x, cy-y);
setpix(cx-x, cy+y);
setpix(cx+x, cy+y);
setpix(cx-y, cy-x);
setpix(cx+y, cy-x);
setpix(cx-y, cy+x);
setpix(cx+y, cy+x);
d += dy;
dy -= 4;
++y;
if (d<0) {
d += dx;
dx -= 4;
--x;
}
}
}</syntaxhighlight>
 
=={{header|FBSL}}==
'''Using pure FBSL's built-in graphics functions:'''
Line 2,486 ⟶ 2,605:
{{trans|Kotlin}}
{{libheader|DOME}}
<syntaxhighlight lang="ecmascriptwren">import "graphics" for Canvas, Color, ImageData
import "dome" for Window
 
Line 2,546 ⟶ 2,665:
 
var Game = MidpointCircle.new(400, 400)</syntaxhighlight>
 
=={{header|XPL0}}==
<syntaxhighlight lang="xpl0">include c:\cxpl\codes; \include 'code' declarations
9,485

edits