Skip to content

Commit

Permalink
Clean up logo.component.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
mfp22 committed Jul 21, 2023
1 parent 63644ad commit cb58558
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/app/components/logo/logo.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="logo">
<div [ngClass]="dragonNgClass$ | async"></div>
<div [ngClass]="['bg dragon', dragonClass$ | async]"></div>
<p>Press Space to start</p>
</div>
39 changes: 19 additions & 20 deletions src/app/components/logo/logo.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { CommonModule, NgClass } from '@angular/common';
import { Component } from '@angular/core';
import { UntilDestroy } from '@ngneat/until-destroy';
import { concat, timer } from 'rxjs';
import { delay, map, repeat, startWith, takeWhile, tap } from 'rxjs/operators';
import { map, repeat, startWith, takeWhile } from 'rxjs/operators';

@UntilDestroy()
@Component({
selector: 't-logo',
standalone: true,
Expand All @@ -13,29 +11,30 @@ import { delay, map, repeat, startWith, takeWhile, tap } from 'rxjs/operators';
styleUrls: ['./logo.component.scss']
})
export class LogoComponent {
blinkingEyesClass$ = timer(0, 500).pipe(
startWith(0),
map((x) => x + 1),
takeWhile((x) => x < 6),
map((x) => `l${x % 2 === 0 ? 1 : 2}`)
);

runningClass$ = timer(0, 100).pipe(
startWith(0),
map((x) => x + 1),
takeWhile((x) => x <= 40),
map((x) => {
const range = Math.ceil(x / 10);
takeWhile((t) => t < 40),
map((t) => {
const range = Math.ceil((t + 1) / 10);
const side = range % 2 === 0 ? 'l' : 'r';
const runningLegState = x % 2 === 0 ? 3 : 4;
const legState = x === 40 ? 1 : runningLegState;
const runningLegState = t % 2 === 1 ? 3 : 4;
const legState = t === 39 ? 1 : runningLegState;
return `${side}${legState}`;
})
);

dragonNgClass$ = concat(this.blinkingEyesClass$, this.runningClass$).pipe(
delay(5000),
repeat(1000),
map((className) => ['bg dragon', className])
blinkingEyesClass$ = timer(0, 500).pipe(
startWith(0),
takeWhile((t) => t < 5),
map((t) => `l${t % 2 === 1 ? 1 : 2}`)
);

restingClass$ = timer(5000).pipe(
startWith(0),
map(() => 'l2')
);

dragonClass$ = concat(this.runningClass$, this.blinkingEyesClass$, this.restingClass$).pipe(
repeat(Infinity)
);
}

0 comments on commit cb58558

Please sign in to comment.