-
-
Save brunofarache/5855622 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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