2
0

added some rotational sidekicks

This commit is contained in:
2018-08-29 12:48:14 +02:00
parent c3afe0c4e9
commit da36b71b2c
6 changed files with 24 additions and 12 deletions

View File

@@ -32,6 +32,8 @@ import { MathService } from './../services/math.service';
import { GraphService } from '../services/graph.service';
import { AnimationService } from './../services/animation.service';
const ANIMATION_INTERVAL = 60;
@Directive({
selector: '[guilloche]'
})
@@ -81,7 +83,7 @@ export class GuillocheDirective implements OnChanges, OnDestroy {
this.graph.end.point
];
this.medianPoint = this.math.medianOfCurve(this.initialCurve);
this.medianIndex = this.math.medianIndex(this.initialNodes);
this.medianIndex = this.math.medianIndex(this.initialCurve);
if (this.graphService.isAnimated) {
this.graph.nodes = this.graph.nodes.slice().map((node, i) => {
@@ -96,7 +98,11 @@ export class GuillocheDirective implements OnChanges, OnDestroy {
const bounceAmplitude = Math.round(Math.random() * 150);
return this.math.bounce(bounceAmplitude, 3);
});
this.animationInterval = setInterval(() => this.animateGraph(), 40);
let i = 0;
this.animationInterval = setInterval(() => {
// this.animateGraph();
this.animateGraph(i++ % 1000 / 10000);
}, ANIMATION_INTERVAL);
} else {
if (this.animationInterval) {
this.bounce = null;
@@ -118,12 +124,13 @@ export class GuillocheDirective implements OnChanges, OnDestroy {
this.guillocheChanged();
}
private animateGraph() {
private animateGraph(x) {
const graphs = this.spreadLines([
this.graph.start.point,
this.graph.start.direction,
...this.graph.nodes.map((point, i) => {
return this.graphService.shiftPoint(point, point.ascent, this.bounces[i].next().value);
const ascent = point.ascent * Math.sin(Math.PI * x);
return this.graphService.shiftPoint(point, ascent, this.bounces[i].next().value);
}),
this.graph.end.direction,
this.graph.end.point,