import * as React from 'react'; import Hitu from '@ant-design/hitu'; import './Background.less'; const RANDOM_OFFSET = 50; const TOTAL_FRAMES = 600; function randomFrames(x: number, y: number): any[] { const common = { x, y, cubic: Hitu.CUBIC_EASE_IN_OUT }; return [ { frame: 0, ...common, }, { frame: TOTAL_FRAMES / 2, ...common, x: x - Math.random() * RANDOM_OFFSET * 2 + RANDOM_OFFSET, y: y - Math.random() * RANDOM_OFFSET * 2 + RANDOM_OFFSET, }, { frame: TOTAL_FRAMES, ...common, }, ]; } const ShadowSize = 30; // =================================== Circle 1 =================================== const CircleSize1 = 140; const Circle1 = () => ( ); Circle1.width = (CircleSize1 + ShadowSize) * 2; Circle1.height = (CircleSize1 + ShadowSize) * 2; // =================================== Circle 2 =================================== const CircleSize2 = 200; const Circle2 = () => ( ); Circle2.width = (CircleSize2 + ShadowSize) * 2; Circle2.height = (CircleSize2 + ShadowSize) * 2; // ==================================== Rect 1 ==================================== const ReactSize1 = 90; const React1 = () => ( ); React1.width = (ReactSize1 + ShadowSize) * 2; React1.height = (ReactSize1 + ShadowSize) * 2; // ================================== Diamond 1 =================================== const DiamondSize1 = 400; const Diamond1 = () => { const start = ShadowSize; const center = ShadowSize + DiamondSize1; const end = ShadowSize + DiamondSize1 * 2; return ( ); }; Diamond1.width = (DiamondSize1 + ShadowSize) * 2; Diamond1.height = (DiamondSize1 + ShadowSize) * 2; export default function Background() { const [circleFrames, setCircleFrames] = React.useState(randomFrames(550, 200)); const [circle2Frames, setCircle2Frames] = React.useState(randomFrames(0, 448)); const [reactFrames, setReactFrames] = React.useState(randomFrames(1400, 300)); const [diamondFrames, setDiamondFrames] = React.useState(randomFrames(1100, -230)); return (
background { if (frame === 0) { setCircleFrames(randomFrames(550, 200)); setCircle2Frames(randomFrames(0, 448)); setReactFrames(randomFrames(1400, 300)); setDiamondFrames(randomFrames(1100, -230)); } }} shapes={[ { type: 'shape', source: Circle1, frames: circleFrames, }, { type: 'shape', source: Circle2, frames: circle2Frames, }, { type: 'shape', source: React1, frames: reactFrames, }, { type: 'shape', source: Diamond1, frames: diamondFrames, }, ]} />
); }