superbrew
Member
Hello again, i am trying to write a function to draw a line from (x1,y1) to (x2,y2) on a GLCD. What I have so far only works if the slope of the line is 1 and x1,y1 values are less than x2,y2 values. Please be patient with me, lol.
Code:
void dline(unsigned char x1, unsigned char x2,unsigned char y1,unsigned char y2){
signed int dx,dy;
double slope,draw;
//plot start
plot(x1,y1);
//find delta and delta y
dx=(x2-x1);
dy=(y2-y1);
//find slope
slope = dx/dy;
//draw the line
while(dx--){
for(draw=0;draw<=(slope-1);draw++)
{
plot(x1,y1);
y1++;
}
x1++;
}
}