Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View file

@ -0,0 +1,35 @@
procedure Circle
( Picture : in out Image;
Center : Point;
Radius : Natural;
Color : Pixel
) is
F : Integer := 1 - Radius;
ddF_X : Integer := 0;
ddF_Y : Integer := -2 * Radius;
X : Integer := 0;
Y : Integer := Radius;
begin
Picture (Center.X, Center.Y + Radius) := Color;
Picture (Center.X, Center.Y - Radius) := Color;
Picture (Center.X + Radius, Center.Y) := Color;
Picture (Center.X - Radius, Center.Y) := Color;
while X < Y loop
if F >= 0 then
Y := Y - 1;
ddF_Y := ddF_Y + 2;
F := F + ddF_Y;
end if;
X := X + 1;
ddF_X := ddF_X + 2;
F := F + ddF_X + 1;
Picture (Center.X + X, Center.Y + Y) := Color;
Picture (Center.X - X, Center.Y + Y) := Color;
Picture (Center.X + X, Center.Y - Y) := Color;
Picture (Center.X - X, Center.Y - Y) := Color;
Picture (Center.X + Y, Center.Y + X) := Color;
Picture (Center.X - Y, Center.Y + X) := Color;
Picture (Center.X + Y, Center.Y - X) := Color;
Picture (Center.X - Y, Center.Y - X) := Color;
end loop;
end Circle;

View file

@ -0,0 +1,5 @@
X : Image (1..16, 1..16);
begin
Fill (X, White);
Circle (X, (8, 8), 5, Black);
Print (X);

View file

@ -7,33 +7,33 @@ color blue
call DrawCircle(200,200,50)
refresh
#Function DrawCircle
#1st param = X-coord of center
#2nd param = Y-coord of center
#3rd param = radius
#Function DrawCircle
#1st param = X-coord of center
#2nd param = Y-coord of center
#3rd param = radius
Function DrawCircle(x0,y0,radius)
x=radius
y=0
decisionOver2=1-x
x=radius
y=0
decisionOver2=1-x
while x>=y
plot( x + x0, y + y0)
plot( y + x0, x + y0)
plot(-x + x0, y + y0)
plot(-y + x0, x + y0)
plot(-x + x0, -y + y0)
plot(-y + x0, -x + y0)
plot( x + x0, -y + y0)
plot( y + x0, -x + y0)
while x>=y
plot( x + x0, y + y0)
plot( y + x0, x + y0)
plot(-x + x0, y + y0)
plot(-y + x0, x + y0)
plot(-x + x0, -y + y0)
plot(-y + x0, -x + y0)
plot( x + x0, -y + y0)
plot( y + x0, -x + y0)
y++
y++
if decisionOver2<=0 then
decisionOver2+=2*y+1
else
x--
decisionOver2+=2*(y-x)+1
end if
end while
return 0
if decisionOver2<=0 then
decisionOver2+=2*y+1
else
x--
decisionOver2+=2*(y-x)+1
end if
end while
return 0
End Function

View file

