|
|
1.1 ! root 1: ! 2: /* This file contains code for X-CHESS. ! 3: Copyright (C) 1986 Free Software Foundation, Inc. ! 4: ! 5: This file is part of X-CHESS. ! 6: ! 7: X-CHESS is distributed in the hope that it will be useful, ! 8: but WITHOUT ANY WARRANTY. No author or distributor ! 9: accepts responsibility to anyone for the consequences of using it ! 10: or for whether it serves any particular purpose or works at all, ! 11: unless he says so in writing. Refer to the X-CHESS General Public ! 12: License for full details. ! 13: ! 14: Everyone is granted permission to copy, modify and redistribute ! 15: X-CHESS, but only under the conditions described in the ! 16: X-CHESS General Public License. A copy of this license is ! 17: supposed to have been given to you along with X-CHESS so you ! 18: can know your rights and responsibilities. It should be in a ! 19: file named COPYING. Among other things, the copyright notice ! 20: and this notice must be preserved on all copies. */ ! 21: ! 22: ! 23: /* RCS Info: $Revision: 1.2 $ on $Date: 86/11/23 17:17:04 $ ! 24: * $Source: /users/faustus/xchess/RCS/XCircle.c,v $ ! 25: * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group ! 26: * Permission is granted to do anything with this code except sell it ! 27: * or remove this message. ! 28: * ! 29: */ ! 30: ! 31: #include <stdio.h> ! 32: #include <X11/Xlib.h> ! 33: #include <X11/X10.h> ! 34: #include <math.h> ! 35: ! 36: #define PI 3.1415926535897932384 ! 37: ! 38: #define MAXVERTS 1000 ! 39: ! 40: void ! 41: XCircle(win, x, y, rad, start, end, width, height, pixel, func, planes) ! 42: Window win; ! 43: int x, y, rad; ! 44: double start, end; ! 45: int pixel; ! 46: int width, height; ! 47: int func, planes; ! 48: { ! 49: Vertex verts[MAXVERTS]; ! 50: double xp, yp, ang; ! 51: int lx, ly, xpt, ypt, i; ! 52: double gradincr = 2 / (double) rad; ! 53: int bk = 0; ! 54: ! 55: while (end >= PI * 2) ! 56: end -= PI * 2; ! 57: while (start >= PI * 2) ! 58: start -= PI * 2; ! 59: while (end < 0) ! 60: end += PI * 2; ! 61: while (start < 0) ! 62: start += PI * 2; ! 63: if (end == start) { ! 64: if (end < gradincr) ! 65: end = end + PI * 2 - gradincr / 2; ! 66: else ! 67: end -= gradincr / 2; ! 68: } ! 69: for (ang = start, i = 0; i < MAXVERTS; ) { ! 70: ! 71: xp = x + rad * cos(ang); ! 72: yp = y + rad * sin(ang); ! 73: ! 74: xpt = xp; ! 75: ypt = yp; ! 76: ! 77: if (!i || (lx != xpt) || (ly != ypt)) { ! 78: verts[i].x = xpt; ! 79: verts[i].y = ypt; ! 80: verts[i].flags = 0; ! 81: i++; ! 82: } ! 83: lx = xpt; ! 84: ly = ypt; ! 85: if (bk) ! 86: break; ! 87: if (((ang < end) && (ang + gradincr > end)) || ((end < start) ! 88: && (ang + gradincr > 2 * PI) ! 89: && (ang + gradincr - 2 * PI > end))) { ! 90: ang = end; ! 91: bk = 1; ! 92: } else if (ang == end) { ! 93: break; ! 94: } else { ! 95: ang += gradincr; ! 96: } ! 97: if (ang >= PI * 2) ! 98: ang -= PI * 2; ! 99: } ! 100: ! 101: /* Now draw the thing.. */ ! 102: XDraw(win, verts, i, width, height, pixel, func, planes); ! 103: ! 104: return; ! 105: } ! 106: ! 107: #ifdef notdef VertexCurved is screwed up ! 108: ! 109: void ! 110: XCircle(win, x, y, rad, start, end, width, height, pixel, func, planes) ! 111: Window win; ! 112: int x, y, rad; ! 113: double start, end; ! 114: int pixel; ! 115: int width, height; ! 116: int func, planes; ! 117: { ! 118: Vertex verts[7]; ! 119: int i, j, sv, ev; ! 120: int dp = 0; ! 121: ! 122: for (i = j = 0 ; i < 4; i++) { ! 123: verts[j].x = x + rad * cos((double) (PI * i / 2)); ! 124: verts[j].y = y + rad * sin((double) (PI * i / 2)); ! 125: verts[j].flags = VertexCurved; ! 126: if ((start >= PI * i / 2) && (start < PI * (i + 1) / 2) && ! 127: (start != end)) { ! 128: j++; ! 129: verts[j].x = x + rad * cos(start); ! 130: verts[j].y = y + rad * sin(start); ! 131: verts[j].flags = VertexCurved; ! 132: sv = j; ! 133: } else if ((end >= PI * i / 2) && (end < PI * (i + 1) / 2) ! 134: && (start != end)) { ! 135: j++; ! 136: verts[j].x = x + rad * cos(end); ! 137: verts[j].y = y + rad * sin(end); ! 138: verts[j].flags = VertexCurved; ! 139: ev = j; ! 140: } ! 141: j++; ! 142: } ! 143: verts[0].flags |= VertexStartClosed; ! 144: verts[j].x = verts[0].x; ! 145: verts[j].y = verts[0].y; ! 146: verts[j].flags = (verts[0].flags & ~VertexStartClosed) | ! 147: VertexEndClosed; ! 148: for (i = 0; i < 15; i++) { ! 149: if (dp) ! 150: verts[i % 7].flags |= VertexDontDraw; ! 151: if (i % 7 == ev) ! 152: dp = 1; ! 153: else if (i % 7 == sv) ! 154: dp = 0; ! 155: } ! 156: XDraw(win, verts, j + 1, width, height, pixel, func, planes); ! 157: ! 158: return; ! 159: } ! 160: ! 161: #endif notdef ! 162:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.