Rev 7190 | Rev 7257 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7190 | Rev 7254 | ||
---|---|---|---|
Line -... | Line 1... | ||
- | 1 | #define MAX_CELL_SIZE 256 |
|
- | 2 | ||
1 | struct _image |
3 | struct _image |
2 | { |
4 | { |
3 | unsigned rows, columns; |
5 | unsigned rows, columns; |
4 | dword mas[32*32]; |
6 | dword mas[MAX_CELL_SIZE*MAX_CELL_SIZE]; |
5 | dword img; |
7 | dword img; |
6 | void create(); |
8 | void create(); |
7 | void set_pixel(); |
9 | void set_pixel(); |
- | 10 | void draw_line(); |
|
- | 11 | void fill(); |
|
8 | void set_image(); |
12 | void set_image(); |
9 | dword get_pixel(); |
13 | dword get_pixel(); |
10 | dword get_image(); |
14 | dword get_image(); |
11 | void move(); |
15 | void move(); |
12 | }; |
16 | }; |
Line 22... | Line 26... | ||
22 | void _image::set_pixel(int _r, _c, _color) |
26 | void _image::set_pixel(int _r, _c, _color) |
23 | { |
27 | { |
24 | mas[columns*_r + _c] = _color; |
28 | mas[columns*_r + _c] = _color; |
25 | } |
29 | } |
Line -... | Line 30... | ||
- | 30 | ||
- | 31 | void _image::draw_line(int x1, int y1, int x2, int y2, dword color) { |
|
- | 32 | int dx, dy, signX, signY, error, error2; |
|
- | 33 | ||
- | 34 | dx = x2 - x1; |
|
- | 35 | ||
- | 36 | if (dx < 0) |
|
- | 37 | dx = -dx; |
|
- | 38 | ||
- | 39 | dy = y2 - y1; |
|
- | 40 | ||
- | 41 | if (dy < 0) |
|
- | 42 | dy = -dy; |
|
- | 43 | ||
- | 44 | if (x1 < x2) |
|
- | 45 | signX = 1; |
|
- | 46 | else |
|
- | 47 | signX = -1; |
|
- | 48 | ||
- | 49 | if (y1 < y2) |
|
- | 50 | signY = 1; |
|
- | 51 | else |
|
- | 52 | signY = -1; |
|
- | 53 | ||
- | 54 | error = dx - dy; |
|
- | 55 | ||
- | 56 | set_pixel(y2, x2, color); |
|
- | 57 | ||
- | 58 | while((x1 != x2) || (y1 != y2)) |
|
- | 59 | { |
|
- | 60 | set_pixel(y1, x1, color); |
|
- | 61 | ||
- | 62 | error2 = error * 2; |
|
- | 63 | ||
- | 64 | if(error2 > calc(-dy)) |
|
- | 65 | { |
|
- | 66 | error -= dy; |
|
- | 67 | x1 += signX; |
|
- | 68 | } |
|
- | 69 | ||
- | 70 | if(error2 < dx) |
|
- | 71 | { |
|
- | 72 | error += dx; |
|
- | 73 | y1 += signY; |
|
- | 74 | } |
|
- | 75 | } |
|
- | 76 | } |
|
- | 77 | ||
- | 78 | void _image::fill(int _r, _c, _color) |
|
- | 79 | { |
|
- | 80 | #define MARKED 6 |
|
- | 81 | int r, c, i, restart; |
|
- | 82 | ||
- | 83 | dword old_color = get_pixel(_r, _c); |
|
- | 84 | set_pixel(_r, _c, MARKED); |
|
- | 85 | ||
- | 86 | do { |
|
- | 87 | restart=false; |
|
- | 88 | for (r = 0; r < rows; r++) |
|
- | 89 | for (c = 0; c < columns; c++) |
|
- | 90 | { |
|
- | 91 | IF (get_pixel(r,c) != old_color) continue; |
|
- | 92 | IF (get_pixel(r,c) == MARKED) continue; |
|
- | 93 | ||
- | 94 | IF (c>0) && (get_pixel(r,c-1) == MARKED) set_pixel(r,c,MARKED); |
|
- | 95 | IF (r>0) && (get_pixel(r-1,c) == MARKED) set_pixel(r,c,MARKED); |
|
- | 96 | IF (c |
|
- | 97 | IF (r |
|
- | 98 | ||
- | 99 | IF (get_pixel(r,c)==MARKED) restart=true; |
|
- | 100 | } |
|
- | 101 | }while(restart); |
|
- | 102 | ||
- | 103 | for (i=0; i |
|
- | 104 | IF (mas[i]==MARKED) mas[i] = _color; |
|
- | 105 | } |
|
26 | 106 | ||
27 | dword _image::get_pixel(int _r, _c) |
107 | dword _image::get_pixel(int _r, _c) |
28 | { |
108 | { |
29 | return mas[columns*_r + _c]; |
109 | return mas[columns*_r + _c]; |