I have an SVG in the shape of a cloud, I want you to write a typescript function that takes an integer number between 0 and 100 as input and partially fill the cloud with a solid color. For example, if the input value is 50, I expect half the cloud to be filled with the color blue and the other half to be transparent.
here is the SVG shape ...
O1 思考了 30 秒,然后提供了以下解决方案
const CloudFill: React.FC = ({ percentage }) => { // Ensure percentage is within 0 to 100 const clampedPercentage = Math.max(0, Math.min(percentage, 100)); const yPosition = (24 * (100 - clampedPercentage)) / 100; // Calculate Y position based on percentage // Generate a unique ID for the clip path to avoid ID conflicts if multiple clouds are rendered const clipPathId = React.useMemo(() => `clip-${Math.random().toString(36).substr(2, 9)}`, []); return ( xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" strokeWidth={0.5} stroke="currentColor" width={200} height={200} > {/* Rectangle that determines the filled area based on the percentage */} {/* Filled cloud shape clipped to the percentage */} fill="#5cc6fe" d="M2.25 15a4.5 4.5 0 0 0 4.5 4.5H18a3.75 3.75 0 0 0 1.332-7.257 3 3 0 0 0-3.758-3.848 5.25 5.25 0 0 0-10.233 2.33A4.502 4.502 0 0 0 2.25 15Z" clipPath={`url(#${clipPathId})`} /> {/* Cloud outline */} fill="none" strokeLinecap="round" strokeLinejoin="round" d="M2.25 15a4.5 4.5 0 0 0 4.5 4.5H18a3.75 3.75 0 0 0 1.332-7.257 3 3 0 0 0-3.758-3.848 5.25 5.25 0 0 0-10.233 2.33A4.502 4.502 0 0 0 2.25 15Z" /> );};