Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void plotTriangleLineColorBlendedInt(Vec2 p1, Vec2 p2, Vec2_int center, Span* edge, uint8_t start_color, uint8_t end_color)
- {
- int offset;
- int counter;
- int x = (int)(p1.x + 0.5) + center.x;
- int y = (int)(p1.y + 0.5) + center.y;
- int x_diff = (int)(p2.x - p1.x + 0.5);
- int y_diff = (int)(p2.y - p1.y + 0.5);
- int x_sign = SIGN(x_diff);
- int y_sign = SIGN(y_diff);
- int color = start_color;
- int color_diff = end_color - start_color;
- int color_sign = SIGN(color_diff);
- int color_counter;
- char* edge_name;
- uint8_t test_color;
- x_diff = abs(x_diff);
- y_diff = abs(y_diff);
- color_diff = abs(color_diff);
- if (edge == &LeftEdge)
- {
- test_color = 200;
- edge_name = "Left";
- }
- else if (edge == &RightEdge)
- {
- test_color = 112;
- edge_name = "Right";
- }
- if (y_diff > x_diff)
- {
- color_counter = y_diff/2;
- counter = y_diff/2;
- // beginning at y_diff/2 instead of 0 fixes a minor inaccuracy
- for (offset = 0; offset < y_diff; offset++)
- {
- // move along the y coordinate
- y += y_sign;
- // check whether to move on the y coordinate
- counter += x_diff;
- while (counter > y_diff)
- {
- counter -= y_diff;
- x += x_sign;
- }
- edge->offset[y] = x;
- edge->color[y] = (uint8_t)color;
- // check whether to step the color value forwards
- color_counter += color_diff;
- while (color_counter > y_diff)
- {
- color_counter -= y_diff;
- color += color_sign;
- }
- //printf("Writing: %s Y: %d X:%d\n", edge_name, y, x);
- //delay(100);
- if (KEY_IS_PRESSED (KEY_Q))
- SET_PIXEL(edge->offset[y], y, test_color);
- else if (KEY_IS_PRESSED (KEY_R))
- SET_PIXEL(edge->offset[y], y, edge->color[y]);
- }
- }
- else if (x_diff > y_diff)
- {
- color_counter = x_diff/2;
- counter = x_diff/2;
- // beginning at y_diff/2 instead of 0 fixes a minor inaccuracy
- for (offset = 0; offset < x_diff; offset++)
- {
- // move along the x coordinate
- x += x_sign;
- // check whether to move on the x coordinate
- counter += y_diff;
- while (counter > x_diff)
- {
- counter -= x_diff;
- y += y_sign;
- }
- edge->offset[y] = x;
- edge->color[y] = (uint8_t)color;
- // check whether to step the color value forwards
- color_counter += color_diff;
- while (color_counter > x_diff)
- {
- color_counter -= x_diff;
- color += color_sign;
- }
- //printf("Writing: %s Y: %d X:%d\n", edge_name, y, x);
- //delay(100);
- if (KEY_IS_PRESSED (KEY_Q))
- SET_PIXEL(edge->offset[y], y, test_color);
- else if (KEY_IS_PRESSED (KEY_R))
- SET_PIXEL(edge->offset[y], y, edge->color[y]);
- }
- }
- }
Add Comment
Please, Sign In to add comment