Click here to Skip to main content
15,120,326 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:

How to draw line ( slanting line ) vertically ???

For Ex :
Consider X1 = 100, Y1 = 80; And X2=100, Y2 = 185;

So This is for Straight LINE

for(nRow = Y1; nRow < Y2; nRow++)
  for(nCol = X1; nCol < X2; nCol++)
     nPixPos = nRow*nEffectiveWidth+nCol*3; 

     Image[nPixPos] = 0 ;
     Image[nPixPos+1] = 0 ;
     Image[nPixPos+2] = 0 ;

If i want to draw Line for EX :X1 = 100 , Y1 = 80 and X2 = 115 , Y2 = 185

HOW TO DRAW Slanting Line for the above CO-ORDINATES - how to use for loop then ???

1 solution

Oh boy! I haven't implemented one of those in what...twenty years?

There are a lot of ways to do it: some simple, and some much, much better. Wiki has a list:[^] - pick one you like and off you go!

(But don't expect them to look as good as the standard Windows line drawing functions unless you put in a lot of work. Look up antialiasing while you are at it.)
JackDingler 10-May-12 15:38pm
We don't do much in the way of primitives work anymore. The current graphics cards and APIs handle that very well.

It is a fascinating area to work in though.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900