-
Notifications
You must be signed in to change notification settings - Fork 2
/
cube.html
56 lines (43 loc) · 1.51 KB
/
cube.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="UTF-8" />
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<link href="./styles.css" rel="stylesheet" type="text/css">
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.js"></script>
</head>
<body>
<h1>three.js with pyscript </h1>
<div id="container">
</div>
<py-script>
from pyodide import create_proxy
from js import THREE, window, document
container = document.querySelector('#container');
scene = THREE.Scene.new();
scene.background = THREE.Color.new('black');
fov = 35
aspect = container.clientWidth/container.clientHeight
near = 0.1
far = 100
camera = THREE.PerspectiveCamera.new(fov, aspect, near, far)
camera.position.set(0,0,10)
renderer = THREE.WebGLRenderer.new()
renderer.setSize(container.clientWidth, container.clientHeight)
renderer.setPixelRatio(window.devicePixelRatio)
geometry = THREE.BoxGeometry.new()
material = THREE.MeshBasicMaterial.new(color="#00ff00")
cube = THREE.Mesh.new( geometry, material )
scene.add( cube )
renderer.render( scene, camera )
def animate(*args):
window.requestAnimationFrame( create_proxy(animate) )
cube.rotation.x += 0.01
cube.rotation.y += 0.01
renderer.render( scene, camera )
animate()
container.append(renderer.domElement);
</py-script>
</body>
</html>