@ -1,7 +1,7 @@
@echo off
setlocal enabledelayedexpansion
%== Initializations ==%
%== Initializations ==%
set width=50
set height=30
@ -11,62 +11,62 @@ echo Rendering...
set "outp="
for /l %%i in (1,1,%height%) do (
for /l %%j in (1,1,%width%) do (
set "c[%%i][%%j]= "
)
for /l %%j in (1,1,%width%) do (
set "c[%%i][%%j]= "
)
)
%== Set the parameters for making circle ==%
%== Set the parameters for making circle ==%
call :DrawCircle 20 20 10
call :DrawCircle 10 30 15
%== Output result ==%
%== Output result ==%
for /l %%i in (1,1,%height%) do (
for /l %%j in (1,1,%width%) do (
set "outp=!outp!!c[%%i][%%j]!"
)
for /l %%j in (1,1,%width%) do (
set "outp=!outp!!c[%%i][%%j]!"
)
)
cls
echo !outp!
pause>nul
exit /b
%== The main function ==%
%== The main function ==%
:DrawCircle
set x0=%1
set y0=%2
set radius=%3
set x0=%1
set y0=%2
set radius=%3
set x=!radius!
set y=0
set /a decisionOver2 = 1 - !x!
set x=!radius!
set y=0
set /a decisionOver2 = 1 - !x!
:circle_loop
if !x! geq !y! (
set /a "hor=x + x0","ver=y + y0"
set "c[!hor!][!ver!]=Û"
set /a "hor=y + x0","ver=x + y0"
set "c[!hor!][!ver!]=Û"
set /a "hor=-x + x0","ver=y + y0"
set "c[!hor!][!ver!]=Û"
set /a "hor=-y + x0","ver=x + y0"
set "c[!hor!][!ver!]=Û"
set /a "hor=-x + x0","ver=-y + y0"
set "c[!hor!][!ver!]=Û"
set /a "hor=-y + x0","ver=-x + y0"
set "c[!hor!][!ver!]=Û"
set /a "hor=x + x0","ver=-y + y0"
set "c[!hor!][!ver!]=Û"
set /a "hor=y + x0","ver=-x + y0"
set "c[!hor!][!ver!]=Û"
:circle_loop
if !x! geq !y! (
set /a "hor=x + x0","ver=y + y0"
set "c[!hor!][!ver!]=Û"
set /a "hor=y + x0","ver=x + y0"
set "c[!hor!][!ver!]=Û"
set /a "hor=-x + x0","ver=y + y0"
set "c[!hor!][!ver!]=Û"
set /a "hor=-y + x0","ver=x + y0"
set "c[!hor!][!ver!]=Û"
set /a "hor=-x + x0","ver=-y + y0"
set "c[!hor!][!ver!]=Û"
set /a "hor=-y + x0","ver=-x + y0"
set "c[!hor!][!ver!]=Û"
set /a "hor=x + x0","ver=-y + y0"
set "c[!hor!][!ver!]=Û"
set /a "hor=y + x0","ver=-x + y0"
set "c[!hor!][!ver!]=Û"
set /a y+=1
if !decisionOver2! leq 0 (
set /a "decisionOver2 = !decisionOver2! + (2 * y^) + 1"
) else (
set /a x-=1
set /a "decisionOver2 = !decisionOver2! + 2 * (y - x^) + 1"
)
goto circle_loop
)
set /a y+=1
if !decisionOver2! leq 0 (
set /a "decisionOver2 = !decisionOver2! + (2 * y^) + 1"
) else (
set /a x-=1
set /a "decisionOver2 = !decisionOver2! + 2 * (y - x^) + 1"
)
goto circle_loop
)
goto :EOF

View file

@ -0,0 +1,40 @@
require "./pixmap"
require "./bresenham"
class Pixmap
def circle (cx, cy, r, color, fill = false)
f = 1 - r
ddF_X = 0
ddF_Y = -2 * r
x = 0
y = r
self[cx, cy + r] = color
self[cx, cy - r] = color
p1, p2 = {cx + r, cy}, {cx - r, cy}
if fill
line(*p1, *p2, color)
else
self[*p1] = self[*p2] = color
end
while x < y
if f >= 0
y -= 1
ddF_Y += 2
f += ddF_Y
end
x += 1
ddF_X += 2
f += ddF_X + 1
[{cx - x, cy - y}, {cx + x, cy - y},
{cx - x, cy + y}, {cx + x, cy + y},
{cx - y, cy - x}, {cx + y, cy - x},
{cx - y, cy + x}, {cx + y, cy + x}].each_slice(2, reuse: true) do |(p1, p2)|
if fill
line(*p1, *p2, color)
else
self[*p1] = self[*p2] = color
end
end
end
end
end

View file

