/* Edge++ Library Demonstration */ #include "Edge.h" int PickingPoints = 0; EdgeVector Center(0,0,0), Perimeter(0,0,0); void PlotSafePoint(int x, int y, EdgeColor Color) { if(EdgeIsPointSafe(x, y)) EdgeDrawPoint(x, y, Color); } /*----------------------------------------------------------------------*/ /* g_offset_circle_points() */ /* */ /* plots a 8 "safe" points which are all reflections of x, y */ /* offset from 0,0 by amount specified */ /*----------------------------------------------------------------------*/ void g_offset_circle_points(int x, int y, int xoff, int yoff, EdgeColor Color) { PlotSafePoint(x + xoff, y + yoff, Color); PlotSafePoint(y + xoff, x + yoff, Color); PlotSafePoint(x + xoff, -y + yoff, Color); PlotSafePoint(y + xoff, -x + yoff, Color); PlotSafePoint(-x + xoff,-y + yoff, Color); PlotSafePoint(-y + xoff,-x + yoff, Color); PlotSafePoint(-x + xoff, y + yoff, Color); PlotSafePoint(-y + xoff, x + yoff, Color); } /*----------------------------------------------------------------------*/ /* g_draw_circle() */ /* */ /* draws a circle around given center, using the midpoint circle */ /* algorithm */ /*----------------------------------------------------------------------*/ void g_draw_circle(EdgeVector Center, EdgeVector CirclePt, EdgeColor Color) { int x, y, d, deltaE, deltaSE; int Radius = (Center - CirclePt).Size2d(); x = 0; y = Radius; d = 1 - Radius; deltaE = 3; deltaSE = 5 - (Radius * 2); g_offset_circle_points(x, y, Center.x, Center.y, Color); while(y > x) { if(d<0) { d += deltaE; deltaE += 2; deltaSE += 2; x++; } else { d += deltaSE; deltaE += 2; deltaSE += 4; x++; y--; } g_offset_circle_points(x, y, Center.x, Center.y, Color); } } void DrawCircleButton(void) { Center.x = (float)(rand()&640); Center.y =(float)(rand()&480); Perimeter.x =Center.x + (float)(rand()&128); Perimeter.y =Center.y + (float)(rand()&128); g_draw_circle(Center, Perimeter, EdgeColor(((float)(rand()&255) / 256.0f), ((float)(rand()&255) / 256.0f), ((float)(rand()&255) / 256.0f))); } void ClearAllButton(void) { EdgeClearAll(); } void WritePPMButton(void) { EdgeWritePPM("example.ppm"); } void AppExitButton(void) { exit(0); } void main() { EdgeAddButton(1, 1, 150, 45, "Draw Circle", DrawCircleButton, GLUT_BITMAP_HELVETICA_18, EdgeColor(1,1,1), EdgeColor(0,1,0)); EdgeAddButton(152, 1, 150, 45, "Clear All", ClearAllButton, GLUT_BITMAP_HELVETICA_18, EdgeColor(1,1,1), EdgeColor(0,0,1)); EdgeAddButton(303, 1, 150, 45, "Write PPM", WritePPMButton, GLUT_BITMAP_HELVETICA_18, EdgeColor(1,1,1), EdgeColor(0,0,1)); EdgeAddButton(454, 1, 150, 45, "Exit", AppExitButton, GLUT_BITMAP_HELVETICA_18, EdgeColor(1,1,1), EdgeColor(0,0.5,1)); EdgeInit(640, 480, "Testing Edge"); }