From 61c94502bd33f2a38bdae502318c4a766448db60 Mon Sep 17 00:00:00 2001 From: pixel Date: Fri, 28 Mar 2003 16:08:13 +0000 Subject: Circles and funny stuffs --- lib/shape.cc | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) (limited to 'lib') diff --git a/lib/shape.cc b/lib/shape.cc index e586d6d..972600c 100644 --- a/lib/shape.cc +++ b/lib/shape.cc @@ -1,3 +1,4 @@ +#include #include #include "engine.h" #include "base.h" @@ -92,6 +93,105 @@ void mogltk::shape::pixel(int x, int y, ColorP c) { LEAVE; } +void mogltk::shape::circle(int x0, int y0, int r, ColorP c) { + ENTER; + + int x = 0; + int y = r - 1; + int d = 3 - 2 * r; + int dI = 10 - 4 * r; + int rI = 6; + + while (x <= y) { + pixel(x0 + x, y0 + y, c); + pixel(x0 - x, y0 + y, c); + pixel(x0 + x, y0 - y, c); + pixel(x0 - x, y0 - y, c); + pixel(x0 + y, y0 + x, c); + pixel(x0 - y, y0 + x, c); + pixel(x0 + y, y0 - x, c); + pixel(x0 - y, y0 - x, c); + if (d >= 0) { + d += dI; + dI += 8; + y -= 1; + } else { + d += rI; + dI += 4; + } + rI += 4; + x += 1; + } + + LEAVE; +} + +void mogltk::shape::pcircle(int x0, int y0, int r, ColorP c) { + ENTER; + + int x = 0; + int y = r - 1; + int d = 3 - 2 * r; + int dI = 10 - 4 * r; + int rI = 6; + + while (x <= y) { + hline(x0 - x, x0 + x, y0 + y, c); + hline(x0 - x, x0 + x, y0 - y, c); + hline(x0 - y, x0 + y, y0 + x, c); + hline(x0 - y, x0 + y, y0 - x, c); + if (d >= 0) { + d += dI; + dI += 8; + y -= 1; + } else { + d += rI; + dI += 4; + } + rI += 4; + x += 1; + } + + LEAVE; +} + +void mogltk::shape::arc(int x0, int y0, int r, double a1, double a2, ColorP c) { + ENTER; + + int x = 0; + int y = r - 1; + int d = 3 - 2 * r; + int dI = 10 - 4 * r; + int rI = 6; + + while (x <= y) { + pixel(x0 + y, y0 - x, c); // 1 + pixel(x0 + x, y0 - y, c); // 2 + pixel(x0 - x, y0 - y, c); // 3 + pixel(x0 - y, y0 - x, c); // 4 + pixel(x0 - y, y0 + x, c); // 5 + pixel(x0 - x, y0 + y, c); // 6 + pixel(x0 + x, y0 + y, c); // 7 + pixel(x0 + y, y0 + x, c); // 8 + + if (d >= 0) { + d += dI; + dI += 8; + y -= 1; + } else { + d += rI; + dI += 4; + } + rI += 4; + x += 1; + } + + LEAVE; +} + +void mogltk::shape::arc(int x0, int y0, int r, int x1, int y1, int x2, int y2, ColorP c) { +} + void mogltk::shape::obox(int x1, int y1, int x2, int y2, ColorP c) { ENTER; -- cgit v1.2.3