import { ColorUtil } from "../../utils/ColorUtil" ; import { ParamUpdater } from "./ParamUpdater" ; export class StyleColorUpdater { private _key : string ; private _color : string ; private _r : ParamUpdater ; private _g : ParamUpdater ; private _b : ParamUpdater ; constructor ( key , colorCode ) { this . _key = key ; this . _color = colorCode ; const rgb = ColorUtil . getRGBList ( colorCode ) ; this . _r = new ParamUpdater ( "r" , rgb [ 0 ] ) ; this . _g = new ParamUpdater ( "g" , rgb [ 1 ] ) ; this . _b = new ParamUpdater ( "b" , rgb [ 2 ] ) ; } init ( start ) { const rgb = ColorUtil . getRGBList ( start ) ; this . _r . init ( Number ( rgb [ 0 ] ) ) ; this . _g . init ( Number ( rgb [ 1 ] ) ) ; this . _b . init ( Number ( rgb [ 2 ] ) ) ; } update ( progress ) { return `rgb(${ this . _r . update ( progress ) },${ this . _g . update ( progress ) },${ this . _b . update ( progress ) })` ; } getDelta ( ) { const dr = this . _r . getDelta ( ) ; const dg = this . _g . getDelta ( ) ; const db = this . _b . getDelta ( ) ; return Math . max ( Math . sqrt ( dr * dr + dg * dg + db * db ) ) ; } clone ( ) { return new StyleColorUpdater ( this . _key , this . _color ) ; } toString ( ) { return `${ this . _key }:${ this . _color }` ; } }