From ad61b89abdaf5a81ba9d5908fc1022458cfbba0f Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 13 Oct 2015 14:16:28 -0700 Subject: [PATCH] setting up colors, adding some functions to utils.js --- examples/libraries/utils.js | 18 ++++++ .../painting/whiteboard/whiteboardSpawner.js | 60 +++++++++++++++++-- examples/utilities.js | 60 ------------------- 3 files changed, 74 insertions(+), 64 deletions(-) delete mode 100644 examples/utilities.js diff --git a/examples/libraries/utils.js b/examples/libraries/utils.js index 3583aad76a..ab86007e4b 100644 --- a/examples/libraries/utils.js +++ b/examples/libraries/utils.js @@ -253,3 +253,21 @@ orientationOf = function(vector) { return Quat.multiply(yaw, pitch); } +randFloat = function(low, high) { + return low + Math.random() * (high - low); +} + + +randInt = function(low, high) { + return Math.floor(randFloat(low, high)); +} + +hexToRgb = function(hex) { + var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); + return result ? { + red: parseInt(result[1], 16), + green: parseInt(result[2], 16), + blue: parseInt(result[3], 16) + } : null; +} + diff --git a/examples/painting/whiteboard/whiteboardSpawner.js b/examples/painting/whiteboard/whiteboardSpawner.js index 4b7b99dc5b..0702aa0360 100644 --- a/examples/painting/whiteboard/whiteboardSpawner.js +++ b/examples/painting/whiteboard/whiteboardSpawner.js @@ -21,19 +21,71 @@ var rotation = Quat.safeEulerAngles(Camera.getOrientation()); rotation = Quat.fromPitchYawRollDegrees(0, rotation.y, 0); var center = Vec3.sum(MyAvatar.position, Vec3.multiply(3, Quat.getFront(rotation))); center.y += 0.4; +var whiteboardDimensions = { + x: 2, + y: 1.5, + z: 0.01 +}; var whiteboard = Entities.addEntity({ type: "Box", position: center, rotation: rotation, script: scriptURL, - dimensions: {x: 2, y: 1.5, z: 0.01}, - color: {red: 255, green: 255, blue: 255} + dimensions: whiteboardDimensions, + color: { + red: 255, + green: 255, + blue: 255 + } }); +//COLORS + +var colors = [ + hexToRgb("#2F8E84"), + hexToRgb("#66CCB3"), + hexToRgb("#A43C37"), + hexToRgb("#491849"), + hexToRgb("#6AB03B"), + hexToRgb("#993369"), + hexToRgb("#9B47C2") +]; + +var direction = Quat.getRight(rotation); +var colorBoxPosition = Vec3.subtract(center, Vec3.multiply(direction, whiteboardDimensions.x / 2)); +colorBoxPosition.y += whiteboardDimensions.y / 2; + +var colorBoxes = []; + +var colorSquareDimensions = { + x: (whiteboardDimensions.x / 2) / (colors.length - 1), + y: .1, + z: 0.05 +}; +var spaceBetweenColorBoxes = Vec3.multiply(direction, colorSquareDimensions.x * 2); + +for (var i = 0; i < colors.length; i++) { + var colorBox = Entities.addEntity({ + type: "Box", + position: colorBoxPosition, + dimensions: colorSquareDimensions, + rotation: rotation, + color: colors[i] + }); + colorBoxes.push(colorBox); + + colorBoxPosition = Vec3.sum(colorBoxPosition, spaceBetweenColorBoxes); + +} + + function cleanup() { Entities.deleteEntity(whiteboard); -} + colorBoxes.forEach(function(colorBox) { + Entities.deleteEntity(colorBox); + }); + } -Script.scriptEnding.connect(cleanup); \ No newline at end of file + Script.scriptEnding.connect(cleanup); \ No newline at end of file diff --git a/examples/utilities.js b/examples/utilities.js deleted file mode 100644 index 85e27079a8..0000000000 --- a/examples/utilities.js +++ /dev/null @@ -1,60 +0,0 @@ -// utilities.js -// examples -// -// Created by Eric Levin on June 8 -// Copyright 2015 High Fidelity, Inc. -// -// Common utilities -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html - - - -map = function(value, min1, max1, min2, max2) { - return min2 + (max2 - min2) * ((value - min1) / (max1 - min1)); -} - -hslToRgb = function(hslColor) { - var h = hslColor.hue; - var s = hslColor.sat; - var l = hslColor.light; - var r, g, b; - - if (s == 0) { - r = g = b = l; // achromatic - } else { - var hue2rgb = function hue2rgb(p, q, t) { - if (t < 0) t += 1; - if (t > 1) t -= 1; - if (t < 1 / 6) return p + (q - p) * 6 * t; - if (t < 1 / 2) return q; - if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6; - return p; - } - - var q = l < 0.5 ? l * (1 + s) : l + s - l * s; - var p = 2 * l - q; - r = hue2rgb(p, q, h + 1 / 3); - g = hue2rgb(p, q, h); - b = hue2rgb(p, q, h - 1 / 3); - } - - return { - red: Math.round(r * 255), - green: Math.round(g * 255), - blue: Math.round(b * 255) - }; - -} - - - -randFloat = function(low, high) { - return low + Math.random() * (high - low); -} - - -randInt = function(low, high) { - return Math.floor(randFloat(low, high)); -} \ No newline at end of file