Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Рисование круга(для толщины линии)
- void draw_Circle(struct Png *image, int x0, int y0, int line_fat, int width_pix, int Red,
- int
- Green,
- int Blue) {
- int x = 0;
- int rad = line_fat / 2;
- int y = rad;
- int start0 = y0 - rad;
- int end1 = y0 + rad;
- int phi = 1 - 2 * rad;
- int err;
- while (y >= 0) {
- paint_pixel(image, x0 + x, y0 + y, width_pix, Red, Green, Blue);
- paint_pixel(image, x0 + x, y0 - y, width_pix, Red, Green, Blue);
- paint_pixel(image, x0 - x, y0 + y, width_pix, Red, Green, Blue);
- paint_pixel(image, x0 - x, y0 - y, width_pix, Red, Green, Blue);
- err = 2 * (phi + y) - 1;
- while (start0 <= y0) {
- for (int i = abs(x - x0); i < (x + x0); i++) {
- paint_pixel(image, i, start0, width_pix, Red, Green, Blue);
- paint_pixel(image, i, end1, width_pix, Red, Green, Blue);
- }
- if (err > 0) {
- start0++;
- end1--;
- }
- break;
- }
- if (phi < 0 && err <= 0) {
- ++x;
- phi += 2 * x + 1;
- continue;
- }
- err = 2 * (phi - x) - 1;
- if (phi > 0 && err > 0) {
- --y;
- phi += 1 - 2 * y;
- continue;
- }
- ++x;
- phi += 2 * (x - y);
- --y;
- }
- }
- void paint_line(struct Png *image, int width_pix, int x0, int y0, int x1, int y1, int line_fat,
- int Red, int Green, int Blue) {
- int A, B, sign1;
- A = y1 - y0;
- B = x0 - x1;
- if (abs(A) > abs(B)) sign1 = 1;
- else sign1 = -1;
- int signA, signB;
- if (A < 0) signA = -1;
- else signA = 1;
- if (B < 0) signB = -1;
- else signB = 1;
- int f = 0;
- paint_pixel(image, x0, y0, width_pix, Red, Green, Blue);
- draw_Circle(image, x0, y0, line_fat, width_pix, Red, Green, Blue);
- int x = x0, y = y0;
- if (sign1 == -1) {
- do {
- f += A * signA;
- if (f > 0) {
- f -= B * signB;
- y += signA;
- }
- x -= signB;
- paint_pixel(image, x, y, width_pix, Red, Green, Blue);
- draw_Circle(image, x, y, line_fat, width_pix, Red, Green, Blue);
- } while (x != x1 || y != y1);
- } else {
- do {
- f += B * signB;
- if (f > 0) {
- f -= A * signA;
- x -= signB;
- }
- y += signA;
- paint_pixel(image, x, y, width_pix, Red, Green, Blue);
- draw_Circle(image, x, y, line_fat, width_pix, Red, Green, Blue);
- } while (x != x1 || y != y1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement