hexagram/src/anim.c

52 lines
966 B
C
Raw Normal View History

2024-01-19 16:33:54 -05:00
#include <stdlib.h>
#include <string.h>
2024-01-19 16:33:54 -05:00
#include <hexagram/anim.h>
void hexagram_anim_init(hexagram_anim *anim) {
anim->current = 0;
gettimeofday(&anim->start, NULL);
}
static inline double tv_seconds(struct timeval *tv) {
return (double)tv->tv_sec + (double)tv->tv_usec / 1000000.0;
}
static inline double stop_offset(hexagram_anim *anim, size_t index) {
double offset = 0.0;
size_t i;
for (i=0; i<index; i++) {
offset += anim->stops[i].duration;
}
return offset;
}
static inline size_t stop_index(hexagram_anim *anim, double offset) {
return 0;
}
2024-01-19 16:33:54 -05:00
int hexagram_anim_step(hexagram_anim *anim, cairo_t *bg, cairo_t *fg) {
struct timeval tv;
double offset, interval;
size_t i;
if (anim->current >= anim->count) {
goto done;
}
gettimeofday(&anim->now, NULL);
timersub(&anim->now, &anim->start, &tv);
interval = tv_seconds(&tv);
done:
return 0;
2024-01-19 16:33:54 -05:00
next:
return 1;
2024-01-19 16:33:54 -05:00
}