import { Circle } from "./Circle" ; export class AnimatedCircle extends Circle { public dx : number ; public dy : number ; constructor ( x , y , radius , dx , dy ) { super ( x , y , radius ) ; this . dx = dx ; this . dy = dy ; } public bounceOf ( minX , maxX , minY , maxY ) { if ( this . x + this . radius > maxX || this . x - this . radius < minX ) this . dx = - this . dx ; if ( this . y + this . radius > maxY || this . y - this . radius < minY ) this . dy = - this . dy ; } public setNewPositionWhenOut ( minX , maxX , minY , maxY ) { if ( this . x > maxX || this . x < minX || this . y > maxY || this . y < minY ) { this . x = Math . random ( ) * maxX ; this . y = Math . random ( ) * maxY ; } } public update ( ) { this . translateByVector ( { x : this . dx , y : this . dy } ) ; } }