@ -0,0 +1,12 @@
require "./circle"
require "./write_ppm"
img = Pixmap.new 100, 100, Color::WHITE
img.circle 50, 50, 40, Color::RED, true
img.circle 70, 60, 15, Color::BLUE, true
img.circle 40, 20, 20, Color::BLACK
img.circle 40, 20, 19, Color.new(255, 144, 0)
img.circle 40, 20, 18, Color::BLACK
img.write "crystal_circles.ppm"

View file

@ -3,18 +3,18 @@ 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;
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;
@ -22,18 +22,18 @@ 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
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;

View file

@ -13,29 +13,29 @@ DIM Breadth AS INTEGER, Height AS INTEGER
FBSL.GETCLIENTRECT(ME, 0, 0, Breadth, Height)
BEGIN EVENTS ' Main message loop
SELECT CASE CBMSG
CASE WM_LBUTTONDOWN: MidpointCircle() ' Draw
CASE WM_CLOSE: FBSL.RELEASEDC(ME, FBSL.GETDC) ' Clean up
END SELECT
SELECT CASE CBMSG
CASE WM_LBUTTONDOWN: MidpointCircle() ' Draw
CASE WM_CLOSE: FBSL.RELEASEDC(ME, FBSL.GETDC) ' Clean up
END SELECT
END EVENTS
SUB MidpointCircle()
BresenhamCircle(Breadth \ 2, Height \ 2, 80, &HFF) ' Red: Windows stores colors in BGR order
BresenhamCircle(Breadth \ 2, Height \ 2, 40, 0) ' Black
SUB BresenhamCircle(cx, cy, radius, colour)
DIM x = 0, y = radius, f = 1 - radius, dx = 0, dy = -2 * radius
PSET(FBSL.GETDC, cx, cy + radius, colour)(FBSL.GETDC, cx, cy - radius, colour)
PSET(FBSL.GETDC, cx + radius, cy, colour)(FBSL.GETDC, cx - radius, cy, colour)
WHILE x < y
IF f >= 0 THEN: DECR(y): INCR(dy, 2)(f, dy): END IF ' Try also "IF f THEN" :)
INCR(x)(dx, 2)(f, dx + 1)
PSET(FBSL.GETDC, cx + x, cy + y, colour)(FBSL.GETDC, cx - x, cy + y, colour)
PSET(FBSL.GETDC, cx + x, cy - y, colour)(FBSL.GETDC, cx - x, cy - y, colour)
PSET(FBSL.GETDC, cx + y, cy + x, colour)(FBSL.GETDC, cx - y, cy + x, colour)
PSET(FBSL.GETDC, cx + y, cy - x, colour)(FBSL.GETDC, cx - y, cy - x, colour)
WEND
END SUB
BresenhamCircle(Breadth \ 2, Height \ 2, 80, &HFF) ' Red: Windows stores colors in BGR order
BresenhamCircle(Breadth \ 2, Height \ 2, 40, 0) ' Black
SUB BresenhamCircle(cx, cy, radius, colour)
DIM x = 0, y = radius, f = 1 - radius, dx = 0, dy = -2 * radius
PSET(FBSL.GETDC, cx, cy + radius, colour)(FBSL.GETDC, cx, cy - radius, colour)
PSET(FBSL.GETDC, cx + radius, cy, colour)(FBSL.GETDC, cx - radius, cy, colour)
WHILE x < y
IF f >= 0 THEN: DECR(y): INCR(dy, 2)(f, dy): END IF ' Try also "IF f THEN" :)
INCR(x)(dx, 2)(f, dx + 1)
PSET(FBSL.GETDC, cx + x, cy + y, colour)(FBSL.GETDC, cx - x, cy + y, colour)
PSET(FBSL.GETDC, cx + x, cy - y, colour)(FBSL.GETDC, cx - x, cy - y, colour)
PSET(FBSL.GETDC, cx + y, cy + x, colour)(FBSL.GETDC, cx - y, cy + x, colour)
PSET(FBSL.GETDC, cx + y, cy - x, colour)(FBSL.GETDC, cx - y, cy - x, colour)
WEND
END SUB
END SUB

View file

