Skip to content

Instantly share code, notes, and snippets.

@brunofarache
Forked from anonymous/y3d-script.js
Last active December 18, 2015 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunofarache/5855622 to your computer and use it in GitHub Desktop.
Save brunofarache/5855622 to your computer and use it in GitHub Desktop.
/**
* Click on the box, it should change to a random color.
*
* https://gist.github.com/brunofarache/5855622
*/
YUI().use('y3d-picker-plugin' ,'y3d-scene', 'y3d-geometry', 'node', function(Y) {
var scene = new Y.Scene({
background: '#272822'
});
scene.plug(Y.Plugin.Picker);
var box = new Y.Box({
color: '#ff7700',
position: {
z: -20
}
});
box.set('rotation', { x: 45, y: 45 });
scene.add(box);
scene.render();
var canvas = scene.get('srcNode');
canvas.on('click', function(e) {
var x = e.pageX - canvas.getXY()[0];
var y = e.pageY - canvas.getXY()[1];
var geometry = scene.picker.pick(x, y);
if (geometry) {
var randomColor = Math.floor(Math.random() * 16777215).toString(16);
geometry.set('color', '#' + randomColor);
scene.render();
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment