Skip to content

Instantly share code, notes, and snippets.

@peune
Last active May 30, 2019 08:26
Show Gist options
  • Save peune/890913371b5c84330a18af96d6c4b1e5 to your computer and use it in GitHub Desktop.
Save peune/890913371b5c84330a18af96d6c4b1e5 to your computer and use it in GitHub Desktop.
import IPython.display
def _display_html(html_str):
html = IPython.display.HTML(html_str)
IPython.display.display(html)
def test():
code = '''
<script src="https://cdn.rawgit.com/mrdoob/three.js/r89/build/three.min.js"></script>
<script src="https://cdn.rawgit.com/mrdoob/three.js/r89/examples/js/controls/OrbitControls.js"></script>
<script>
"use strict";
var camera, scene, renderer, controls;
var mesh, material;
init();
animate(0);
function init() {
var width = 400, height = 300;
scene = new THREE.Scene();
var light0 = new THREE.AmbientLight( 0x000000);
scene.add(light0);
var light2 = new THREE.PointLight(0xffffff, 1, 0);
var light3 = new THREE.PointLight(0xffffff, 1, 0);
var light4 = new THREE.PointLight(0xffffff, 1, 0);
light2.position.set(0,100,0);
light3.position.set(100,100,100);
light4.position.set(-100,-100,-100);
scene.add(light2);
scene.add(light3);
scene.add(light4);
camera = new THREE.PerspectiveCamera( 75, width / height, 10, 50);
camera.position.set(0,0,30);
camera.lookAt(0, 0, 0);
scene.add(camera)
controls = new THREE.OrbitControls( camera );
var geometry = new THREE.BoxGeometry(15, 15, 15);
// simple material
material = new THREE.MeshStandardMaterial({
emissive: 0x404040,
specular:0x111111,
});
mesh = new THREE.Mesh( geometry, material );
scene.add(mesh);
renderer = new THREE.WebGLRenderer({antialias: true});
renderer.setSize(width, height);
renderer.setClearColor( 0x000000, 1 );
document.body.appendChild(renderer.domElement);
}
function update() {
requestAnimationFrame(animate);
}
function animate(time) {
requestAnimationFrame( animate );
mesh.rotation.x += 0.01;
mesh.rotation.y += 0.01;
renderer.render( scene, camera );
}
</script>
'''
_display_html(code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment