preved tento kod pro webovou aplikaci do skriptu v pythonu ke spousteni prostrednictvim…
- User
preved tento kod pro webovou aplikaci do skriptu v pythonu ke spousteni prostrednictvim pythonu jako program.
import { useState, useEffect } from 'react'; import { Canvas, useThree } from '@react-three/fiber'; import { OrbitControls, Line, Text } from '@react-three/drei'; import * as THREE from 'three';
const Circle3D = ({ plane, color, numPoints, rotationAngle }) => { const points = []; for (let i = 0; i <= 64; i++) { const angle = (i / 64) * Math.PI * 2; const x = Math.cos(angle); const y = Math.sin(angle); switch (plane) { case 'XY': points.push(new THREE.Vector3(x, y, 0)); break; case 'YZ': points.push(new THREE.Vector3(0, x, y)); break; case 'XZ': points.push(new THREE.Vector3(x, 0, y)); break; } }
return ( <group rotation={[ plane === 'YZ' ? rotationAngle : 0, plane === 'XZ' ? rotationAngle : 0, plane === 'XY' ? rotationAngle : 0 ]}> {Array.from({ length: numPoints }).map((_, index) => { const angle = (index / numPoints) * Math.PI * 2; const x = Math.cos(angle); const y = Math.sin(angle); let position; switch (plane) { case 'XY': position = [x, y, 0]; break; case 'YZ': position = [0, x, y]; break; case 'XZ': position = [x, 0, y]; break; } return ( <sphereGeometry args={[0.03, 16, 16]} /> <Text position={[position[0] * 1.1, position[1] * 1.1, position[2] * 1.1]} fontSize={0.1} color={color} anchorX="center" anchorY="middle" > {index + 1} ); })} ); };
const Scene = ({ circles, lines, triangles, fillTriangles }) => { const { scene } = useThree(); useEffect(() => { scene.background = new THREE.Color(0x111111); }, [scene]);
return ( <> <pointLight position={[10, 10, 10]} intensity={1} /> <pointLight position={[-10, -10, -10]} intensity={0.5} /> {circles.map((circle, index) => ( ))} {lines.map((line, index) => ( ))} {triangles.map((triangle, index) => ( <bufferAttribute attach="attributes-position" array={new Float32Array(triangle.flatMap(v => [v.x, v.y, v.z]))} itemSize={3} count={3} /> <meshPhongMaterial color="#FFFF00" side={THREE.DoubleSide} transparent opacity={fillTriangles ? 0.7 : 0} /> <Line points={[...triangle, triangle[0]]} color="#FF00FF" lineWidth={4} /> ))} </> ); };
const Home = () => { const [numPoints, setNumPoints] = useState(12); const [selectedPoints, setSelectedPoints] = useState([0, 0, 0]); const [circles, setCircles] = useState([]); const [lines, setLines] = useState([]); const [triangles, setTriangles] = useState([]); const [fillTriangles, setFillTriangles] = useState(false);
useEffect(() => { const newCircles = [ { plane: 'XY', color: '#FF4136', numPoints, rotationAngle: 0 }, { plane: 'YZ', color: '#2ECC40', numPoints, rotationAngle: 0 }, { plane: 'XZ', color: '#0074D9', numPoints, rotationAngle: 0 }, ]; setCircles(newCircles); }, [numPoints]);
const handlePointSelection = (circleIndex, point) => { const newSelectedPoints = [...selectedPoints]; newSelectedPoints[circleIndex] = point; setSelectedPoints(newSelectedPoints); };
const handleDraw = () => { const nonZeroPoints = selectedPoints.filter(point => point !== 0); const zeroCount = selectedPoints.filter(point => point === 0).length;
- Assistant