avr/animation/bresenham.c

33 lines
615 B
C

#include <stdlib.h>
void bresenham_time(int t1, int y1, int t2, int y2) {
int dt = t2 - t1;
int dy = y2 - y1;
int m = 2 * dy;
int err = 0;
if (m > 0) {
err = m - dt;
} else if (m < 0) {
err = m + dt;
}
for (int t = t1, y = y1; t <= t2; t++) {
printf("(%d, %d) [%d]\n", t, y, err);
err += m;
if (m > 0) {
if (err >= 0) {
y++;
err -= 2 * dt;
}
} else if (m < 0) {
if (err <= 0) {
y--;
err += 2 * dt;
}
}
}
}