Skip to content

Instantly share code, notes, and snippets.

@cubicleDowns
cubicleDowns / rayprojection.js
Last active December 29, 2015 11:28
Casting a ray and randomly coloring a cube with THREE.js. See full code here: https://github.com/cubicleDowns/webgl-code-samples
function listeners () {
document.addEventListener('click', castRay, false);
}
function castRay (event) {
event.preventDefault();
var mouse = {};
/**
* This gulpfile will copy static libraries and a index.html file as well as
* merge, babelify and uglify the rest of the javascript project.
*
* TODO:
* - Separate media, libs and src with different watchers.
* - Media and libs should only be copied to dist if they are different sizes.
*
* The expected project is to be laid out as such:
*
@cubicleDowns
cubicleDowns / getscopes.js
Created November 7, 2014 18:07
Returns list of scopes. Requires underscore. From here: http://larseidnes.com/2014/11/05/angularjs-the-bad-parts/
function getScopes(root) {
var scopes = [];
function traverse(scope) {
scopes.push(scope);
if (scope.$$nextSibling)
traverse(scope.$$nextSibling);
if (scope.$$childHead)
traverse(scope.$$childHead);
}
traverse(root);
@cubicleDowns
cubicleDowns / ngExceptions.js
Created October 13, 2014 16:42
Angular Error Exception Module
//inject the module as such
var myApp = angular.module("myApp", ['ngExceptions'])
// put this in one file.
(function(window, angular) {'use strict';
/**
* @ngdoc module
* @name ngExceptions
* @description
*
@cubicleDowns
cubicleDowns / controller.js
Created February 9, 2014 21:48
Example of an AngularJS controller accessing a THREEjs factory. In this example, I am simply calling the exposed API to modify the THREEjs scene.
"use strict";
tttApp.controller('TTTController', function ($scope, ThreeEnv) {
$scope.dims = 3;
$scope.usercolor = "#0000FF";
$scope.username = "Player1";
$scope.userfirst = false;
@cubicleDowns
cubicleDowns / clickDirective.js
Created February 9, 2014 21:44
Example of using an AngularJS directive to interact with a THREEjs factory.
"use strict";
tttApp.directive("selectcube", function(ThreeEnv){
return {
restrict: "A",
link: function(scope, element){
var offsetLeft = element[0].offsetLeft,
offsetTop = element[0].offsetTop,