here2share

# Brython -- Rotating 3D Cube

May 7th, 2022 (edited)
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.  
  4. <head>
  5.     <meta charset="iso-8859-1">
  6.     <<title>Getting Started with Three.js -- Brython version</title>
  7.     <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/brython@3.8.9/brython.min.js">
  8.     </script>
  9.     <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/100/three.min.js"></script>
  10.    
  11. <script type="text/python">
  12.  
  13. from browser import document, window
  14.  
  15. THREE = window.THREE
  16.  
  17. camera = THREE.PerspectiveCamera.new(75, 1, 1, 10000)
  18. camera.position.z = 1000
  19. scene = THREE.Scene.new()
  20. geometry = THREE.CubeGeometry.new(200, 200, 200)
  21. material = THREE.MeshBasicMaterial.new({"color": "#ff0000", "wireframe": True})
  22. mesh = THREE.Mesh.new(geometry, material)
  23. scene.add(mesh)
  24.  
  25. renderer = THREE.WebGLRenderer.new()
  26. renderer.setSize(444, 444)
  27.  
  28. document <= renderer.domElement
  29. renderer.render(scene, camera)
  30.  
  31. def animate(i):
  32.     # note: three.js includes requestAnimationFrame shim
  33.     window.requestAnimationFrame(animate)
  34.  
  35.     mesh.rotation.x += 0.01
  36.     mesh.rotation.y += 0.02
  37.  
  38.     renderer.render(scene, camera)  
  39.  
  40. animate(0)
  41.  
  42. </script>
  43.  
  44. </head>
  45. <body onload="brython(1)">
  46.     <div id="test"></div>
  47. </body>
  48. </html>
  49.  
Add Comment
Please, Sign In to add comment