summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpixel <pixel>2003-03-28 16:08:13 +0000
committerpixel <pixel>2003-03-28 16:08:13 +0000
commit61c94502bd33f2a38bdae502318c4a766448db60 (patch)
tree0555192016991fb187335dcb478f2a0363572aa1
parent3e2e4fe9e05d73ba1c1b5de93160bb1cdb7cb56e (diff)
Circles and funny stuffs
-rw-r--r--include/shape.h4
-rw-r--r--lib/shape.cc100
-rw-r--r--src/test.cc5
3 files changed, 108 insertions, 1 deletions
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 <math.h>
#include <SDL.h>
#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());