answersLogoWhite

0

C program to draw parallel lines?

Updated: 4/28/2022
User Avatar

Wiki User

14y ago

Best Answer

/* 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

14y ago
This answer is:
User Avatar

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.

Related questions

How do you divide a triangle into 2 triangles and 2 trapezoids?

Let's assume the triangle has points A, B, and C. Method 1 (3 lines) Draw two lines across the triangle parallel to line segment AB. Now you have two trapezoids and one triangle. Draw another line from C to the any point on the closest of the two lines you just drew, splitting the triangle into two more triangles. Method 2 (2 lines) Draw one line across the triangle parallel to line segment AB. Now you have one trapezoid and one triangle. Draw a second line that passes through C and is perpendicular to AB, splitting the trapezoid into two trapezoids and the triangle into 2 triangles. Method 3 (3 lines) Draw one line from point C to any point on line segment AB. Then draw a line parallel to AC and one parallel to BC, but don't let them cross the line you just drew.


C program to Draw a line chart?

draw a line chart.


How do you draw a softball?

u draw a circle, then u draw two backwards C's with lines through them.


Write a c programme to draw a rainbow?

Write a C program to Draw a RAINBOW and fill the suitable colors ...


Which capital letter does not appear to have parallel or perpendicular C L N Z?

It is C which has no perpendicular or parallel lines


What is the c angle proper name?

supplementary angles on parallel lines.


Which of the following statements is a good definition a Skew lines are lines that do not intersect b Parallel lines are lines that do not intersect c A square is a rectangle with four congruent side?

b &amp; c


Where can you find a sample program to draw a pie chart in a C program?

in BGIDEMO.C, part of TurboC


How is the Transitive Property of Parallel Lines similar to the Transitive Property of Congruence?

If A ~ B and B ~ C then A ~ C. The above statement is true is you substitute "is parallel to" for ~ or if you substitute "is congruent to" for ~.


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 are parallels?

Parallel chords are A sequence of chords consisting of intervals that do not change as the chord moves. For example the chord of C (C,E,G) would be parallel to a following chord ofF (F,A,C)


What is the parallel line to 2x-11?

13