summaryrefslogtreecommitdiff
path: root/lib
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 /lib
parent3e2e4fe9e05d73ba1c1b5de93160bb1cdb7cb56e (diff)
Circles and funny stuffs
Diffstat (limited to 'lib')
-rw-r--r--lib/shape.cc100
1 files changed, 100 insertions, 0 deletions
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;