A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
|
|
@ -0,0 +1,11 @@
|
|||
INTERFACE Circle;
|
||||
|
||||
IMPORT Bitmap;
|
||||
|
||||
PROCEDURE Draw(
|
||||
img: Bitmap.T;
|
||||
center: Bitmap.Point;
|
||||
radius: CARDINAL;
|
||||
color: Bitmap.Pixel);
|
||||
|
||||
END Circle.
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
MODULE Circle;
|
||||
|
||||
IMPORT Bitmap;
|
||||
|
||||
PROCEDURE Draw(
|
||||
img: Bitmap.T;
|
||||
center: Bitmap.Point;
|
||||
radius: CARDINAL;
|
||||
color: Bitmap.Pixel) =
|
||||
VAR f := 1 - radius;
|
||||
ddfx := 0;
|
||||
ddfy := - 2 * radius;
|
||||
x := 0;
|
||||
y := radius;
|
||||
BEGIN
|
||||
Bitmap.SetPixel(img, Bitmap.Point{center.x, center.y + radius}, color);
|
||||
Bitmap.SetPixel(img, Bitmap.Point{center.x, center.y - radius}, color);
|
||||
Bitmap.SetPixel(img, Bitmap.Point{center.x + radius, center.y}, color);
|
||||
Bitmap.SetPixel(img, Bitmap.Point{center.x - radius, center.y}, color);
|
||||
WHILE x < y DO
|
||||
IF f >= 0 THEN
|
||||
y := y - 1;
|
||||
ddfy := ddfy + 2;
|
||||
f := f + ddfy;
|
||||
END;
|
||||
x := x + 1;
|
||||
ddfx := ddfx + 2;
|
||||
f := f + ddfx + 1;
|
||||
Bitmap.SetPixel(img, Bitmap.Point{center.x + x, center.y + y}, color);
|
||||
Bitmap.SetPixel(img, Bitmap.Point{center.x - x, center.y + y}, color);
|
||||
Bitmap.SetPixel(img, Bitmap.Point{center.x + x, center.y - y}, color);
|
||||
Bitmap.SetPixel(img, Bitmap.Point{center.x - x, center.y - y}, color);
|
||||
Bitmap.SetPixel(img, Bitmap.Point{center.x + y, center.y + x}, color);
|
||||
Bitmap.SetPixel(img, Bitmap.Point{center.x - y, center.y + x}, color);
|
||||
Bitmap.SetPixel(img, Bitmap.Point{center.x + y, center.y - x}, color);
|
||||
Bitmap.SetPixel(img, Bitmap.Point{center.x - y, center.y - x}, color);
|
||||
END;
|
||||
END Draw;
|
||||
|
||||
BEGIN
|
||||
END Circle.
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
MODULE Main;
|
||||
|
||||
IMPORT Circle, Bitmap, PPM;
|
||||
|
||||
VAR testpic: Bitmap.T;
|
||||
|
||||
BEGIN
|
||||
testpic := Bitmap.NewImage(32, 32);
|
||||
Bitmap.Fill(testpic, Bitmap.White);
|
||||
Circle.Draw(testpic, Bitmap.Point{16, 16}, 10, Bitmap.Black);
|
||||
PPM.Create("testpic.ppm", testpic);
|
||||
END Main.
|
||||
|
|
@ -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
|
||||
;;
|
||||
Loading…
Add table
Add a link
Reference in a new issue