Back to Coding

3D Bouncing Balls Cube

Prompt

Create a complete three-dimensional simulation contained entirely within a single HTML file that features 50 realistic-looking balls bouncing inside a spinning cube. The 3D scene must include the following features: - The cube should slowly rotate around its center, providing a dynamic and continuously changing perspective. - Each of the 50 balls should be visually realistic and have proper shading or materials to differentiate them clearly from the cube and from each other. - The balls must move with realistic physics, including accurate velocity, acceleration, and collision detection. - The balls must bounce off the inner surfaces of the cube, reversing direction appropriately upon collision to simulate realistic bouncing behavior. Additional requirements: - Use only HTML and JavaScript (e.g., WebGL with Three.js or similar libraries embedded via CDN) within a single HTML file. - Ensure performance is smooth and the animation runs fluidly on modern browsers. - The camera perspective should allow a clear view of the bouncing balls inside the cube as it spins. - The solution should be self-contained, requiring no external assets beyond CDN links. # Steps 1. Set up a 3D scene with a cube mesh that can rotate slowly around its center. 2. Generate 50 spheres positioned initially inside the cube with random velocities. 3. Implement physics calculations to update the positions of balls each animation frame. 4. Detect collisions of balls against cube walls and update velocity vectors to simulate bouncing. 5. Render the updated scene at smooth frame rates. # Output Format Provide the complete HTML code as a single text block. This code should include all necessary HTML, CSS, and JavaScript so that saving it as an .html file and opening it in a modern web browser displays the described simulation immediately. # Notes - Focus on realistic motion and smooth rotation of the cube. - Optimize collision detection for 50 balls to maintain performance. - You can use publicly available JavaScript 3D libraries via CDN, but the entire solution must remain in one HTML file. # Response Formats ## prompt // Extracts the full prompt and metadata as valid JSON. {"prompt":"Create a complete three-dimensional simulation contained entirely within a single HTML file that features 50 realistic-looking balls bouncing inside a spinning cube.\n\nThe 3D scene must include the following features:\n\n- The cube should slowly rotate around its center, providing a dynamic and continuously changing perspective.\n- Each of the 50 balls should be visually realistic and have proper shading or materials to differentiate them clearly from the cube and from each other.\n- The balls must move with realistic physics, including accurate velocity, acceleration, and collision detection.\n- The balls must bounce off the inner surfaces of the cube, reversing direction appropriately upon collision to simulate realistic bouncing behavior.\n\nAdditional requirements:\n\n- Use only HTML and JavaScript (e.g., WebGL with Three.js or similar libraries embedded via CDN) within a single HTML file.\n- Ensure performance is smooth and the animation runs fluidly on modern browsers.\n- The camera perspective should allow a clear view of the bouncing balls inside the cube as it spins.\n- The solution should be self-contained, requiring no external assets beyond CDN links.\n\n# Steps\n\n1. Set up a 3D scene with a cube mesh that can rotate slowly around its center.\n2. Generate 50 spheres positioned initially inside the cube with random velocities.\n3. Implement physics calculations to update the positions of balls each animation frame.\n4. Detect collisions of balls against cube walls and update velocity vectors to simulate bouncing.\n5. Render the updated scene at smooth frame rates.\n\n# Output Format\n\nProvide the complete HTML code as a single text block. This code should include all necessary HTML, CSS, and JavaScript so that saving it as an .html file and opening it in a modern web browser displays the described simulation immediately.\n\n# Notes\n\n- Focus on realistic motion and smooth rotation of the cube.\n- Optimize collision detection for 50 balls to maintain performance.\n- You can use publicly available JavaScript 3D libraries via CDN, but the entire solution must remain in one HTML file.","name":"3D Bouncing Balls Cube","short_description":"Generates a 3D animation of 50 bouncing balls inside a rotating cube in a single HTML file.","icon":"CubeIcon","category":"programming","tags":["3D","Physics","Animation","HTML"],"should_index":true}

Related Coding Prompts

Write Code

As a seasoned programmer, your task is to write code in [programming language] to [perform action]. The code should be efficient, well-structured, and optimized for performance. Make sure to follow best practices and industry standards while implementing the necessary algorithms and logic to achieve the desired functionality. Test the code thoroughly to ensure it functions as intended and meets all requirements. Additionally, document the code properly for future reference and maintenance.

Debug Code

Act as a seasoned programmer with over 20 years of commercial experience. Analyze the provided [piece of code] that is causing a specific [error]. Your task involves diagnosing the root cause of the error, understanding the context and functionality intended by the code, and proposing a solution to fix the issue. Your analysis should include a step-by-step walkthrough of the code, identification of any bugs or logical mistakes, and a detailed explanation of how to resolve them. Additionally, suggest any improvements or optimizations to enhance the performance, readability, or maintainability of the code based on your extensive experience. Ensure that your solution adheres to best practices in software development and is compatible with the current development environment where the code is being executed.

Do Code Review

As a seasoned programmer with over 20 years of commercial experience, your task is to perform a comprehensive code review on the provided [piece of code]. Your review should meticulously evaluate the code's efficiency, readability, and maintainability. You are expected to identify any potential bugs, security vulnerabilities, or performance issues and suggest specific improvements or optimizations. Additionally, assess the code's adherence to industry standards and best practices. Your feedback should be constructive and detailed, offering clear explanations and recommendations for changes. Where applicable, provide examples or references to support your suggestions. Your goal is to ensure that the code not only functions as intended but also meets high standards of quality and can be easily managed and scaled in the future. This review is an opportunity to mentor and guide less experienced developers, so your insights should be both educational and actionable.