Skip to content

Instantly share code, notes, and snippets.

@Adrianl3d
Last active August 29, 2015 14:03
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 Adrianl3d/0bf07c446d9415dcc466 to your computer and use it in GitHub Desktop.
Save Adrianl3d/0bf07c446d9415dcc466 to your computer and use it in GitHub Desktop.
Color Palette Menu
// colorPaletteMenu.js
//
// Created by Adrian
// 27 June 2014 Adrian McCarlie
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
// From the "Create" Menu, create banks of voxels in graded colours for use as a simple paint palette. Where ever your avatar is standing.
// Run all colour bars from the Create Menu and then use eyedropper tool to preselect all the colours you want on the UI, then select Remove All Palettes from the Remove menu.
// It is recommended to [create palettes, preselect colours on UI, run "Remove" function] without moving, as once you move from the create position the remove will not work,
// and you will have to delete the palette voxels manually.
// Function that adds two categories to the menu.
function setupMenus()
{
//Add menu create
Menu.addMenu("Create");
// Add menu item Create Red Palette .
Menu.addMenuItem({
menuName: "Create",
menuItemName: "Create Red Palette",
isCheckable: false
});
Menu.addMenuItem({
menuName: "Create",
menuItemName: "Create Green Palette",
isCheckable: false
});
Menu.addMenuItem({
menuName: "Create",
menuItemName: "Create Blue Palette",
isCheckable: false
});
Menu.addMenuItem({
menuName: "Create",
menuItemName: "Create GreyScale Palette",
isCheckable: false
});
Menu.addMenuItem({
menuName: "Create",
menuItemName: "Create Red/Green Palette",
isCheckable: false
});
Menu.addMenuItem({
menuName: "Create",
menuItemName: "Create Green/Blue Palette",
isCheckable: false
});
Menu.addMenuItem({
menuName: "Create",
menuItemName: "Create Blue/Red Palette",
isCheckable: false
});
// Add menu Remove.
Menu.addMenu("Remove");
// Add menu item Remove All Palettes.
Menu.addMenuItem({
menuName: "Remove",
menuItemName: "Remove All Palettes",
isCheckable: false
});
}
// Function that defines the menu items.
function menuItemEvent(menuItem)
{
if (menuItem == "Create Red Palette")
{
// Call placeSingleVoxel function.
placeRedVoxel();
}
if (menuItem == "Create Green Palette")
{
// Call placeSingleVoxel function.
placeGreenVoxel();
}
if (menuItem == "Create Blue Palette")
{
// Call placeSingleVoxel function.
placeBlueVoxel();
}
if (menuItem == "Create Red/Green Palette")
{
// Call placeSingleVoxel function.
placeRedGreenVoxel();
}
if (menuItem == "Create Green/Blue Palette")
{
// Call placeSingleVoxel function.
placeGreenBlueVoxel();
}
if (menuItem == "Create Blue/Red Palette")
{
// Call placeSingleVoxel function.
placeBlueRedVoxel();
}
if (menuItem == "Create GreyScale Palette")
{
// Call placeSingleVoxel function.
placeGreyScaleVoxel();
}
if (menuItem == "Remove All Palettes")
{
// Call removeAllPalettes function.
removeAllPalettes();
}
}
// Call setupMenus function.
setupMenus();
// Connect menuItemEvent.
Menu.menuItemEvent.connect(menuItemEvent);
// Create variable buildingRoot and initialize values.
var buildingRoot = {x:0, y:0, z:0};
// Function that parses the values of the current avatar position and assigns them to the absolute values of the buildingRoot variable.
function startBuilding()
{
buildingRoot.x = Math.round(MyAvatar.position.x);
buildingRoot.y = Math.round(MyAvatar.position.y);
buildingRoot.z = Math.round(MyAvatar.position.z);
}
// Function that defines the creation of a relative voxel placement based on the buildingRoot.
function placeVoxel(x, y, z, s, r, g, b)
{
Voxels.setVoxel(buildingRoot.x + x - 1, buildingRoot.y + y - 1, buildingRoot.z + z - 1, s, r, g, b);
}
// Function that defines the removal of a relative voxel placement based on the buildingRoot.
function eraseVoxel(x, y, z, s)
{
Voxels.eraseVoxel(buildingRoot.x + x - 1, buildingRoot.y + y - 1, buildingRoot.z + z - 1, s);
}
function placeRedVoxel()
{
var x = -0.5;
var y = 1;
var z = 0;
var r = 230;
var gb = 230;
startBuilding();
while (gb > 1)
{
placeVoxel(x, y+ 0.25, z, 0.125, 255, gb, gb);
gb = gb - 25;
if (gb < 1) {gb = 1;}
x = x + 0.125;
}
while (r > 1)
{
placeVoxel(x, y+ 0.25, z, 0.125, r, 1, 1);
r = r - 25;
x = x + 0.125;
}
}
function placeGreenVoxel()
{
var x = -0.5;
var y = 1;
var z = 0;
var g = 230;
var gb = 230;
startBuilding();
while (gb > 1)
{
placeVoxel(x, y+ 0.125, z, 0.125, gb, 245, gb);
gb = gb - 25;
if (gb <1){gb = 1;}
x = x + 0.125;
}
while (g > 1)
{
placeVoxel(x, y+ 0.125, z, 0.125, 1, g, 1);
g = g - 25;
x = x + 0.125;
}
}
function placeBlueVoxel()
{
var x = -0.5;
var y = 1;
var z = 0;
var b = 230;
var gb = 230;
startBuilding();
while (gb > 1)
{
placeVoxel(x, y, z, 0.125, gb, gb, 245);
gb = gb - 25;
if (gb < 1){gb = 1;}
x = x + 0.125;
}
while (b > 1)
{
placeVoxel(x, y , z, 0.125, 1, 1, b);
b = b - 25;
x = x + 0.125;
}
}
///////////////////////////////////////////////////////////////start greyscale
function placeGreyScaleVoxel()
{
var x = -0.5;
var y = 1;
var z = 0;
var rgb = 255;
//var g = 255;
//var b = 255;
startBuilding();
while (rgb > 1)
{
placeVoxel(x, y- 0.125, z, 0.125, rgb, rgb, rgb);
rgb = rgb - 15;
if (rgb <1){rgb = 1;}
x = x + 0.125;
}
}
//////////////////////////////////////////////////////////////// gradient
function placeRedGreenVoxel()
{
var x = -0.5;
var y = 1;
var z = 0;
var r = 255;
var g = 1;
startBuilding();
while (g < 255)
{
placeVoxel(x, y- 0.25, z, 0.125, r, g, 1);
g = g + 25;
if (g >255){g = 255;}
x = x + 0.125;
}
while (r > 1)
{
placeVoxel(x, y - 0.25, z, 0.125, r, g, 1);
r = r - 25;
x = x + 0.125;
}
}
function placeGreenBlueVoxel()
{
var x = -0.5;
var y = 1;
var z = 0;
var g = 255;
var b = 1;
startBuilding();
while (b < 255)
{
placeVoxel(x, y- 0.375, z, 0.125, 1, g, b);
b = b + 25;
if (b >255){b = 255;}
x = x + 0.125;
}
while (g > 1)
{
placeVoxel(x, y - 0.375, z, 0.125, 1, g, b);
g =g - 25;
x = x + 0.125;
}
}
function placeBlueRedVoxel()
{
var x = -0.5;
var y = 1;
var z = 0;
var b = 255;
var r = 1;
startBuilding();
while (r < 255)
{
placeVoxel(x, y- 0.5, z, 0.125, r, 1, b);
r = r + 25;
if (r >255){r = 255;}
x = x + 0.125;
}
while (b > 1)
{
placeVoxel(x, y - 0.5, z, 0.125, r, 1, b);
b = b - 25;
x = x + 0.125;
}
}
//////////////////////////////////////////////////////////////// removal
function removeAllPalettes()
{
var x = -0.5;
var y = 0.5;
var z = 0;
startBuilding();
while (y <= 1.25)
{
while (x <= 2.125)
{
eraseVoxel(x, y, z, 0.125);
x = x + 0.125;
}
y = y + 0.125;
x = -0.5;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment