- Timestamp:
- Nov 9, 2003, 8:46:14 PM (19 years ago)
- Location:
- ttyvaders/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
ttyvaders/trunk/libee/ee.h
r98 r104 76 76 void ee_draw_circle(int, int, int, char); 77 77 void ee_draw_line(int, int, int, int, char); 78 void ee_draw_thin_line(int, int, int, int); 78 79 79 80 int ee_rand(int, int); -
ttyvaders/trunk/libee/line.c
r102 r104 39 39 static uint8_t clip_bits(int, int); 40 40 static void draw_solid_line(struct line*); 41 static void draw_thin_line(struct line*); 41 42 42 43 void ee_draw_line(int x1, int y1, int x2, int y2, char c) … … 52 53 } 53 54 55 void ee_draw_thin_line(int x1, int y1, int x2, int y2) 56 { 57 struct line s; 58 s.x1 = x1; 59 s.y1 = y1; 60 s.x2 = x2; 61 s.y2 = y2; 62 s.draw = draw_thin_line; 63 clip_line(&s); 64 } 65 54 66 static void clip_line(struct line* s) 55 67 { … … 122 134 static void draw_solid_line(struct line* s) 123 135 { 124 int x1 = s->x1; 125 int y1 = s->y1; 126 int x2 = s->x2; 127 int y2 = s->y2; 128 129 int dx = abs(x2-x1); 130 int dy = abs(y2-y1); 131 136 int x1, y1, x2, y2; 137 int dx, dy; 132 138 int xinc, yinc; 139 140 x1 = s->x1; y1 = s->y1; x2 = s->x2; y2 = s->y2; 141 142 dx = abs(x2 - x1); 143 dy = abs(y2 - y1); 133 144 134 145 xinc = (x1 > x2) ? -1 : 1; … … 183 194 } 184 195 196 static void draw_thin_line(struct line* s) 197 { 198 char *charmapx, *charmapy; 199 int x1, y1, x2, y2; 200 int dx, dy; 201 int yinc; 202 203 if(s->x2 >= s->x1) 204 { 205 if(s->y1 > s->y2) 206 charmapx = ",'"; 207 else 208 charmapx = "`."; 209 x1 = s->x1; y1 = s->y1; x2 = s->x2; y2 = s->y2; 210 } 211 else 212 { 213 if(s->y1 > s->y2) 214 charmapx = "`."; 215 else 216 charmapx = ",'"; 217 x2 = s->x1; y2 = s->y1; x1 = s->x2; y1 = s->y2; 218 } 219 220 dx = abs(x2 - x1); 221 dy = abs(y2 - y1); 222 223 if(y1 > y2) 224 { 225 charmapy = ",'"; 226 yinc = -1; 227 } 228 else 229 { 230 yinc = 1; 231 charmapy = "`."; 232 } 233 234 if(dx >= dy) 235 { 236 int dpr = dy << 1; 237 int dpru = dpr - (dx << 1); 238 int delta = dpr - dx; 239 int prev = 0; 240 241 for(; dx>=0; dx--) 242 { 243 ee_goto(x1, y1); 244 if(delta > 0) 245 { 246 ee_putchar(charmapy[1]); 247 x1++; 248 y1 += yinc; 249 delta += dpru; 250 prev = 1; 251 } 252 else 253 { 254 if(prev) 255 ee_putchar(charmapy[0]); 256 else 257 ee_putchar('-'); 258 x1++; 259 delta += dpr; 260 prev = 0; 261 } 262 } 263 } 264 else 265 { 266 int dpr = dx << 1; 267 int dpru = dpr - (dy << 1); 268 int delta = dpr - dy; 269 270 for(; dy >= 0; dy--) 271 { 272 ee_goto(x1, y1); 273 if(delta > 0) 274 { 275 ee_putchar(charmapx[0]); 276 ee_putchar(charmapx[1]); 277 x1++; 278 y1 += yinc; 279 delta += dpru; 280 } 281 else 282 { 283 ee_putchar('|'); 284 y1 += yinc; 285 delta += dpr; 286 } 287 } 288 } 289 } 290 -
ttyvaders/trunk/test/demo.c
r100 r104 30 30 static void demo_dots(void); 31 31 static void demo_lines(void); 32 static void demo_thin_lines(void); 32 33 static void demo_circles(void); 33 34 static void demo_radar(void); … … 74 75 case '3': 75 76 ee_clear(); 77 demo = demo_thin_lines; 78 break; 79 case '4': 80 ee_clear(); 76 81 demo = demo_circles; 77 82 break; 78 case ' 4':83 case '5': 79 84 ee_clear(); 80 85 demo = demo_radar; … … 115 120 ee_putstr("2: lines demo"); 116 121 ee_goto(4, 8); 117 ee_putstr("3: circles demo");122 ee_putstr("3: thin lines demo"); 118 123 ee_goto(4, 9); 119 ee_putstr("4: radar demo"); 124 ee_putstr("4: circles demo"); 125 ee_goto(4, 10); 126 ee_putstr("5: radar demo"); 120 127 121 128 ee_goto(4, yo - 2); … … 127 134 static void demo_dots(void) 128 135 { 136 int xmax = ee_get_width() - 1; 137 int ymax = ee_get_height() - 1; 129 138 int i; 130 139 131 for(i =1000; i--;)140 for(i = 1000; i--;) 132 141 { 133 142 /* Putpixel */ 134 143 ee_color(ee_rand(1, 10)); 135 ee_goto(ee_rand(0, ee_get_width() - 1), 136 ee_rand(0, ee_get_height() - 1)); 144 ee_goto(ee_rand(0, xmax), ee_rand(0, ymax)); 137 145 ee_putchar('#'); 138 146 } … … 142 150 static void demo_lines(void) 143 151 { 152 int w = ee_get_width(); 153 int h = ee_get_height(); 154 144 155 /* Draw lines */ 145 156 ee_color(ee_rand(1, 10)); 146 157 if(clipping) 147 158 { 148 ee_draw_line(ee_rand(- ee_get_width(), 2 * ee_get_width()), 149 ee_rand(- ee_get_height(), 2 * ee_get_height()), 150 ee_rand(- ee_get_width(), 2 * ee_get_width()), 151 ee_rand(- ee_get_height(), 2 * ee_get_height()), 152 '#'); 159 ee_draw_line(ee_rand(- w, 2 * w), ee_rand(- h, 2 * h), 160 ee_rand(- w, 2 * w), ee_rand(- h, 2 * h), '#'); 153 161 } 154 162 else 155 163 { 156 ee_draw_line(ee_rand(0, ee_get_width()), 157 ee_rand(0, ee_get_height()), 158 ee_rand(0, ee_get_width()), 159 ee_rand(0, ee_get_height()), 160 '*'); 164 ee_draw_line(ee_rand(0, w - 1), ee_rand(0, h - 1), 165 ee_rand(0, w - 1), ee_rand(0, h - 1), '*'); 166 } 167 ee_refresh(); 168 } 169 170 static void demo_thin_lines(void) 171 { 172 int w = ee_get_width(); 173 int h = ee_get_height(); 174 175 /* Draw lines */ 176 ee_color(ee_rand(1, 10)); 177 if(clipping) 178 { 179 ee_draw_thin_line(ee_rand(- w, 2 * w), ee_rand(- h, 2 * h), 180 ee_rand(- w, 2 * w), ee_rand(- h, 2 * h)); 181 } 182 else 183 { 184 ee_draw_thin_line(ee_rand(0, w), ee_rand(0, h), 185 ee_rand(0, w), ee_rand(0, h)); 161 186 } 162 187 ee_refresh(); … … 165 190 static void demo_circles(void) 166 191 { 192 int w = ee_get_width(); 193 int h = ee_get_height(); 194 167 195 /* Draw circles */ 168 196 if(clipping) 169 197 { 170 198 ee_color(ee_rand(1, 10)); 171 ee_draw_circle(ee_rand(- ee_get_width(), 2 * ee_get_width()),172 ee_rand(- ee_get_height(), 2 * ee_get_height()),173 ee_rand(0, ee_get_width() + ee_get_height()) / 2,199 ee_draw_circle(ee_rand(- w, 2 * w), 200 ee_rand(- h, 2 * h), 201 ee_rand(0, (w + h) / 2), 174 202 '#'); 175 203 } 176 204 else 177 205 { 178 int x = ee_rand(0, ee_get_width()); 179 int y = ee_rand(0, ee_get_height()); 180 int r = ee_rand(0, (ee_get_width() + ee_get_height()) / 2); 181 182 if(x - r < 0 || x + r >= ee_get_width() || 183 y - r < 0 || y + r >= ee_get_height()) 206 int x = ee_rand(0, w); 207 int y = ee_rand(0, h); 208 int r = ee_rand(0, (w + h) / 2); 209 210 if(x - r < 0 || x + r >= w || y - r < 0 || y + r >= h) 184 211 { 185 212 demo_circles();
Note: See TracChangeset
for help on using the changeset viewer.