Question: Consider the following line drawing code: int Image[20][20]; void draw_line(int x1, int y1, int x2, int y2, int value) { // Calculate step size double
Consider the following line drawing code:
int Image[20][20]; void draw_line(int x1, int y1, int x2, int y2, int value) {
// Calculate step size double dx = x2 - x1; double dy = y2 - y1;
// Draw points on line double x = x1 + 0.5; for (int y = y1; y <= y2; y++) {
Image[y][(int)x] = value;
x += dx/dy; }
}
a) What pixels in the image will be filled in when drawing a line from (10,5) to (15,15)?
b) What will happen if we try to draw a line with dx < 0?
c) What will happen if we try to draw a line with dy < 0?
d) What will happen if we try to draw a line with dy = 0?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
