this.height = height;
this.slope = slope;
this.completed = false;
+ this.initial_offset = this.speed > 0 ? (2000 - window.innerWidth) / 2 - 100 : (2000 + window.innerWidth) / 2 + 100;
if (card_backs) {
this.cards = [...FIFTY_TWO_CARD_DECK].map(card => this.card_image(null));
this.cards = [...FIFTY_TWO_CARD_DECK].map(card => this.card_image(card));
}
- this.schedule_frame(initial_time);
+ this.start_timestamp = new Date().getTime();
+ this.schedule_frame(this.start_timestamp + initial_time);
}
card_image(card) {
}
schedule_frame(time) {
- this.render(time);
+ this.render(time - this.start_timestamp);
if (!this.completed) {
- setTimeout(() => this.schedule_frame(time + this.timestep), this.timestep);
+ const now = new Date().getTime();
+ const next_time = (Math.floor(now / this.timestep) + 1) * this.timestep;
+ setTimeout(() => this.schedule_frame(next_time), next_time - now);
}
}
render(time) {
let x = time;
- const initial_offset = this.speed > 0 ? -100 : 2100;
for (const card of this.cards) {
- card.setAttribute("x", x * this.speed + initial_offset);
+ card.setAttribute("x", x * this.speed + this.initial_offset);
card.setAttribute("y", Math.sin(x * this.speed / this.slope) * this.height + 215);
x -= 40;
}