vytvor skript spustiteny jako html stranku pouze v prohlizeci pro geometricky 3D program na zobrazovani usecek a trojuhelniku uvnitř tri sférických kruznic v prostorových rovinách x,y,z. 3D geometricke znazorneni bude mozne otáčet vsemi smery 3D prostoru. geometricky program bude vytvoren ve vhodnem geometrickem prostředí tak, aby 3D graficke otaceni zabiralo co největší misto na prohlizeni a kruznice byly dostatecne velke. graficke znazorneni kruznic bude umisteno ve stredu plochy programu. na leve strane programu bude maly textovy vstup, kam se da zapsat číslo, podle kterého budou všechny tri kruznice rozdeleny na body od 1 po cislo. pod tim se bude nachazet tri tlačítka pod sebou pro kruznice 1,2 a 3. tato tlačítka budou po jednom menit cisla od 0 az počet bodu na kruznici, vedle tlačítek bude pak viditelne aktualni cislo. pod tim bude tlacitko zakreslit. při pouziti tohoto tlačítka vytvori program usecku mezi body kruznic nebo trojuhelnik mezi body kruznic, podle nastaveni tlačítek shora. pod tim bude tlacitko, které meni pripadne zakreslene trojúhelníky mezi trojúhelníky pouze s liniemi a trojúhelníky s vyplnenymi plochami, ale castecne průhlednými. na prave strane od vykreslenych kruznic budou tri tlačítka pro tri kruznice, která budou při zmacknuti posouvat konkretni kruznici o jeden bod. při posuvu kruznice se usecky a trojúhelníky uvnitr kruznic udrzuji dle bodu, mezi kterými byly provedeny. cely skript mi zapis sem.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Certainly! Below is a complete HTML, CSS, and JavaScript script that creates a 3D geometric visualization tool as per your specifications. This script leverages the Three.js library for 3D rendering and interactive controls.
Features Implemented:
3D Visualization:
Three spherical circles positioned on the X, Y, and Z planes.
Points distributed evenly on each circle based on user input.
Ability to rotate the 3D scene freely.
User Interface:
Left Sidebar:
Input field to set the number of points on each circle.
Three buttons to set the connection count for each circle.
Display of current connection counts.
"Draw" button to create lines or triangles based on the connections.
Toggle button to switch between lines and filled triangles.
Right Sidebar:
Three buttons to shift each circle's points forward by one.
Dynamic Interactions:
Shifting points updates the connections dynamically.
Toggle between wireframe (lines) and filled (semi-transparent) triangles.
How to Use:
Set Points:
Enter the desired number of points in the input field on the left.
Click a "Set Connections" button for each circle to define how many connections to make from each point.
Draw Geometries:
After setting connections, click the "Draw" button to visualize the lines or triangles.
Toggle Display:
Use the toggle button to switch between wireframe and filled triangle views.
Shift Points:
Use the buttons on the right to shift points on each respective circle, which updates the connections accordingly.
Complete Script:
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>3D Geometric Visualization</title>
<style>
body {
margin: 0;
overflow: hidden;
display: flex;
height: 100vh;
font-family: Arial, sans-serif;
}
#leftPanel, #rightPanel {
width: 200px;
padding: 10px;
background-color: #f0f0f0;
box-sizing: border-box;
overflow-y: auto;
}
#leftPanel {
border-right: 1px solid #ccc;
}
#rightPanel {
border-left: 1px solid #ccc;
display: flex;
flex-direction: column;
align-items: center;
}
#controls {
margin-bottom: 20px;
}
button {
width: 100%;
padding: 10px;
margin-top: 5px;
cursor: pointer;
}
#info {
margin-top: 5px;
text-align: center;
}
</style>
</head>
<body>
<!-- Left Sidebar -->
<div id="leftPanel">
<div id="controls">
<label for="pointCount">Number of Points:</label>
<input type="number" id="pointCount" min="3" value="6" style="width: 100%; padding: 5px; margin-top: 5px;">
<div style="margin-top: 15px;">
<div>
<button id="btnCircle1">Circle 1 Connections: 0</button>
<div id="circle1Info" class="info">Current: 0</div>
</div>
<div>
<button id="btnCircle2">Circle 2 Connections: 0</button>
<div id="circle2Info" class="info">Current: 0</div>
</div>
<div>
<button id="btnCircle3">Circle 3 Connections: 0</button>
<div id="circle3Info" class="info">Current: 0</div>
</div>
</div>
<button id="drawBtn" style="margin-top: 15px;">Draw</button>
<button id="toggleBtn" style="margin-top: 10px;">Toggle Lines/Triangles</button>
</div>
</div>
<!-- 3D Canvas -->
<div id="canvasContainer" style="flex: 1;"></div>
<!-- Right Sidebar -->
<div id="rightPanel">
<div style="text-align: center; margin-bottom: 20px;">
<button id="shiftCircle1">Shift Circle 1</button>
<button id="shiftCircle2" style="margin-top: 10px;">Shift Circle 2</button>
<button id="shiftCircle3" style="margin-top: 10px;">Shift Circle 3</button>
</div>
</div>
<!-- Three.js Library -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r142/three.min.js"></script>
<script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>
<script>
// Scene setup
let scene, camera, renderer, controls;
initScene();
// Geometry data
let pointCount = 6;
let circles = [[], [], []]; // Circle 1 (X), Circle 2 (Y), Circle 3 (Z)
let connections = [0, 0, 0]; // Number of connections per circle
let connectionButtons = [null, null, null];
let connectionInfos = [null, null, null];
let drawnObjects = [];
let drawMode = 'lines'; // or 'triangles'
// Initialize controls
initControls();
// Event listeners
document.getElementById('pointCount').addEventListener('change', (e) => {
let val = parseInt(e.target.value);
if (val < 3) {
alert("Number of points must be at least 3.");
e.target.value = 3;
val = 3;
}
pointCount = val;
generateCircles();
updateConnections();
redraw();
});
// Initialize connection buttons and infos
for(let i=0;i<3;i++) {
connectionButtons[i] = document.getElementById('btnCircle'+(i+1));
connectionInfos[i] = document.getElementById('circle'+(i+1)+'Info');
connectionButtons[i].addEventListener('click', () => {
connections[i] = (connections[i] +1) % (pointCount);
connectionButtons[i].innerText = `Circle ${i+1} Connections: ${connections[i]}`;
connectionInfos[i].innerText = `Current: ${connections[i]}`;
});
}
// Draw button
document.getElementById('drawBtn').addEventListener('click', () => {
drawGeometries();
});
// Toggle button
document.getElementById('toggleBtn').addEventListener('click', () => {
drawMode = (drawMode === 'lines') ? 'triangles' : 'lines';
redraw();
});
// Shift buttons
document.getElementById('shiftCircle1').addEventListener('click', () => {
shiftCircle(0);
});
document.getElementById('shiftCircle2').addEventListener('click', () => {
shiftCircle(1);
});
document.getElementById('shiftCircle3').addEventListener('click', () => {
shiftCircle(2);
});
// Initialize everything
generateCircles();
drawCircles();
animate();
// Functions
function initScene() {
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.set(10, 10, 10);
renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth - 400, window.innerHeight); // Adjust for side panels
document.getElementById('canvasContainer').appendChild(renderer.domElement);
controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.dampingFactor = 0.05;
window.addEventListener('resize', onWindowResize, false);
}
function initControls() {
// Placeholder for any additional control initialization if needed
}
function onWindowResize() {
let width = window.innerWidth - 400; // Adjust for side panels
let height = window.innerHeight;
renderer.setSize(width, height);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
function generateCircles() {
// Remove existing circles
for(let i=0;i<3;i++) {
circles[i] = [];
}
const radius = 5;
for(let i=0;i<3;i++) {
for(let j=0; j<pointCount; j++) {
let angle = (2 * Math.PI / pointCount) * j;
let point = new THREE.Vector3();
switch(i) {
case 0: // X plane
point.set(0, radius * Math.cos(angle), radius * Math.sin(angle));
break;
case 1: // Y plane
point.set(radius * Math.cos(angle), 0, radius * Math.sin(angle));
break;
case 2: // Z plane
point.set(radius * Math.cos(angle), radius * Math.sin(angle), 0);
break;
}
circles[i].push(point);
}
}
// Draw updated circles
redraw(true);
}
function drawCircles() {
const material = new THREE.LineBasicMaterial({ color: 0x0000ff });
for(let i=0;i<3;i++) {
const geometry = new THREE.BufferGeometry().setFromPoints([...circles[i], circles[i][0]]);
const circle = new THREE.Line(geometry, material.clone());
scene.add(circle);
drawnObjects.push(circle);
}
// Draw points
const pointMaterial = new THREE.PointsMaterial({ color: 0xff0000, size: 0.1 });
for(let i=0;i<3;i++) {
const geometry = new THREE.BufferGeometry().setFromPoints(circles[i]);
const points = new THREE.Points(geometry, pointMaterial.clone());
scene.add(points);
drawnObjects.push(points);
}
}
function drawGeometries() {
// Remove existing geometries
for(let obj of drawnObjects.slice(6)) { // First 6 are circles and points
scene.remove(obj);
}
drawnObjects = drawnObjects.slice(0,6);
if(drawMode === 'lines') {
const lineMaterial = new THREE.LineBasicMaterial({ color: 0x00ff00 });
// Draw lines based on connections
for(let i=0;i<3;i++) {
let conn = connections[i];
if(conn === 0) continue;
const circle = circles[i];
for(let j=0; j<pointCount; j++) {
let start = circle[j];
let end = circle[(j + conn) % pointCount];
const geometry = new THREE.BufferGeometry().setFromPoints([start, end]);
const line = new THREE.Line(geometry, lineMaterial.clone());
scene.add(line);
drawnObjects.push(line);
}
}
} else if(drawMode === 'triangles') {
const material = new THREE.MeshBasicMaterial({ color: 0x00ff00, side: THREE.DoubleSide, transparent: true, opacity: 0.5 });
for(let i=0;i<3;i++) {
let conn = connections[i];
if(conn === 0) continue;
const circle = circles[i];
for(let j=0; j<pointCount; j++) {
let a = circle[j];
let b = circle[(j + conn) % pointCount];
let c = circle[(j + 2 * conn) % pointCount];
const geometry = new THREE.Geometry();
geometry.vertices.push(a, b, c);
geometry.faces.push(new THREE.Face3(0,1,2));
geometry.computeFaceNormals();
const mesh = new THREE.Mesh(geometry, material.clone());
scene.add(mesh);
drawnObjects.push(mesh);
}
}
}
}
function redraw(clearAll=false) {
// Remove all existing geometries except circles and points
if(clearAll) {
for(let obj of drawnObjects.slice(6)) { // First 6 are circles and points
scene.remove(obj);
}
drawnObjects = drawnObjects.slice(0,6);
} else {
// Redraw circles and points
for(let obj of drawnObjects.slice(0,6)) {
scene.remove(obj);
}
drawnObjects = [];
drawCircles();
}
// Optionally redraw geometries
//drawGeometries();
}
function shiftCircle(index) {
// Shift points forward by one
circles[index].push(circles[index].shift());
// Update circle lines and points
redraw(true);
drawCircles();
// Redraw geometries
drawGeometries();
}
function updateConnections() {
// Placeholder for any updates needed when connections change
}
function animate() {
requestAnimationFrame(animate);
controls.update();
renderer.render(scene, camera);
}
</script>
</body>
</html>
Explanation of the Script:
HTML Structure:
Left Panel (#leftPanel):
Number of Points: An input field to specify how many points each circle should have.
Connection Buttons: Three buttons (btnCircle1, btnCircle2, btnCircle3) to set the number of connections for each circle. Clicking these buttons cycles the connection count between 0 and number of points - 1.
Draw Button (drawBtn): Triggers the drawing of lines or triangles based on the current connection settings.
Toggle Button (toggleBtn): Switches between drawing lines and filled triangles.
Right Panel (#rightPanel):
Three buttons (shiftCircle1, shiftCircle2, shiftCircle3) to shift each circle's points forward by one.
3D Canvas (#canvasContainer):
This is where the Three.js scene is rendered.
CSS Styling:
The page is divided into three parts: left sidebar, center canvas, and right sidebar.
Basic styling ensures that the side panels are fixed in width, and the canvas takes up the remaining space.
JavaScript Functionality:
Three.js Initialization:
Sets up the scene, camera, renderer, and orbit controls to allow user interaction (rotation, zooming).
Adjusts the renderer's size on window resize to maintain responsiveness.
Geometry Generation (generateCircles):
Generates three sets of points placed on the X, Y, and Z planes respectively.
Points are evenly distributed based on the number specified by the user.
Drawing Circles and Points (drawCircles):
Creates visual representations of the three circles and the points on them.
Circles are drawn using THREE.Line, and points are drawn using THREE.Points.
Notes:
Performance: For a large number of points and connections, performance might be impacted. It's advisable to limit the number of points to a reasonable number (e.g., up to 50).
Enhancements: Additional features like color selection, different line styles, or saving/loading configurations can be implemented as needed.
Error Handling: Basic error handling is included (e.g., minimum number of points). Further validation can be added for robustness.
Feel free to customize and expand upon this script to better suit your specific requirements!