Spaces:
Running
Running
Download algospaced-ui/src/components/map/RealisticTree.tsx from iamfebin/algospaced-dsa: direct link, hf CLI and curl.
- Browser
- Download file 11.4 kB
-
https://huggingface.co/spaces/iamfebin/algospaced-dsa/resolve/main/algospaced-ui/src/components/map/RealisticTree.tsx
- Command line
-
hf download hf://spaces/iamfebin/algospaced-dsa/algospaced-ui/src/components/map/RealisticTree.tsx
-
curl -L -o RealisticTree.tsx https://huggingface.co/spaces/iamfebin/algospaced-dsa/resolve/main/algospaced-ui/src/components/map/RealisticTree.tsx
11.4 kB
| import React from 'react'; | |
| import type { TreeData, MapTheme } from '../../types/mapTypes'; | |
| interface RealisticTreeProps { | |
| tree: TreeData; | |
| theme: MapTheme; | |
| } | |
| export const RealisticTree: React.FC<RealisticTreeProps> = ({ tree, theme }) => { | |
| const { x, y, scale = 1, type = 'pine' } = tree; | |
| const isDark = theme.id !== 'parchment'; | |
| const pencil = theme.pencilColor; | |
| const shade = theme.pencilShade; | |
| const pineFill = isDark ? '#1e281c' : '#d8d4bf'; | |
| const oakFill = isDark ? '#242a1e' : '#ded6bf'; | |
| const trunkFill = isDark ? '#2e251d' : '#cca98a'; | |
| const willowFill = isDark ? '#1f2920' : '#d5dcc2'; | |
| const birchFoliageFill = isDark ? '#293222' : '#e2dbcb'; | |
| const renderTreeContent = () => { | |
| switch (type) { | |
| case 'pine': | |
| case 'spruce': { | |
| const width = type === 'spruce' ? 14 : 17; | |
| const h = type === 'spruce' ? 32 : 28; | |
| return ( | |
| <g transform={`translate(${x}, ${y}) scale(${scale})`}> | |
| <ellipse | |
| cx="1" | |
| cy="2" | |
| rx={width * 0.75} | |
| ry="3" | |
| fill={pencil} | |
| opacity={isDark ? 0.25 : 0.2} | |
| /> | |
| <path | |
| d="M -1.8,2 L -1,-6 L 1,-6 L 1.8,2 Z" | |
| fill={trunkFill} | |
| stroke={pencil} | |
| strokeWidth="1.1" | |
| strokeLinejoin="round" | |
| /> | |
| {/* Bottom Tier */} | |
| <path | |
| d={`M 0,-10 | |
| Q ${width * 0.55},-7 ${width * 0.95},-3 | |
| Q ${width * 0.6},0 0, -2 | |
| Q ${-width * 0.6},0 ${-width * 0.95},-3 | |
| Q ${-width * 0.55},-7 0,-10 Z`} | |
| fill={pineFill} | |
| stroke={pencil} | |
| strokeWidth="1.2" | |
| strokeLinejoin="round" | |
| /> | |
| <path | |
| d={`M 1,-6 Q ${width * 0.5},-4 ${width * 0.85},-3 Q ${width * 0.4},-1 0,-2 Z`} | |
| fill={pencil} | |
| opacity={isDark ? 0.4 : 0.3} | |
| /> | |
| <line x1="2" y1="-7" x2={width * 0.75} y2="-4" stroke={shade} strokeWidth="0.8" /> | |
| <line x1="1" y1="-4" x2={width * 0.65} y2="-2" stroke={shade} strokeWidth="0.8" /> | |
| {/* Middle Tier */} | |
| <path | |
| d={`M 0,-18 | |
| Q ${width * 0.45},-15 ${width * 0.8},-11 | |
| Q ${width * 0.5},-8 0, -10 | |
| Q ${-width * 0.5},-8 ${-width * 0.8},-11 | |
| Q ${-width * 0.45},-15 0,-18 Z`} | |
| fill={pineFill} | |
| stroke={pencil} | |
| strokeWidth="1.2" | |
| strokeLinejoin="round" | |
| /> | |
| <path | |
| d={`M 1,-14 Q ${width * 0.45},-12 ${width * 0.7},-11 Q ${width * 0.35},-9 0,-10 Z`} | |
| fill={pencil} | |
| opacity={isDark ? 0.4 : 0.3} | |
| /> | |
| <line x1="1" y1="-15" x2={width * 0.6} y2="-12" stroke={shade} strokeWidth="0.8" /> | |
| {/* Upper Tier */} | |
| <path | |
| d={`M 0,-25 | |
| Q ${width * 0.35},-22 ${width * 0.55},-18 | |
| Q ${width * 0.3},-16 0, -17 | |
| Q ${-width * 0.3},-16 ${-width * 0.55},-18 | |
| Q ${-width * 0.35},-22 0,-25 Z`} | |
| fill={pineFill} | |
| stroke={pencil} | |
| strokeWidth="1.1" | |
| strokeLinejoin="round" | |
| /> | |
| {/* Top Spire */} | |
| <path | |
| d={`M 0,-${h} L ${width * 0.35},-${h - 9} Q 0,-${h - 8} -${width * 0.35},-${h - 9} Z`} | |
| fill={pineFill} | |
| stroke={pencil} | |
| strokeWidth="1.1" | |
| strokeLinejoin="round" | |
| /> | |
| <path | |
| d={`M 0,-${h} L ${width * 0.35},-${h - 9} Q 0,-${h - 8} 0,-${h - 9} Z`} | |
| fill={pencil} | |
| opacity={isDark ? 0.4 : 0.35} | |
| /> | |
| <path | |
| d={`M -5,1 L -3,3 M 3,2 L 5,0 M -1,3 L 0,1`} | |
| stroke={pencil} | |
| strokeWidth="0.8" | |
| strokeLinecap="round" | |
| /> | |
| </g> | |
| ); | |
| } | |
| case 'ancient_oak': | |
| case 'oak': { | |
| const isAncient = type === 'ancient_oak'; | |
| const rw = isAncient ? 22 : 18; | |
| const rh = isAncient ? 24 : 20; | |
| return ( | |
| <g transform={`translate(${x}, ${y}) scale(${scale})`}> | |
| <ellipse | |
| cx="2" | |
| cy="2" | |
| rx={rw * 0.8} | |
| ry="4" | |
| fill={pencil} | |
| opacity={isDark ? 0.3 : 0.22} | |
| /> | |
| {/* Trunk */} | |
| <path | |
| d="M -4,2 Q -3,-4 -2,-8 Q -6,-12 -8,-14 M 4,2 Q 3,-4 2,-8 Q 6,-12 9,-13 M -1,-8 L 0,-15" | |
| fill="none" | |
| stroke={pencil} | |
| strokeWidth="1.8" | |
| strokeLinecap="round" | |
| /> | |
| <path | |
| d="M -3.5,2 L -1.5,-8 L 1.5,-8 L 3.5,2 Z" | |
| fill={trunkFill} | |
| stroke={pencil} | |
| strokeWidth="1" | |
| /> | |
| <line x1="-0.8" y1="0" x2="-0.8" y2="-6" stroke={shade} strokeWidth="0.75" /> | |
| <line x1="0.8" y1="1" x2="0.8" y2="-5" stroke={shade} strokeWidth="0.75" /> | |
| <ellipse cx="6" cy="-14" rx={rw * 0.45} ry={rh * 0.4} fill={pencil} opacity={0.25} /> | |
| <ellipse cx="2" cy="-8" rx={rw * 0.55} ry={rh * 0.35} fill={pencil} opacity={0.25} /> | |
| {/* Canopy */} | |
| <path | |
| d={`M -${rw * 0.85},-10 | |
| C -${rw * 1.05},-16 -${rw * 0.8},-23 -${rw * 0.45},-24 | |
| C -${rw * 0.25},-30 ${rw * 0.35},-31 ${rw * 0.65},-25 | |
| C ${rw * 1.05},-24 ${rw * 1.15},-16 ${rw * 0.9},-10 | |
| C ${rw * 1.05},-4 ${rw * 0.65},0 0,-1 | |
| C -${rw * 0.55},0 -${rw * 0.95},-4 -${rw * 0.85},-10 Z`} | |
| fill={oakFill} | |
| stroke={pencil} | |
| strokeWidth="1.35" | |
| strokeLinejoin="round" | |
| /> | |
| <path | |
| d={`M -${rw * 0.5},-18 Q -${rw * 0.2},-24 ${rw * 0.2},-22 Q ${rw * 0.45},-18 ${rw * 0.3},-14`} | |
| fill="none" | |
| stroke={pencil} | |
| strokeWidth="1" | |
| /> | |
| <path | |
| d={`M 1,-12 Q ${rw * 0.5},-15 ${rw * 0.8},-9 Q ${rw * 0.45},-4 1,-6`} | |
| fill={pencil} | |
| opacity={isDark ? 0.35 : 0.28} | |
| /> | |
| <path | |
| d={`M -${rw * 0.65},-10 Q -${rw * 0.3},-13 -${rw * 0.1},-8`} | |
| fill="none" | |
| stroke={pencil} | |
| strokeWidth="1" | |
| /> | |
| <line x1={rw * 0.15} y1="-17" x2={rw * 0.55} y2="-14" stroke={shade} strokeWidth="0.8" /> | |
| <line x1={rw * 0.25} y1="-12" x2={rw * 0.7} y2="-9" stroke={shade} strokeWidth="0.8" /> | |
| <line x1={rw * 0.1} y1="-7" x2={rw * 0.55} y2="-4" stroke={shade} strokeWidth="0.8" /> | |
| <path | |
| d="M -6,1 L -3,2 M 3,2 L 6,1 M -2,3 L -1,1 M 2,3 L 1,1" | |
| stroke={pencil} | |
| strokeWidth="0.9" | |
| strokeLinecap="round" | |
| /> | |
| </g> | |
| ); | |
| } | |
| case 'willow': { | |
| const w = 18; | |
| return ( | |
| <g transform={`translate(${x}, ${y}) scale(${scale})`}> | |
| <ellipse cx="1" cy="2" rx={w * 0.8} ry="3.5" fill={pencil} opacity={isDark ? 0.28 : 0.2} /> | |
| <path | |
| d="M -3,2 Q -1,-4 -2,-9 Q -5,-14 -7,-17 M 3,2 Q 2,-4 3,-9 Q 5,-14 8,-16" | |
| fill="none" | |
| stroke={pencil} | |
| strokeWidth="1.6" | |
| strokeLinecap="round" | |
| /> | |
| <path | |
| d="M -2.5,2 L -1.5,-9 L 2,-9 L 2.5,2 Z" | |
| fill={trunkFill} | |
| stroke={pencil} | |
| strokeWidth="0.9" | |
| /> | |
| <path | |
| d={`M -${w * 0.85},-12 | |
| C -${w * 0.95},-20 -${w * 0.5},-27 0,-26 | |
| C ${w * 0.5},-27 ${w * 0.95},-20 ${w * 0.85},-12 | |
| C ${w * 0.6},-7 0,-8 -${w * 0.85},-12 Z`} | |
| fill={willowFill} | |
| stroke={pencil} | |
| strokeWidth="1.2" | |
| strokeLinejoin="round" | |
| /> | |
| <path | |
| d={`M -${w * 0.75},-12 Q -${w * 0.85},-4 -${w * 0.7},0 M -${w * 0.55},-14 Q -${w * 0.65},-3 -${w * 0.45},1 M -${w * 0.35},-15 Q -${w * 0.45},-1 -${w * 0.25},2`} | |
| fill="none" | |
| stroke={pencil} | |
| strokeWidth="1.1" | |
| strokeLinecap="round" | |
| /> | |
| <path | |
| d={`M -${w * 0.15},-16 Q -${w * 0.15},-2 0,1 M ${w * 0.1},-16 Q ${w * 0.15},-3 ${w * 0.2},0`} | |
| fill="none" | |
| stroke={pencil} | |
| strokeWidth="1.1" | |
| strokeLinecap="round" | |
| /> | |
| <path | |
| d={`M ${w * 0.35},-15 Q ${w * 0.5},-2 ${w * 0.4},2 M ${w * 0.6},-14 Q ${w * 0.75},-2 ${w * 0.65},1 M ${w * 0.78},-12 Q ${w * 0.9},-3 ${w * 0.8},0`} | |
| fill="none" | |
| stroke={pencil} | |
| strokeWidth="1.2" | |
| strokeLinecap="round" | |
| /> | |
| <path | |
| d={`M 1,-23 Q ${w * 0.6},-20 ${w * 0.75},-12 Q ${w * 0.4},-10 0,-14 Z`} | |
| fill={pencil} | |
| opacity={isDark ? 0.35 : 0.25} | |
| /> | |
| <path | |
| d="M -7,2 Q -5,-2 -4,0 M -5,2 Q -3,-3 -2,0 M 4,2 Q 6,-2 7,0 M 6,2 Q 8,-1 9,1" | |
| stroke={pencil} | |
| strokeWidth="0.8" | |
| fill="none" | |
| /> | |
| </g> | |
| ); | |
| } | |
| case 'birch': | |
| case 'cypress': | |
| default: { | |
| const w = 12; | |
| const h = 26; | |
| return ( | |
| <g transform={`translate(${x}, ${y}) scale(${scale})`}> | |
| <ellipse cx="1" cy="2" rx={w * 0.6} ry="3" fill={pencil} opacity={0.25} /> | |
| <path d="M -1.2,2 L -0.6,-16 L 0.6,-16 L 1.2,2 Z" fill={trunkFill} stroke={pencil} strokeWidth="1" /> | |
| <line x1="-1" y1="-4" x2="0" y2="-4" stroke={pencil} strokeWidth="0.9" /> | |
| <line x1="0" y1="-8" x2="1" y2="-8" stroke={pencil} strokeWidth="0.9" /> | |
| <line x1="-0.8" y1="-12" x2="0.2" y2="-12" stroke={pencil} strokeWidth="0.9" /> | |
| <path | |
| d={`M 0,-${h} | |
| C ${w * 0.7},-${h - 4} ${w * 0.8},-${h * 0.4} ${w * 0.45},-${h * 0.2} | |
| C 0,-${h * 0.15} -${w * 0.45},-${h * 0.2} -${w * 0.8},-${h * 0.4} | |
| C -${w * 0.8},-${h * 0.4} -${w * 0.7},-${h - 4} 0,-${h} Z`} | |
| fill={birchFoliageFill} | |
| stroke={pencil} | |
| strokeWidth="1.2" | |
| strokeLinejoin="round" | |
| /> | |
| <path | |
| d={`M 0,-${h} C ${w * 0.7},-${h - 4} ${w * 0.8},-${h * 0.4} ${w * 0.45},-${h * 0.2} C 0,-${h * 0.15} 0,-${h * 0.4} 0,-${h} Z`} | |
| fill={pencil} | |
| opacity={isDark ? 0.35 : 0.25} | |
| /> | |
| <line x1="1" y1="-16" x2={w * 0.55} y2="-13" stroke={shade} strokeWidth="0.8" /> | |
| <line x1="1" y1="-10" x2={w * 0.5} y2="-7" stroke={shade} strokeWidth="0.8" /> | |
| <line x1="-3" y1="2" x2="-1" y2="0" stroke={pencil} strokeWidth="0.8" /> | |
| <line x1="2" y1="2" x2="4" y2="0" stroke={pencil} strokeWidth="0.8" /> | |
| </g> | |
| ); | |
| } | |
| } | |
| }; | |
| return <g id={`tree-${x}-${y}`} className="realistic-tree">{renderTreeContent()}</g>; | |
| }; | |