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 --- include/shape.h | 4 +++ lib/shape.cc | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/test.cc | 5 ++- 3 files changed, 108 insertions(+), 1 deletion(-) diff --git a/include/shape.h b/include/shape.h index 2c7addf..fdae6af 100644 --- a/include/shape.h +++ b/include/shape.h @@ -15,6 +15,10 @@ namespace mogltk { class shape : public Base { public: virtual void pixel(int x, int y, ColorP = WHITE); + virtual void circle(int x, int y, int r, ColorP = WHITE); + virtual void pcircle(int x, int y, int r, ColorP = WHITE); + virtual void arc(int x, int y, int r, double a1, double a2, ColorP = WHITE); + virtual void arc(int x, int y, int r, int x1, int y1, int x2, int y2, ColorP = WHITE); virtual void box(int x1, int y1, int x2, int y2, ColorP = WHITE); virtual void box3d(int x1, int y1, int x2, int y2, ColorP = DOS_WHITE, ColorP = DOS_HIGH_WHITE, ColorP = DOS_GRAY, int = 2, bool = false); virtual void obox(int x1, int y1, int x2, int y2, ColorP = WHITE); 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; diff --git a/src/test.cc b/src/test.cc index 5bdb0ce..4ba9349 100644 --- a/src/test.cc +++ b/src/test.cc @@ -62,8 +62,11 @@ virtual int startup() throw (GeneralException) { sh->window(50, 350, 150, 400, "Titre plus beau ;)"); sh->box3d(180, 130, 320, 220); sh->button(200, 150, 300, 200, "Bouton"); + + sh->pcircle(320, 240, 50); +// sh->arc(320, 240, 50, 0, 0); - sh->box(MIN(sx1, sx2), MIN(sy1, sy2), MAX(sx1, sx2), MAX(sy1, sy2), AlphaBlue); +// sh->box(MIN(sx1, sx2), MIN(sy1, sy2), MAX(sx1, sx2), MAX(sy1, sy2), AlphaBlue); font->putcursor(550, 400); font->printf("FPS: %.2f\n", mogltk::engine::FPS()); -- cgit v1.2.3