@ -1,35 +1,35 @@
import java.awt.Color;
public class MidPointCircle {
private BasicBitmapStorage image;
private BasicBitmapStorage image;
public MidPointCircle(final int imageWidth, final int imageHeight) {
this.image = new BasicBitmapStorage(imageWidth, imageHeight);
}
public MidPointCircle(final int imageWidth, final int imageHeight) {
this.image = new BasicBitmapStorage(imageWidth, imageHeight);
}
private void drawCircle(final int centerX, final int centerY, final int radius) {
int d = (5 - radius * 4)/4;
int x = 0;
int y = radius;
Color circleColor = Color.white;
private void drawCircle(final int centerX, final int centerY, final int radius) {
int d = (5 - radius * 4)/4;
int x = 0;
int y = radius;
Color circleColor = Color.white;
do {
image.setPixel(centerX + x, centerY + y, circleColor);
image.setPixel(centerX + x, centerY - y, circleColor);
image.setPixel(centerX - x, centerY + y, circleColor);
image.setPixel(centerX - x, centerY - y, circleColor);
image.setPixel(centerX + y, centerY + x, circleColor);
image.setPixel(centerX + y, centerY - x, circleColor);
image.setPixel(centerX - y, centerY + x, circleColor);
image.setPixel(centerX - y, centerY - x, circleColor);
if (d < 0) {
d += 2 * x + 1;
} else {
d += 2 * (x - y) + 1;
y--;
}
x++;
} while (x <= y);
do {
image.setPixel(centerX + x, centerY + y, circleColor);
image.setPixel(centerX + x, centerY - y, circleColor);
image.setPixel(centerX - x, centerY + y, circleColor);
image.setPixel(centerX - x, centerY - y, circleColor);
image.setPixel(centerX + y, centerY + x, circleColor);
image.setPixel(centerX + y, centerY - x, circleColor);
image.setPixel(centerX - y, centerY + x, circleColor);
image.setPixel(centerX - y, centerY - x, circleColor);
if (d < 0) {
d += 2 * x + 1;
} else {
d += 2 * (x - y) + 1;
y--;
}
x++;
} while (x <= y);
}
}
}

View file

@ -0,0 +1,33 @@
local canvas = require "canvas"
local function trunc(x) return x >= 0 ? math.floor(x) : math.ceil(x) end
local function circle(c, cx, cy, r, col)
local d = trunc((5 - r * 4) / 4)
local x = 0
local y = r
repeat
c:set(cx + x, cy + y, col)
c:set(cx + x, cy - y, col)
c:set(cx - x, cy + y, col)
c:set(cx - x, cy - y, col)
c:set(cx + y, cy + x, col)
c:set(cx + y, cy - x, col)
c:set(cx - y, cy + x, col)
c:set(cx - y, cy - x, col)
if d < 0 then
d += 2 * x + 1
else
d += 2 * (x - y) + 1
y -= 1
end
++x
until x > y
end
local c = canvas.new(400, 400)
c:fill(0xffffff) -- white background
-- Draw a blue circle with centre at (200, 200) and radius 100.
circle(c, 200, 200, 100, 0xff0000)
io.contents("mybmp.bmp", c:tobmp()) -- save to a bitmap file

View file

@ -0,0 +1,6 @@
require "bitmap"
local bmp = bitmap.of(400, 400, color.white, "mybmp")
bmp:circle(200, 200, 100, color.blue)
bmp:view()
bmp:save() -- if required

View file

@ -0,0 +1,49 @@
Rebol [
title: "Rosetta code: Bitmap/Midpoint circle algorithm"
file: %Bitmap-Midpoint_circle_algorithm.r3
url: https://rosettacode.org/wiki/Bitmap/Midpoint_circle_algorithm
]
draw-circle: func [
"Draw a circle on an image using the Midpoint Circle Algorithm."
bitmap [image!] center [pair!] radius [integer!] color [tuple!]
][
x: center/x ;; unpack center coords from pair for arithmetic
y: center/y
dx: radius dy: 0
err: 1 - radius ;; initial error term for midpoint decision
while [dx >= dy] [ ;; iterate through the first octant only
;; Mirror the single computed point into all 8 octants at once,
;; exploiting the 8-fold symmetry of the circle.
bitmap/(as-pair x + dx y + dy): color ; octant 1
bitmap/(as-pair x - dx y + dy): color ; octant 2
bitmap/(as-pair x + dx y - dy): color ; octant 8
bitmap/(as-pair x - dx y - dy): color ; octant 7
bitmap/(as-pair x + dy y + dx): color ; octant 3
bitmap/(as-pair x - dy y + dx): color ; octant 4 (swapped dx/dy)
bitmap/(as-pair x + dy y - dx): color ; octant 5
bitmap/(as-pair x - dy y - dx): color ; octant 6
dy: dy + 1 ;; advance one step along the minor axis
;; Update the error term and conditionally step inward on dx.
;; err < 0 means we are still inside the circle boundary
either err < 0 [
err: err + (2 * dy) + 1 ;; correct error for dy step
][
dx: dx - 1 ;; step inward on major axis
err: err + (2 * (dy - dx)) + 1 ;; correct error for both steps
]
]
]
img: make image! 29x29 ;; create a blank 29x29 canvas (white by default)
draw-circle img 15x15 5 black ;; small inner circle
draw-circle img 15x15 10 red ;; mid-size red ring
draw-circle img 15x15 14 green ;; large green ring, nearly fills the canvas
;; scale up 10x with nearest-neighbour (Box) to keep pixel edges sharp
img: resize/filter img 290 'Box
save %midpoint-circles.png img
try [view img]

View file

@ -22,7 +22,7 @@ object BitmapOps {
x+=1
ddF_x+=2
f+=ddF_x
bm.setPixel(x0+x, y0+y, c)
bm.setPixel(x0-x, y0+y, c)
bm.setPixel(x0+x, y0-y, c)

View file

@ -13,10 +13,10 @@ function drawcircle {
for y in $( seq $((y0-radius)) $((y0+radius)) )
do
echo -en "\e[${y}H"
for x in $( seq $((x0+radius)) )
do
echo -n "-"
done
for x in $( seq $((x0+radius)) )
do
echo -n "-"
done
done
x=$((radius-1))
@ -38,12 +38,12 @@ function drawcircle {
if [ $err -le 0 ]
then
((++y))
((++y))
((err+=dy))
((dy+=2))
fi
if [ $err -gt 0 ]
then
then
((--x))
((dx+=2))
((err+=dx-(radius<<1)))

View file

@ -2,11 +2,11 @@
// #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
#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")
@ -18,9 +18,9 @@ while (#41 <= #42) {
#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
#42--
#32 += 2
#30 += #32
}
#41++
#31 += 2

View file

@ -2,15 +2,15 @@
x:=r; y:=0; radiusError:=1-x;
while(x >= y){
__sSet(rgb, x + x0, y + y0);
__sSet(rgb, y + x0, x + y0);
__sSet(rgb,-x + x0, y + y0);
__sSet(rgb,-y + x0, x + y0);
self[-x + x0, -y + y0]=rgb; // or do it this way, __sSet gets called as above
self[-y + x0, -x + y0]=rgb;
self[ x + x0, -y + y0]=rgb;
self[ y + x0, -x + y0]=rgb;
y+=1;
if (radiusError<0) radiusError+=2*y + 1;
else{ x-=1; radiusError+=2*(y - x + 1); }
__sSet(rgb, y + x0, x + y0);
__sSet(rgb,-x + x0, y + y0);
__sSet(rgb,-y + x0, x + y0);
self[-x + x0, -y + y0]=rgb; // or do it this way, __sSet gets called as above
self[-y + x0, -x + y0]=rgb;
self[ x + x0, -y + y0]=rgb;
self[ y + x0, -x + y0]=rgb;
y+=1;
if (radiusError<0) radiusError+=2*y + 1;
else{ x-=1; radiusError+=2*(y - x + 1); }
}
}