setting up colors, adding some functions to utils.js

This commit is contained in:
ericrius1 2015-10-13 14:16:28 -07:00
parent b490f9e2c1
commit ad61b89abd
3 changed files with 74 additions and 64 deletions

View file

@ -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;
}

View file

@ -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);
Script.scriptEnding.connect(cleanup);

View file

@ -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));
}