Skip to content

Instantly share code, notes, and snippets.

@alecperkins
Last active August 29, 2015 14:07
Show Gist options
  • Select an option

  • Save alecperkins/54e63051921ab501404d to your computer and use it in GitHub Desktop.

Select an option

Save alecperkins/54e63051921ab501404d to your computer and use it in GitHub Desktop.
# Component = React.createClass
# displayName: 'Component'
# render: ->
# <div className='Component'>
# Component! {@props.time}
# </div>
# React.renderComponent(Component(time=new Date()), document.getElementById('app'))
scene = new THREE.Scene()
camera = new THREE.PerspectiveCamera(
75
window.innerWidth / window.innerHeight
0.1
1000
)
camera.position.z = 60
renderer = new THREE.WebGLRenderer()
renderer.setSize(window.innerWidth, window.innerHeight)
document.body.appendChild(renderer.domElement)
origin =
x: window.innerWidth / 2
y: window.innerHeight / 2
renderer.domElement.addEventListener 'mousemove', (e) ->
# Convert the screen coordinates to world
rel_x = origin.x - e.pageX
rel_y = e.pageY - origin.y
# Adjust camera position
SCALE_FACTOR = 0.01
camera.position.x = rel_x * SCALE_FACTOR
camera.position.y = rel_y * SCALE_FACTOR
person = new THREE.BoxGeometry(1,2,0.1)
material = new THREE.MeshLambertMaterial
color: 0x00ff00
PERSON_X_SPACING = 10
PERSON_Y_SPACING = 10
PERSON_Z_SPACING = 20
[-10..10].forEach (x, i) ->
[-10..10].forEach (y, j) ->
[0...3].forEach (z, k) ->
cube = new THREE.Mesh(person, material)
scene.add(cube)
offset = if y % 2 then 0.5 else 0
cube.position.set(
(x + offset) * PERSON_X_SPACING
y * PERSON_Y_SPACING
z * PERSON_Z_SPACING
)
sun = new THREE.DirectionalLight( 0xffffff, 0.5 )
sun.position.set(0,0,100)
scene.add(sun)
render = ->
requestAnimationFrame(render)
renderer.render(scene, camera)
render()
{
"name": "magritte-golconda",
"proto_version": "1.5.1",
"script_libraries": [
"https://cdnjs.cloudflare.com/ajax/libs/three.js/r68/three.min.js"
],
"style_libraries": [
],
"extra_head_markup": "<meta name='viewport' content='width=device-width'>"
}
html,
body
margin: 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment