Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,49 @@
import bitmap
proc setPixel(img: Image; x, y: int; color: Color) {.inline.} =
# Set a pixel at a given color.
# Ignore if the point is outside of the image.
if x in 0..<img.w and y in 0..<img.h:
img[x, y] = color
proc drawCircle(img: Image; center: Point; radius: Natural; color: Color) =
## Draw a circle using midpoint circle algorithm.
var
f = 1 - radius
ddFX = 0
ddFY = -2 * radius
x = 0
y = radius
img.setPixel(center.x, center.y + radius, color)
img.setPixel(center.x, center.y - radius, color)
img.setPixel(center.x + radius, center.y, color)
img.setPixel(center.x - radius, center.y, color)
while x < y:
if f >= 0:
dec y
inc ddFY, 2
inc f, ddFY
inc x
inc ddFX, 2
inc f, ddFX + 1
img.setPixel(center.x + x, center.y + y, color)
img.setPixel(center.x - x, center.y + y, color)
img.setPixel(center.x + x, center.y - y, color)
img.setPixel(center.x - x, center.y - y, color)
img.setPixel(center.x + y, center.y + x, color)
img.setPixel(center.x - y, center.y + x, color)
img.setPixel(center.x + y, center.y - x, color)
img.setPixel(center.x - y, center.y - x, color)
#———————————————————————————————————————————————————————————————————————————————————————————————————
when isMainModule:
var img = newImage(16, 16)
img.fill(White)
img.drawCircle((7, 7), 5, Black)
img.print()

View file

@ -0,0 +1,27 @@
let raster_circle ~img ~color ~c:(x0, y0) ~r =
let plot = put_pixel img color in
let x = 0
and y = r
and m = 5 - 4 * r
in
let rec loop x y m =
plot (x0 + x) (y0 + y);
plot (x0 + y) (y0 + x);
plot (x0 - x) (y0 + y);
plot (x0 - y) (y0 + x);
plot (x0 + x) (y0 - y);
plot (x0 + y) (y0 - x);
plot (x0 - x) (y0 - y);
plot (x0 - y) (y0 - x);
let y, m =
if m > 0
then (y - 1), (m - 8 * y)
else y, m
in
if x <= y then
let x = x + 1 in
let m = m + 8 * x + 4 in
loop x y m
in
loop x y m
;;