answersLogoWhite

0

/* This is an incomplete program. The function below will draw two parallel lines, but depends on a putpixel function that is not defined here. Also of course needs a main function calling it somewhere, and all the other usual necessities. */

/* draw a line from point (x1, y1) to point (x2, y2) and another one that is (xoffset, yoffset) pixels away from it. Uses Bresenham's line algorithm and depends on a "putpixel" function */

void pline(int x1, int y1, int x2, int y2, int xoffset, yoffset){

int n, deltax, deltay, sgndeltax, sgndeltay, deltaxabs, deltayabs, x, y, drawx, drawy;

deltax = x2 - x1;

deltay = y2 - y1;

deltaxabs = abs(deltax);

deltayabs = abs(deltay);

sgndeltax = sgn(deltax);

sgndeltay = sgn(deltay);

x = deltayabs >> 1;

y = deltaxabs >> 1;

drawx = x1;

drawy = y1;

putpixel(drawx, drawy);

putpixel(drawx + xoffset, drawy + yoffset);

if(deltaxabs >= deltayabs){

for(n = 0; n < deltaxabs; n++){

y += deltayabs;

if(y >= deltaxabs){

y -= deltaxabs;

drawy += sgndeltay;

}

drawx += sgndeltax;

putpixel(drawx, drawy);

putpixel(drawx + xoffset, drawy + yoffset);

}

}else{

for(n = 0; n < deltayabs; n++){

x += deltaxabs;

if(x >= deltayabs){

x -= deltayabs;

drawx += sgndeltax;

}

drawy += sgndeltay;

putpixel(drawx, drawy);

putpixel(drawx + xoffset, drawy + yoffset);

}

}

}

User Avatar

Wiki User

15y ago

Still curious? Ask our experts.

Chat with our AI personalities

ProfessorProfessor
I will give you the most educated answer.
Chat with Professor
JordanJordan
Looking for a career mentor? I've seen my fair share of shake-ups.
Chat with Jordan
MaxineMaxine
I respect you enough to keep it real.
Chat with Maxine

Add your answer:

Earn +20 pts
Q: C program to draw parallel lines?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Other Math

What is the c angle proper name?

supplementary angles on parallel lines.


What letters in the alphabet have parallel lines?

Parallel lines are lines that never intersect or never cross and meet together. There is 4 letters in the alphabet that have parallel lines. E,F,H,I, and N. The letters A,X, and T are examples of intersecting lines. the lines meet together.


What is the difference between the transitive property of congruence and parallel lines?

They are similar because they both have the definition of if A=B and B=C then A=C. They are different because since every parallel line is equal it shows that they do not exactly match up because of the transitive property of congruence.


How would you check correctness of a parabola?

The answer depends on what information you have and what form you are checking.The functional form of a parabola is y = ax2+ bx + c where a, b and c are real and a >0. If that is the case then, functionally it is a parabola.The graph of a parabola has a single turning point and is symmetric about its axis. But that is not enough. The graph of y = ax4+ bx2 + c or y = ax6+ bx3+ c have similar shapes but they are not parabolas.Find the axis. This should be easy because the parabola is symmetric about its axis. Draw a number of lines parallel to the axis. Where they meet the parabola, reflect them. These reflected lines should all meet at the same point which is the focus of the parabola.


How do you write an Algorithm for a C plus plus Program?

You don't write an algorithm for a C++ program, unless you are documenting the C++ program after-the-fact. The normal procedure is to write the algorithm first, in a language independent fashion, and then translate that stated algorithm into C++ code, or into whatever language you wish.