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_pixel, int Red,
- int
- Green,
- int Blue) {
- int x = 0;
- int radius = line_fat / 2;
- int y = radius;
- int start = y0 - radius;
- int end = y0 + radius;
- int delta = 1 - 2 * radius;
- int error;
- while (y >= 0) {
- paint_pixel(image, x0 + x, y0 + y, width_pixel, Red, Green, Blue);
- paint_pixel(image, x0 + x, y0 - y, width_pixel, Red, Green, Blue);
- paint_pixel(image, x0 - x, y0 + y, width_pixel, Red, Green, Blue);
- paint_pixel(image, x0 - x, y0 - y, width_pixel, Red, Green, Blue);
- error = 2 * (delta + y) - 1;
- while (start <= y0) {
- for (int i = abs(x - x0); i < (x + x0); i++) {
- paint_pixel(image, i, start, width_pixel, Red, Green, Blue);
- paint_pixel(image, i, end, width_pixel, Red, Green, Blue);
- }
- if (error > 0) {
- start++;
- end--;
- }
- break;
- }
- if (delta < 0 && error <= 0) {
- ++x;
- delta += 2 * x + 1;
- continue;
- }
- error = 2 * (delta - x) - 1;
- if (delta > 0 && error > 0) {
- --y;
- delta += 1 - 2 * y;
- continue;
- }
- ++x;
- delta += 2 * (x - y);
- --y;
- }
- }
- void paint_line(struct Png *image, int width_pixel, int x0, int y0, int x1, int y1, int line_fat,
- int Red, int Green, int Blue) {
- int A, B, sign;
- A = y1 - y0;
- B = x0 - x1;
- if (abs(A) > abs(B)) sign = 1;
- else sign = -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_pixel, Red, Green, Blue);
- draw_Circle(image, x0, y0, line_fat, width_pixel, Red, Green, Blue);
- int x = x0, y = y0;
- if (sign == -1) {
- do {
- f += A * signa;
- if (f > 0) {
- f -= B * signb;
- y += signa;
- }
- x -= signb;
- paint_pixel(image, x, y, width_pixel, Red, Green, Blue);
- draw_Circle(image, x, y, line_fat, width_pixel, 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_pixel, Red, Green, Blue);
- draw_Circle(image, x, y, line_fat, width_pixel, Red, Green, Blue);
- } while (x != x1 || y != y1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement