1- import { deg2rad , Point , Vector } from '../../api/canvas.ts' ;
1+ import { deg2rad , PI2 , Point , Vector } from '../../api/canvas.ts' ;
22
33interface IMemo {
44 when : number ;
@@ -8,8 +8,10 @@ interface IMemo {
88
99let raf = 0 ;
1010let ctx : CanvasRenderingContext2D ;
11- const R = 40 ;
11+ const R = 20 ;
1212const D = 2 * R ;
13+ const LINE_WIDTH = 4 ;
14+ const SHADOW_WIDTH = 4 ;
1315const pRotationAxis = new Point ( R , R ) ;
1416const WHITE = 'rgb(100% 100% 100%)' ;
1517const BLACK = 'rgb(0% 0% 0%)' ;
@@ -47,8 +49,8 @@ function initContext(_ctx: CanvasRenderingContext2D) {
4749 ctx . canvas . width = D ;
4850 ctx . canvas . height = D ;
4951 ctx . lineCap = 'round' ;
50- ctx . lineWidth = 4 ;
51- ctx . shadowBlur = 4 ;
52+ ctx . lineWidth = LINE_WIDTH ;
53+ ctx . shadowBlur = SHADOW_WIDTH ;
5254
5355 onColourSchemeChange ( ( scheme ) => {
5456 primaryColour = scheme === 'dark' ? WHITE : BLACK ;
@@ -62,24 +64,37 @@ function draw() {
6264 const drawTime = Date . now ( ) ;
6365 ctx . clearRect ( 0 , 0 , D , D ) ;
6466
65- for ( let n = 0 , N = memory . length ; n < N ; n ++ ) {
66- const memo = memory [ n ] ;
67- memo . age = drawTime - memo . when ;
68- drawLine ( memo ) ;
69- }
67+ if ( memory . length ) {
68+ for ( let n = 0 , N = memory . length ; n < N ; n ++ ) {
69+ const memo = memory [ n ] ;
70+ memo . age = drawTime - memo . when ;
71+ drawLine ( memo ) ;
72+ }
7073
71- let n = memory . length ;
72- while ( n -- ) {
73- if ( memory [ n ] . age >= ANIMATION_DURATION ) {
74- memory . pop ( ) ;
75- } else {
76- break ;
74+ let n = memory . length ;
75+ while ( n -- ) {
76+ if ( memory [ n ] . age >= ANIMATION_DURATION ) {
77+ memory . pop ( ) ;
78+ } else {
79+ break ;
80+ }
7781 }
82+ } else {
83+ drawCenter ( ) ;
7884 }
7985
8086 raf = requestAnimationFrame ( draw ) ;
8187}
8288
89+ function drawCenter ( ) {
90+ ctx . save ( ) ;
91+ ctx . beginPath ( ) ;
92+ ctx . arc ( pRotationAxis . x , pRotationAxis . y , 0.5 , 0 , PI2 ) ;
93+ ctx . stroke ( ) ;
94+ ctx . closePath ( ) ;
95+ ctx . restore ( ) ;
96+ }
97+
8398function drawLine ( memo : IMemo ) {
8499 const length = R - memo . age * R / ANIMATION_DURATION ;
85100 const p = memo . vector . setLength ( length ) . toPoint ( pRotationAxis ) ;
@@ -95,9 +110,6 @@ function drawLine(memo: IMemo) {
95110
96111type TColourScheme = 'light' | 'dark' ;
97112
98- /**
99- * NOTE: if OS is dark but devtools is default - then scheme is dark
100- */
101113export function onColourSchemeChange (
102114 callback : ( scheme : TColourScheme ) => void ,
103115) {
0 commit comments