avr/animation/bresenham.c

33 lines
615 B
C
Raw Normal View History

#include <stdlib.h>
2022-07-18 03:01:27 +00:00
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) {
2022-07-18 03:01:27 +00:00
err = m - dt;
} else if (m < 0) {
2022-07-18 03:01:27 +00:00
err = m + dt;
}
2022-07-18 03:01:27 +00:00
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++;
2022-07-18 03:01:27 +00:00
err -= 2 * dt;
}
} else if (m < 0) {
if (err <= 0) {
y--;
2022-07-18 03:01:27 +00:00
err += 2 * dt;
}
}
}
}