| @@ -1,459 +1,459 @@ | | | @@ -1,459 +1,459 @@ |
1 | /* $NetBSD: testpat.c,v 1.1 2021/01/02 03:21:39 nat Exp $ */ | | 1 | /* $NetBSD: testpat.c,v 1.2 2021/01/02 12:10:17 jmcneill Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2016 Nathanial Sloss <nathanialsloss@yahoo.com.au> | | 4 | * Copyright (c) 2016 Nathanial Sloss <nathanialsloss@yahoo.com.au> |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
15 | * | | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | | 16 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
17 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 17 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
26 | * POSSIBILITY OF SUCH DAMAGE. | | 26 | * POSSIBILITY OF SUCH DAMAGE. |
27 | */ | | 27 | */ |
28 | | | 28 | |
29 | #include <curses.h> | | 29 | #include <curses.h> |
30 | #include <err.h> | | 30 | #include <err.h> |
31 | #include <errno.h> | | 31 | #include <errno.h> |
32 | #include <math.h> | | 32 | #include <math.h> |
33 | #include <stdio.h> | | 33 | #include <stdio.h> |
34 | #include <stdlib.h> | | 34 | #include <stdlib.h> |
35 | #include <string.h> | | 35 | #include <string.h> |
36 | #include <time.h> | | 36 | #include <time.h> |
37 | #include <sys/time.h> | | 37 | #include <sys/time.h> |
38 | #include <sys/types.h> | | 38 | #include <sys/types.h> |
39 | | | 39 | |
40 | int main(int argc, char *argv[]) { | | 40 | int main(int argc, char *argv[]) { |
41 | int i, col, colour, line, x_limit, y_limit, colourOK, spacing; | | 41 | int i, col, colour, line, x_limit, y_limit, colourOK, spacing; |
42 | int xpos, ypos, spacing_residual, spacing_start, spacing_end; | | 42 | int xpos, ypos, spacing_residual, spacing_start, spacing_end; |
43 | int grid_x, grid_y; | | 43 | int grid_x, grid_y; |
44 | float grid_unit; | | 44 | float grid_unit; |
45 | | | 45 | |
46 | char title[255] = "NetBSD"; | | 46 | char title[255] = "NetBSD"; |
47 | int numcolours = 6; | | 47 | int numcolours = 6; |
48 | | | 48 | |
49 | int colour_list[6] = { | | 49 | int colour_list[6] = { |
50 | COLOR_YELLOW, | | 50 | COLOR_YELLOW, |
51 | COLOR_CYAN, | | 51 | COLOR_CYAN, |
52 | COLOR_GREEN, | | 52 | COLOR_GREEN, |
53 | COLOR_MAGENTA, | | 53 | COLOR_MAGENTA, |
54 | COLOR_RED, | | 54 | COLOR_RED, |
55 | COLOR_BLUE, | | 55 | COLOR_BLUE, |
56 | }; | | 56 | }; |
57 | | | 57 | |
58 | float coord_x, circle_int; | | 58 | float coord_x, circle_int; |
59 | float a_axis, b_axis; | | 59 | float a_axis, b_axis; |
60 | | | 60 | |
61 | if (!(initscr())) { | | 61 | if (!(initscr())) { |
62 | printf("\nUnknown terminal type."); | | 62 | printf("\nUnknown terminal type."); |
63 | printf("\n"); | | 63 | printf("\n"); |
64 | return EXIT_FAILURE; | | 64 | return EXIT_FAILURE; |
65 | } | | 65 | } |
66 | | | 66 | |
67 | if (argc > 2) { | | 67 | if (argc > 2) { |
68 | endwin(); | | 68 | endwin(); |
69 | errx(EINVAL, "usage: testpat [title]"); | | 69 | errx(EINVAL, "usage: testpat [title]"); |
70 | } | | 70 | } |
71 | | | 71 | |
72 | if (argc == 2 && strlen(argv[1]) < (size_t)COLS) | | 72 | if (argc == 2 && strlen(argv[1]) < (size_t)COLS) |
73 | snprintf(title, sizeof(title), "%s", argv[1]); | | 73 | snprintf(title, sizeof(title), "%s", argv[1]); |
74 | else if (argc == 2 && (int)strlen(argv[1]) > COLS) { | | 74 | else if (argc == 2 && (int)strlen(argv[1]) > COLS) { |
75 | endwin(); | | 75 | endwin(); |
76 | errx(EINVAL, "title string must be less than display columns"); | | 76 | errx(EINVAL, "title string must be less than display columns"); |
77 | } | | 77 | } |
78 | | | 78 | |
79 | colourOK = has_colors(); | | 79 | colourOK = has_colors(); |
80 | | | 80 | |
81 | if (COLS < 13 || LINES < 13) { | | 81 | if (COLS < 13 || LINES < 13) { |
82 | endwin(); | | 82 | endwin(); |
83 | printf("\nTerminal size must be at least 72x25."); | | 83 | printf("\nTerminal size must be at least 72x25."); |
84 | printf("\n"); | | 84 | printf("\n"); |
85 | return EXIT_FAILURE; | | 85 | return EXIT_FAILURE; |
86 | } | | 86 | } |
87 | | | 87 | |
88 | if (colourOK) { | | 88 | if (colourOK) { |
89 | start_color(); | | 89 | start_color(); |
90 | | | 90 | |
91 | init_pair( 0, COLOR_WHITE, COLOR_BLACK ); | | 91 | init_pair( 0, COLOR_WHITE, COLOR_BLACK ); |
92 | init_pair( 1, COLOR_WHITE, COLOR_RED ); | | 92 | init_pair( 1, COLOR_WHITE, COLOR_RED ); |
93 | init_pair( 2, COLOR_WHITE, COLOR_GREEN ); | | 93 | init_pair( 2, COLOR_WHITE, COLOR_GREEN ); |
94 | init_pair( 3, COLOR_WHITE, COLOR_YELLOW ); | | 94 | init_pair( 3, COLOR_WHITE, COLOR_YELLOW ); |
95 | init_pair( 4, COLOR_WHITE, COLOR_BLUE ); | | 95 | init_pair( 4, COLOR_WHITE, COLOR_BLUE ); |
96 | init_pair( 5, COLOR_WHITE, COLOR_MAGENTA ); | | 96 | init_pair( 5, COLOR_WHITE, COLOR_MAGENTA ); |
97 | init_pair( 6, COLOR_WHITE, COLOR_CYAN ); | | 97 | init_pair( 6, COLOR_WHITE, COLOR_CYAN ); |
98 | init_pair( 7, COLOR_BLACK, COLOR_WHITE ); | | 98 | init_pair( 7, COLOR_BLACK, COLOR_WHITE ); |
99 | | | 99 | |
100 | attrset(COLOR_PAIR(0)); | | 100 | attrset(COLOR_PAIR(0)); |
101 | } | | 101 | } |
102 | | | 102 | |
103 | x_limit = (COLS - 1) / 2; | | 103 | x_limit = (COLS - 1) / 2; |
104 | x_limit = x_limit * 2; | | 104 | x_limit = x_limit * 2; |
105 | y_limit = (LINES - 2) / 2; | | 105 | y_limit = (LINES - 2) / 2; |
106 | y_limit = y_limit * 2; | | 106 | y_limit = y_limit * 2; |
107 | spacing = 2 * y_limit / numcolours; | | 107 | spacing = 2 * y_limit / numcolours; |
108 | spacing_residual = ((2 * y_limit) % numcolours) / 2; | | 108 | spacing_residual = ((2 * y_limit) % numcolours) / 2; |
109 | a_axis = y_limit / 2; | | 109 | a_axis = y_limit / 2; |
110 | b_axis = y_limit; | | 110 | b_axis = y_limit; |
111 | grid_unit = b_axis / 13; | | 111 | grid_unit = b_axis / 13; |
112 | grid_y = grid_unit; | | 112 | grid_y = grid_unit; |
113 | grid_x = grid_unit * 2; | | 113 | grid_x = grid_unit * 2; |
114 | | | 114 | |
115 | int circle_pos[y_limit][2]; | | 115 | int circle_pos[y_limit][2]; |
116 | memset(circle_pos, -1, sizeof(circle_pos)); | | 116 | memset(circle_pos, -1, sizeof(circle_pos)); |
117 | | | 117 | |
118 | for (i = 0; i < y_limit; i++) { | | 118 | for (i = 0; i < y_limit; i++) { |
119 | /* Draw an elipse (looks more circular.) */ | | 119 | /* Draw an elipse (looks more circular.) */ |
120 | circle_int = (i - a_axis) / a_axis; | | 120 | circle_int = (i - a_axis) / a_axis; |
121 | circle_int = 1 - powf(circle_int, 2); | | 121 | circle_int = 1 - powf(circle_int, 2); |
122 | circle_int = circle_int * powf(b_axis, 2); | | 122 | circle_int = circle_int * powf(b_axis, 2); |
123 | #if 0 | | 123 | #if 0 |
124 | /* Draw a circle, commented out as elipse looks better.*/ | | 124 | /* Draw a circle, commented out as elipse looks better.*/ |
125 | circle_int = powf(a_axis, 2) - powf(i - a_axis, 2); | | 125 | circle_int = powf(a_axis, 2) - powf(i - a_axis, 2); |
126 | #endif | | 126 | #endif |
127 | coord_x = sqrtf(circle_int); | | 127 | coord_x = sqrtf(circle_int); |
128 | circle_pos[i][0] = (-coord_x + ((float)x_limit / 2)); | | 128 | circle_pos[i][0] = (-coord_x + ((float)x_limit / 2)); |
129 | circle_pos[i][1] = (coord_x + ((float)x_limit / 2)); | | 129 | circle_pos[i][1] = (coord_x + ((float)x_limit / 2)); |
130 | } | | 130 | } |
131 | | | 131 | |
132 | clear(); | | 132 | clear(); |
133 | | | 133 | |
134 | attron(A_ALTCHARSET); | | 134 | attron(A_ALTCHARSET); |
135 | move(0, 0); | | 135 | move(0, 0); |
136 | | | 136 | |
137 | /* Draw a grid. */ | | 137 | /* Draw a grid. */ |
138 | for (line = 1; line < y_limit; line += grid_y) { | | 138 | for (line = 1; line < y_limit; line += grid_y) { |
139 | for (col = 1; col < x_limit; col = col + grid_x) { | | 139 | for (col = 1; col < x_limit; col = col + grid_x) { |
140 | xpos = col; | | 140 | xpos = col; |
141 | while ((xpos < col + grid_x - 1) && (xpos < | | 141 | while ((xpos < col + grid_x - 1) && (xpos < |
142 | x_limit)) { | | 142 | x_limit)) { |
143 | mvaddch(line + grid_y - 1, xpos, 113 | | | 143 | mvaddch(line + grid_y - 1, xpos, 113 | |
144 | A_ALTCHARSET); | | 144 | A_ALTCHARSET); |
145 | xpos++; | | 145 | xpos++; |
146 | } | | 146 | } |
147 | if (xpos < x_limit) | | 147 | if (xpos < x_limit) |
148 | mvaddch(line + grid_y - 1, xpos, 110 | | | 148 | mvaddch(line + grid_y - 1, xpos, 110 | |
149 | A_ALTCHARSET); | | 149 | A_ALTCHARSET); |
150 | } | | 150 | } |
151 | ypos = line; | | 151 | ypos = line; |
152 | while (ypos < line + grid_y - 1) { | | 152 | while (ypos < line + grid_y - 1) { |
153 | for (col = grid_x - 1; col < x_limit; col += grid_x) { | | 153 | for (col = grid_x - 1; col < x_limit; col += grid_x) { |
154 | mvaddch(ypos, col + 1, 120 | A_ALTCHARSET); | | 154 | mvaddch(ypos, col + 1, 120 | A_ALTCHARSET); |
155 | } | | 155 | } |
156 | ypos++; | | 156 | ypos++; |
157 | } | | 157 | } |
158 | } | | 158 | } |
159 | | | 159 | |
160 | for (line = 1; line < y_limit; line += grid_y) { | | 160 | for (line = 1; line < y_limit; line += grid_y) { |
161 | mvaddch(line + grid_y - 1, 0, 116 | A_ALTCHARSET); | | 161 | mvaddch(line + grid_y - 1, 0, 116 | A_ALTCHARSET); |
162 | mvaddch(line + grid_y - 1, x_limit, 117 | A_ALTCHARSET); | | 162 | mvaddch(line + grid_y - 1, x_limit, 117 | A_ALTCHARSET); |
163 | | | 163 | |
164 | ypos = line; | | 164 | ypos = line; |
165 | while (ypos < line + grid_y - 1) { | | 165 | while (ypos < line + grid_y - 1) { |
166 | mvaddch(ypos, 0, 120 | A_ALTCHARSET); | | 166 | mvaddch(ypos, 0, 120 | A_ALTCHARSET); |
167 | mvaddch(ypos, x_limit, 120 | A_ALTCHARSET); | | 167 | mvaddch(ypos, x_limit, 120 | A_ALTCHARSET); |
168 | ypos++; | | 168 | ypos++; |
169 | } | | 169 | } |
170 | } | | 170 | } |
171 | | | 171 | |
172 | for (col = 1; col < x_limit; col += grid_x) { | | 172 | for (col = 1; col < x_limit; col += grid_x) { |
173 | mvaddch(0, col + grid_x - 1, 119 | A_ALTCHARSET); | | 173 | mvaddch(0, col + grid_x - 1, 119 | A_ALTCHARSET); |
174 | mvaddch(y_limit, col + grid_x - 1, 118 | A_ALTCHARSET); | | 174 | mvaddch(y_limit, col + grid_x - 1, 118 | A_ALTCHARSET); |
175 | | | 175 | |
176 | xpos = col; | | 176 | xpos = col; |
177 | while ((xpos < col + grid_x - 1) && (xpos < x_limit)) { | | 177 | while ((xpos < col + grid_x - 1) && (xpos < x_limit)) { |
178 | mvaddch(0, xpos, 113 | A_ALTCHARSET); | | 178 | mvaddch(0, xpos, 113 | A_ALTCHARSET); |
179 | mvaddch(y_limit, xpos, 113 | A_ALTCHARSET); | | 179 | mvaddch(y_limit, xpos, 113 | A_ALTCHARSET); |
180 | xpos++; | | 180 | xpos++; |
181 | } | | 181 | } |
182 | } | | 182 | } |
183 | | | 183 | |
184 | mvaddch(0, 0, 108 | A_ALTCHARSET); | | 184 | mvaddch(0, 0, 108 | A_ALTCHARSET); |
185 | mvaddch(0, x_limit, 107 | A_ALTCHARSET); | | 185 | mvaddch(0, x_limit, 107 | A_ALTCHARSET); |
186 | mvaddch(y_limit, 0, 109 | A_ALTCHARSET); | | 186 | mvaddch(y_limit, 0, 109 | A_ALTCHARSET); |
187 | mvaddch(y_limit, x_limit, 106 | A_ALTCHARSET); | | 187 | mvaddch(y_limit, x_limit, 106 | A_ALTCHARSET); |
188 | | | 188 | |
189 | /* Draw a white circle. */ | | 189 | /* Draw a white circle. */ |
190 | for (i = 1; i < y_limit; i++) { | | 190 | for (i = 1; i < y_limit; i++) { |
191 | for (col = circle_pos[i][0]; col <= circle_pos[i][1]; col++) { | | 191 | for (col = circle_pos[i][0]; col <= circle_pos[i][1]; col++) { |
192 | mvaddch(i, col, 32 | A_REVERSE); | | 192 | mvaddch(i, col, 32 | A_REVERSE); |
193 | } | | 193 | } |
194 | } | | 194 | } |
195 | | | 195 | |
196 | /* Add title segment. */ | | 196 | /* Add title segment. */ |
197 | for (i = roundf(1 * grid_unit); i < roundf(2 * grid_unit); i++) { | | 197 | for (i = roundf(1 * grid_unit); i < roundf(2 * grid_unit); i++) { |
198 | if (colourOK) | | 198 | if (colourOK) |
199 | attrset(COLOR_PAIR(COLOR_BLACK)); | | 199 | attrset(COLOR_PAIR(COLOR_BLACK)); |
200 | | | 200 | |
201 | for (col = roundf((4 * grid_unit * 2) + | | 201 | for (col = roundf((4 * grid_unit * 2) + |
202 | circle_pos[y_limit /2][0]); col <= roundf((9 * grid_unit | | 202 | circle_pos[y_limit /2][0]); col <= roundf((9 * grid_unit |
203 | * 2) + circle_pos[y_limit /2][0]); col++) | | 203 | * 2) + circle_pos[y_limit /2][0]); col++) |
204 | mvaddch(i, col, ' '); | | 204 | mvaddch(i, col, ' '); |
205 | } | | 205 | } |
206 | | | 206 | |
207 | i = roundf(1.4 * grid_unit); | | 207 | i = roundf(1.4 * grid_unit); |
208 | | | 208 | |
209 | col = y_limit - (strlen(title) / 2) + circle_pos[y_limit / 2][0]; | | 209 | col = y_limit - (strlen(title) / 2) + circle_pos[y_limit / 2][0]; |
210 | mvprintw(i, col, "%s", title); | | 210 | mvprintw(i, col, "%s", title); |
211 | | | 211 | |
212 | /* Add black segments at top. */ | | 212 | /* Add black segments at top. */ |
213 | for (line = roundf(2 * grid_unit); line < 4 * grid_unit; line++) { | | 213 | for (line = roundf(2 * grid_unit); line < 4 * grid_unit; line++) { |
214 | if (colourOK) | | 214 | if (colourOK) |
215 | attrset(COLOR_PAIR(COLOR_BLACK)); | | 215 | attrset(COLOR_PAIR(COLOR_BLACK)); |
216 | | | 216 | |
217 | for (col = 0; col <= roundf((3.5 * grid_unit * 2)); col++) { | | 217 | for (col = 0; col <= roundf((3.5 * grid_unit * 2)); col++) { |
218 | xpos = col + circle_pos[y_limit / 2][0]; | | 218 | xpos = col + circle_pos[y_limit / 2][0]; |
219 | if (xpos >= circle_pos[line][0] && | | 219 | if (xpos >= circle_pos[line][0] && |
220 | xpos <= circle_pos[line][1]) | | 220 | xpos <= circle_pos[line][1]) |
221 | mvaddch(line, xpos, ' '); | | 221 | mvaddch(line, xpos, ' '); |
222 | } | | 222 | } |
223 | | | 223 | |
224 | for (col = roundf((9.5 * grid_unit * 2)); col < | | 224 | for (col = roundf((9.5 * grid_unit * 2)); col < |
225 | roundf((13 * grid_unit * 2)); col++) { | | 225 | roundf((13 * grid_unit * 2)); col++) { |
226 | xpos = col + circle_pos[y_limit / 2][0]; | | 226 | xpos = col + circle_pos[y_limit / 2][0]; |
227 | if (xpos >= circle_pos[line][0] && | | 227 | if (xpos >= circle_pos[line][0] && |
228 | xpos <= circle_pos[line][1]) | | 228 | xpos <= circle_pos[line][1]) |
229 | mvaddch(line, xpos, ' '); | | 229 | mvaddch(line, xpos, ' '); |
230 | } | | 230 | } |
231 | } | | 231 | } |
232 | | | 232 | |
233 | /* Add black and white squares close to top. */ | | 233 | /* Add black and white squares close to top. */ |
234 | int gap = (circle_pos[(int)(5 * grid_unit)][1] - | | 234 | int gap = (circle_pos[(int)(5 * grid_unit)][1] - |
235 | circle_pos[(int)(5 * grid_unit)][0]) / 13; | | 235 | circle_pos[(int)(5 * grid_unit)][0]) / 13; |
236 | | | 236 | |
237 | for (i = roundf(3 * grid_unit); i < roundf(4 * grid_unit); i++) { | | 237 | for (i = roundf(3 * grid_unit); i < roundf(4 * grid_unit); i++) { |
238 | for (xpos = 0; xpos <= x_limit; xpos += 2 * gap) { | | 238 | for (xpos = 0; xpos <= x_limit; xpos += 2 * gap) { |
239 | if (colourOK) | | 239 | if (colourOK) |
240 | attrset(COLOR_PAIR(COLOR_BLACK)); | | 240 | attrset(COLOR_PAIR(COLOR_BLACK)); |
241 | | | 241 | |
242 | for (col = xpos; col < xpos + gap; col++) { | | 242 | for (col = xpos; col < xpos + gap; col++) { |
243 | if (col >= circle_pos[i][0] && | | 243 | if (col >= circle_pos[i][0] && |
244 | col <= circle_pos[i][1]) | | 244 | col <= circle_pos[i][1]) |
245 | mvaddch(i, col, ' '); | | 245 | mvaddch(i, col, ' '); |
246 | } | | 246 | } |
247 | | | 247 | |
248 | if (colourOK) | | 248 | if (colourOK) |
249 | attrset(COLOR_PAIR(COLOR_WHITE)); | | 249 | attrset(COLOR_PAIR(COLOR_WHITE)); |
250 | | | 250 | |
251 | for (col = xpos + gap ; col < xpos + (2 * gap); | | 251 | for (col = xpos + gap ; col < xpos + (2 * gap); |
252 | col++) { | | 252 | col++) { |
253 | if (col >= circle_pos[i][0] && | | 253 | if (col >= circle_pos[i][0] && |
254 | col <= circle_pos[i][1]) | | 254 | col <= circle_pos[i][1]) |
255 | mvaddch(i, col, ' '); | | 255 | mvaddch(i, col, ' '); |
256 | } | | 256 | } |
257 | } | | 257 | } |
258 | } | | 258 | } |
259 | | | 259 | |
260 | /* Add colour bars. */ | | 260 | /* Add colour bars. */ |
261 | for (i = 0; i < numcolours; i++) { | | 261 | for (i = 0; i < numcolours; i++) { |
262 | colour = colour_list[i]; | | 262 | colour = colour_list[i]; |
263 | if (colourOK) | | 263 | if (colourOK) |
264 | attrset(COLOR_PAIR(colour)); | | 264 | attrset(COLOR_PAIR(colour)); |
265 | | | 265 | |
266 | if (i == 0) | | 266 | if (i == 0) |
267 | spacing_start = 0; | | 267 | spacing_start = 0; |
268 | else | | 268 | else |
269 | spacing_start = (spacing * i) + spacing_residual; | | 269 | spacing_start = (spacing * i) + spacing_residual; |
270 | | | 270 | |
271 | if (i == numcolours - 1) | | 271 | if (i == numcolours - 1) |
272 | spacing_end = circle_pos[y_limit / 2][1]; | | 272 | spacing_end = circle_pos[y_limit / 2][1]; |
273 | else | | 273 | else |
274 | spacing_end = (spacing * (i + 1)) + spacing_residual; | | 274 | spacing_end = (spacing * (i + 1)) + spacing_residual; |
275 | | | 275 | |
276 | for (line = roundf(4 * grid_unit); line < (y_limit / 2); | | 276 | for (line = roundf(4 * grid_unit); line < (y_limit / 2); |
277 | line++) { | | 277 | line++) { |
278 | for (col = spacing_start; col < spacing_end; col++) { | | 278 | for (col = spacing_start; col < spacing_end; col++) { |
279 | xpos = col + circle_pos[y_limit / 2][0]; | | 279 | xpos = col + circle_pos[y_limit / 2][0]; |
280 | if (xpos >= circle_pos[line][0] && | | 280 | if (xpos >= circle_pos[line][0] && |
281 | xpos <= circle_pos[line][1]) | | 281 | xpos <= circle_pos[line][1]) |
282 | mvprintw(line, xpos, " "); | | 282 | mvprintw(line, xpos, " "); |
283 | } | | 283 | } |
284 | } | | 284 | } |
285 | } | | 285 | } |
286 | | | 286 | |
287 | /* Add black segment under centre line. */ | | 287 | /* Add black segment under centre line. */ |
288 | for (line = y_limit / 2; line < (9.5 * grid_unit); line++) { | | 288 | for (line = y_limit / 2; line < (9.5 * grid_unit); line++) { |
289 | if (colourOK) | | 289 | if (colourOK) |
290 | attrset(COLOR_PAIR(COLOR_BLACK)); | | 290 | attrset(COLOR_PAIR(COLOR_BLACK)); |
291 | | | 291 | |
292 | for (col = circle_pos[line][0]; col <= circle_pos[line][1]; | | 292 | for (col = circle_pos[line][0]; col <= circle_pos[line][1]; |
293 | col++) | | 293 | col++) |
294 | mvaddch(line, col, ' '); | | 294 | mvaddch(line, col, ' '); |
295 | | | 295 | |
296 | for (col = roundf((1.5 * grid_unit * 2)); col < | | 296 | for (col = roundf((1.5 * grid_unit * 2)); col < |
297 | roundf((4.3 * grid_unit * 2)); col++) { | | 297 | roundf((4.3 * grid_unit * 2)); col++) { |
298 | xpos = col + circle_pos[y_limit / 2][0]; | | 298 | xpos = col + circle_pos[y_limit / 2][0]; |
299 | if (xpos >= circle_pos[line][0] && | | 299 | if (xpos >= circle_pos[line][0] && |
300 | xpos < circle_pos[line][1]) | | 300 | xpos < circle_pos[line][1]) |
301 | mvaddch(line, xpos, 120 | A_ALTCHARSET); | | 301 | mvaddch(line, xpos, 120 | A_ALTCHARSET); |
302 | } | | 302 | } |
303 | | | 303 | |
304 | for (col = roundf((4.3 * grid_unit * 2)); col < | | 304 | for (col = roundf((4.3 * grid_unit * 2)); col < |
305 | roundf((7.6 * grid_unit * 2)); col++) { | | 305 | roundf((7.6 * grid_unit * 2)); col++) { |
306 | xpos = col + circle_pos[y_limit / 2][0]; | | 306 | xpos = col + circle_pos[y_limit / 2][0]; |
307 | if (xpos >= circle_pos[line][0] && | | 307 | if (xpos >= circle_pos[line][0] && |
308 | xpos < circle_pos[line][1]) | | 308 | xpos < circle_pos[line][1]) |
309 | mvaddch(line, xpos, '|'); | | 309 | mvaddch(line, xpos, '|'); |
310 | } | | 310 | } |
311 | | | 311 | |
312 | for (col = roundf((7.6 * grid_unit * 2)); col < | | 312 | for (col = roundf((7.6 * grid_unit * 2)); col < |
313 | roundf((11.5 * grid_unit * 2)); col++) { | | 313 | roundf((11.5 * grid_unit * 2)); col++) { |
314 | xpos = col + circle_pos[y_limit / 2][0]; | | 314 | xpos = col + circle_pos[y_limit / 2][0]; |
315 | if (xpos >= circle_pos[line][0] && | | 315 | if (xpos >= circle_pos[line][0] && |
316 | xpos < circle_pos[line][1]) | | 316 | xpos < circle_pos[line][1]) |
317 | mvaddch(line, xpos, 97 | A_ALTCHARSET); | | 317 | mvaddch(line, xpos, 97 | A_ALTCHARSET); |
318 | } | | 318 | } |
319 | } | | 319 | } |
320 | | | 320 | |
321 | /* Add black segment close to bottom. */ | | 321 | /* Add black segment close to bottom. */ |
322 | for (line = roundf(9.5 * grid_unit); line <= (10.5 * grid_unit); | | 322 | for (line = roundf(9.5 * grid_unit); line <= (10.5 * grid_unit); |
323 | line++) { | | 323 | line++) { |
324 | if (colourOK) | | 324 | if (colourOK) |
325 | attrset(COLOR_PAIR(COLOR_BLACK)); | | 325 | attrset(COLOR_PAIR(COLOR_BLACK)); |
326 | | | 326 | |
327 | for (col = roundf((0 * grid_unit * 2)); col < | | 327 | for (col = roundf((0 * grid_unit * 2)); col < |
328 | roundf((4 * grid_unit * 2)); col++) { | | 328 | roundf((4 * grid_unit * 2)); col++) { |
329 | xpos = col + circle_pos[y_limit / 2][0]; | | 329 | xpos = col + circle_pos[y_limit / 2][0]; |
330 | if (xpos >= circle_pos[line][0] && | | 330 | if (xpos >= circle_pos[line][0] && |
331 | xpos < circle_pos[line][1]) | | 331 | xpos < circle_pos[line][1]) |
332 | mvaddch(line, xpos, ' '); | | 332 | mvaddch(line, xpos, ' '); |
333 | } | | 333 | } |
334 | | | 334 | |
335 | for (col = roundf((4 * grid_unit * 2)); col < | | 335 | for (col = roundf((4 * grid_unit * 2)); col < |
336 | roundf((6.5 * grid_unit * 2)); col++) { | | 336 | roundf((6.5 * grid_unit * 2)); col++) { |
337 | xpos = col + circle_pos[y_limit / 2][0]; | | 337 | xpos = col + circle_pos[y_limit / 2][0]; |
338 | if (xpos >= circle_pos[line][0] && | | 338 | if (xpos >= circle_pos[line][0] && |
339 | xpos < circle_pos[line][1]) | | 339 | xpos < circle_pos[line][1]) |
340 | mvaddch(line, xpos, 97 | A_ALTCHARSET); | | 340 | mvaddch(line, xpos, 97 | A_ALTCHARSET); |
341 | } | | 341 | } |
342 | | | 342 | |
343 | if (colourOK) | | 343 | if (colourOK) |
344 | attrset(COLOR_PAIR(COLOR_WHITE)); | | 344 | attrset(COLOR_PAIR(COLOR_WHITE)); |
345 | | | 345 | |
346 | for (col = roundf((6.5 * grid_unit * 2)); col < | | 346 | for (col = roundf((6.5 * grid_unit * 2)); col < |
347 | roundf((9 * grid_unit * 2)); col++) { | | 347 | roundf((9 * grid_unit * 2)); col++) { |
348 | xpos = col + circle_pos[y_limit / 2][0]; | | 348 | xpos = col + circle_pos[y_limit / 2][0]; |
349 | if (xpos >= circle_pos[line][0] && | | 349 | if (xpos >= circle_pos[line][0] && |
350 | xpos < circle_pos[line][1]) | | 350 | xpos < circle_pos[line][1]) |
351 | mvaddch(line, xpos, 97 | A_ALTCHARSET); | | 351 | mvaddch(line, xpos, 97 | A_ALTCHARSET); |
352 | } | | 352 | } |
353 | | | 353 | |
354 | for (col = roundf((9 * grid_unit * 2)); col < | | 354 | for (col = roundf((9 * grid_unit * 2)); col < |
355 | roundf((13 * grid_unit * 2)); col++) { | | 355 | roundf((13 * grid_unit * 2)); col++) { |
356 | xpos = col + circle_pos[y_limit / 2][0]; | | 356 | xpos = col + circle_pos[y_limit / 2][0]; |
357 | if (xpos >= circle_pos[line][0] && | | 357 | if (xpos >= circle_pos[line][0] && |
358 | xpos < circle_pos[line][1]) | | 358 | xpos < circle_pos[line][1]) |
359 | mvaddch(line, xpos, ' '); | | 359 | mvaddch(line, xpos, ' '); |
360 | } | | 360 | } |
361 | } | | 361 | } |
362 | | | 362 | |
363 | /* Add name segment close to bottom. */ | | 363 | /* Add name segment close to bottom. */ |
364 | for (line = roundf(10.5 * grid_unit); line < (12 * grid_unit); | | 364 | for (line = roundf(10.5 * grid_unit); line < (12 * grid_unit); |
365 | line++) { | | 365 | line++) { |
366 | if (colourOK) | | 366 | if (colourOK) |
367 | attrset(COLOR_PAIR(COLOR_BLACK)); | | 367 | attrset(COLOR_PAIR(COLOR_BLACK)); |
368 | | | 368 | |
369 | for (col = roundf(3.5 * grid_unit * 2); col <= roundf(9.5 * | | 369 | for (col = roundf(3.5 * grid_unit * 2); col <= roundf(9.5 * |
370 | grid_unit * 2); col++) { | | 370 | grid_unit * 2); col++) { |
371 | xpos = col + circle_pos[y_limit / 2][0]; | | 371 | xpos = col + circle_pos[y_limit / 2][0]; |
372 | if (xpos >= circle_pos[line][0] && | | 372 | if (xpos >= circle_pos[line][0] && |
373 | xpos < circle_pos[line][1]) | | 373 | xpos < circle_pos[line][1]) |
374 | mvaddch(line, xpos, ' '); | | 374 | mvaddch(line, xpos, ' '); |
375 | } | | 375 | } |
376 | | | 376 | |
377 | if (colourOK) | | 377 | if (colourOK) |
378 | attrset(COLOR_PAIR(COLOR_WHITE)); | | 378 | attrset(COLOR_PAIR(COLOR_WHITE)); |
379 | | | 379 | |
380 | for (col = roundf(0 * grid_unit * 2); col <= roundf(3.5 * | | 380 | for (col = roundf(0 * grid_unit * 2); col <= roundf(3.5 * |
381 | grid_unit * 2); col++) { | | 381 | grid_unit * 2); col++) { |
382 | xpos = col + circle_pos[y_limit / 2][0]; | | 382 | xpos = col + circle_pos[y_limit / 2][0]; |
383 | if (xpos >= circle_pos[line][0] && | | 383 | if (xpos >= circle_pos[line][0] && |
384 | xpos < circle_pos[line][1]) | | 384 | xpos < circle_pos[line][1]) |
385 | mvaddch(line, xpos, ' '); | | 385 | mvaddch(line, xpos, ' '); |
386 | } | | 386 | } |
387 | | | 387 | |
388 | for (col = roundf(9.5 * grid_unit * 2); col <= roundf(13 * | | 388 | for (col = roundf(9.5 * grid_unit * 2); col <= roundf(13 * |
389 | grid_unit * 2); col++) { | | 389 | grid_unit * 2); col++) { |
390 | xpos = col + circle_pos[y_limit / 2][0]; | | 390 | xpos = col + circle_pos[y_limit / 2][0]; |
391 | if (xpos >= circle_pos[line][0] && | | 391 | if (xpos >= circle_pos[line][0] && |
392 | xpos < circle_pos[line][1]) | | 392 | xpos < circle_pos[line][1]) |
393 | mvaddch(line, xpos, ' '); | | 393 | mvaddch(line, xpos, ' '); |
394 | } | | 394 | } |
395 | } | | 395 | } |
396 | | | 396 | |
397 | /* Add yellow segment at bottom. */ | | 397 | /* Add yellow segment at bottom. */ |
398 | for (line = 12 * grid_unit; line < y_limit; line++) { | | 398 | for (line = 12 * grid_unit; line < y_limit; line++) { |
399 | if (colourOK) | | 399 | if (colourOK) |
400 | attrset(COLOR_PAIR(COLOR_YELLOW)); | | 400 | attrset(COLOR_PAIR(COLOR_YELLOW)); |
401 | | | 401 | |
402 | for (col = circle_pos[line][0]; col <= circle_pos[line][1]; | | 402 | for (col = circle_pos[line][0]; col <= circle_pos[line][1]; |
403 | col++) | | 403 | col++) |
404 | mvaddch(line, col, ' '); | | 404 | mvaddch(line, col, ' '); |
405 | | | 405 | |
406 | if (colourOK) | | 406 | if (colourOK) |
407 | attrset(COLOR_PAIR(COLOR_RED)); | | 407 | attrset(COLOR_PAIR(COLOR_RED)); |
408 | | | 408 | |
409 | for (col = roundf((6 * grid_unit * 2)); col < | | 409 | for (col = roundf((6 * grid_unit * 2)); col < |
410 | roundf((7 * grid_unit * 2)); col++) { | | 410 | roundf((7 * grid_unit * 2)); col++) { |
411 | xpos = col + circle_pos[y_limit / 2][0]; | | 411 | xpos = col + circle_pos[y_limit / 2][0]; |
412 | if (xpos >= circle_pos[line][0] && | | 412 | if (xpos >= circle_pos[line][0] && |
413 | xpos < circle_pos[line][1]) | | 413 | xpos < circle_pos[line][1]) |
414 | mvaddch(line, xpos, ' '); | | 414 | mvaddch(line, xpos, ' '); |
415 | } | | 415 | } |
416 | } | | 416 | } |
417 | | | 417 | |
418 | if (colourOK) | | 418 | if (colourOK) |
419 | attrset(COLOR_PAIR(COLOR_BLACK)); | | 419 | attrset(COLOR_PAIR(COLOR_BLACK)); |
420 | | | 420 | |
421 | for (line = 6 * grid_unit; line <= (7 * grid_unit) + 1; line++) { | | 421 | for (line = 6 * grid_unit; line <= (7 * grid_unit) + 1; line++) { |
422 | if (colourOK) | | 422 | if (colourOK) |
423 | attrset(COLOR_PAIR(COLOR_BLACK)); | | 423 | attrset(COLOR_PAIR(COLOR_BLACK)); |
424 | | | 424 | |
425 | col = x_limit / 2; | | 425 | col = x_limit / 2; |
426 | if (line != a_axis) { | | 426 | if (line != a_axis) { |
427 | mvaddch(line, col - 1, ' '); | | 427 | mvaddch(line, col - 1, ' '); |
428 | mvaddch(line, col, 120 | A_ALTCHARSET); | | 428 | mvaddch(line, col, 120 | A_ALTCHARSET); |
429 | mvaddch(line, col + 1, ' '); | | 429 | mvaddch(line, col + 1, ' '); |
430 | } | | 430 | } |
431 | } | | 431 | } |
432 | | | 432 | |
433 | line = y_limit / 2; | | 433 | line = y_limit / 2; |
434 | for (col = 1; col < x_limit; col = col + grid_x) { | | 434 | for (col = 1; col < x_limit; col = col + grid_x) { |
435 | xpos = col; | | 435 | xpos = col; |
436 | while (xpos < col + grid_x - 1) { | | 436 | while (xpos < col + grid_x - 1) { |
437 | if (xpos >= circle_pos[line][0] && xpos < circle_pos[line][1]) | | 437 | if (xpos >= circle_pos[line][0] && xpos < circle_pos[line][1]) |
438 | mvaddch(line, xpos, 113 | A_ALTCHARSET); | | 438 | mvaddch(line, xpos, 113 | A_ALTCHARSET); |
439 | xpos++; | | 439 | xpos++; |
440 | } | | 440 | } |
441 | if (xpos >= circle_pos[line][0] && xpos < circle_pos[line][1]) | | 441 | if (xpos >= circle_pos[line][0] && xpos < circle_pos[line][1]) |
442 | mvaddch(line, xpos, 110 | A_ALTCHARSET); | | 442 | mvaddch(line, xpos, 110 | A_ALTCHARSET); |
443 | } | | 443 | } |
444 | | | 444 | |
445 | line = y_limit / 2; | | 445 | line = y_limit / 2; |
446 | col = x_limit / 2; | | 446 | col = x_limit / 2; |
447 | mvaddch(line, col, 110 | A_ALTCHARSET); | | 447 | mvaddch(line, col, 110 | A_ALTCHARSET); |
448 | mvaddch(line, col - 1, 113 | A_ALTCHARSET); | | 448 | mvaddch(line, col - 1, 113 | A_ALTCHARSET); |
449 | mvaddch(line, col + 1, 113 | A_ALTCHARSET); | | 449 | mvaddch(line, col + 1, 113 | A_ALTCHARSET); |
450 | | | 450 | |
451 | refresh(); | | 451 | refresh(); |
452 | | | 452 | |
453 | getch(); | | 453 | getch(); |
454 | | | 454 | |
455 | endwin(); | | 455 | endwin(); |
456 | | | 456 | |
457 | return EXIT_SUCCESS; | | 457 | return EXIT_SUCCESS; |
458 | } | | 458 | } |
459 | | | 459 | |