I am currently working on a project on arduino which involves drawing a line on a 8x8 rgb led display, given 2 random coordinates, how do I determine which pixels between them should be painted?
Any help is apprecieated
I am currently working on a project on arduino which involves drawing a line on a 8x8 rgb led display, given 2 random coordinates, how do I determine which pixels between them should be painted?
Any help is apprecieated
Here is a simple implementation of the line drawing algorithm mentioned above.
Note that this example will only work if x1
is less than x2
.
void drawLine(int x1, int y1, int x2, int y2) {
int dx = x2 - x1;
int dy = y2 - y1;
for (int x = x1; x < x2; x++){
int y = y1 + dy * (x - x1) / dx;
plot(x, y);
}
}
void plot(int x, int y) {
// Draw each pixel
}