我正在学习 C,我得到了这段代码,它绘制了一行像素:
void draw_line(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2) {
// Insert algorithm here.
if (x1 == x2) {
//Draw Horizontal line
unsigned char i;
for (i = y1; i <= y2; i++){
set_pixel(x1, i, 1);
}
} else if (y1 == y2){
//Draw vertical line
unsigned char i;
for (i = x1; i <= x2; i++){
set_pixel(i, y1, 1);
}
我了解它是如何工作的,但不了解如何实现它。有人可以提供一个如何使用它的例子吗?