mirror of
https://github.com/lubosz/overte.git
synced 2025-04-08 14:42:19 +02:00
voxel scripts
voxelwall is an 8x8 wall made of voxels that transitions from a bright red to dark blue voxelsoundwaves was an array of voxels that was manipulated to resemble an audio scope that responds to loudness and changes its height depending on the loudness of the audio that the microphone picks up
This commit is contained in:
parent
43ac86897c
commit
9571098b8b
3 changed files with 330 additions and 1 deletions
|
@ -65,7 +65,7 @@ colors[4] = { red: 236, green: 174, blue: 0 };
|
|||
colors[5] = { red: 234, green: 133, blue: 0 };
|
||||
colors[6] = { red: 211, green: 115, blue: 0 };
|
||||
colors[7] = { red: 48, green: 116, blue: 119 };
|
||||
colors[8] = { red: 31, green: 64, blue: 64 };
|
||||
colors[8] = { red: 36, green: 64, blue: 64 };
|
||||
var numColors = 9;
|
||||
var whichColor = 0; // Starting color is 'Copy' mode
|
||||
|
||||
|
|
226
examples/voxelsoundwaves.js
Normal file
226
examples/voxelsoundwaves.js
Normal file
|
@ -0,0 +1,226 @@
|
|||
|
||||
|
||||
|
||||
var wallX = 8000;
|
||||
var wallY = 8000;
|
||||
var wallZ = 8000;//location
|
||||
|
||||
|
||||
var VOXELSIZE=12;//size of each voxel
|
||||
|
||||
var FACTOR = 0.75;
|
||||
|
||||
var loud=1.0;
|
||||
var maxLoud=500;
|
||||
var minLoud=200;//range of loudness
|
||||
|
||||
|
||||
|
||||
var maxB={color:225,direction:0,speed:1};
|
||||
var minB={color:50,direction:1,speed:1};
|
||||
var maxG={color:200,direction:0,speed:1};
|
||||
var minG={color:30,direction:1,speed:1};
|
||||
var maxR={color:255,direction:0,speed:1};
|
||||
var minR={color:150,direction:1,speed:1};//color objects
|
||||
var addVoxArray=[];
|
||||
var removeVoxArray=[];
|
||||
var numAddVox=0;
|
||||
var numRemoveVox=0;//array for voxels removed and added
|
||||
|
||||
|
||||
var height;
|
||||
var wallWidth=34;
|
||||
var wallHeight=25;
|
||||
var maxHeight=wallHeight;
|
||||
var minHeight=0;//properties of wall
|
||||
|
||||
|
||||
var heightSamplesArray=[];
|
||||
var sampleIndex=0;//declare new array of heights
|
||||
|
||||
var direction=1;
|
||||
|
||||
|
||||
|
||||
|
||||
//initiate and fill array of heights
|
||||
for(var k=0;k<wallWidth;k++)
|
||||
{
|
||||
heightSamplesArray[k]=0;
|
||||
}
|
||||
|
||||
|
||||
//send objects to function changeColor
|
||||
function scratch()
|
||||
{
|
||||
|
||||
|
||||
changeColor(maxB);
|
||||
changeColor(minB);
|
||||
changeColor(maxG);
|
||||
changeColor(minG);
|
||||
changeColor(maxR);
|
||||
changeColor(minR);
|
||||
|
||||
//calculates loudness
|
||||
var audioAverageLoudness = MyAvatar.audioAverageLoudness * FACTOR;
|
||||
|
||||
|
||||
loud = Math.log(audioAverageLoudness) / 5.0 * 255.0;
|
||||
|
||||
print("loud="+ loud);
|
||||
|
||||
|
||||
var scalingfactor=(loud-minLoud)/(maxLoud-minLoud);
|
||||
if(scalingfactor<0)
|
||||
{
|
||||
scalingfactor=0;
|
||||
}
|
||||
if(scalingfactor>1)
|
||||
{
|
||||
scalingfactor=1;
|
||||
}
|
||||
|
||||
//creates diff shades for diff levels of volume
|
||||
|
||||
var green=(maxG.color-minG.color)*scalingfactor+minG.color;
|
||||
var blue=(maxB.color-minB.color)*scalingfactor+minB.color;
|
||||
var red=(maxR.color-minR.color)*scalingfactor+minR.color;
|
||||
height=(maxHeight-minHeight)*scalingfactor+minHeight;
|
||||
|
||||
|
||||
//sets height at position sampleIndex
|
||||
heightSamplesArray[sampleIndex]=height;
|
||||
|
||||
|
||||
|
||||
|
||||
if(loud==Number.NEGATIVE_INFINITY)
|
||||
{
|
||||
green=minG.color;
|
||||
blue=minB.color;
|
||||
red=minR.color;
|
||||
|
||||
}
|
||||
|
||||
|
||||
var k=sampleIndex;
|
||||
|
||||
//add&remove voxels
|
||||
|
||||
for(var i=wallWidth-1;i>=0;i--)
|
||||
{
|
||||
|
||||
for(var j=0;j<wallHeight;j++)
|
||||
|
||||
{
|
||||
if(j<=heightSamplesArray[k])
|
||||
{
|
||||
addVoxArray[numAddVox]={x:wallX+i*VOXELSIZE, y:wallY+j*VOXELSIZE, z:wallZ};
|
||||
|
||||
numAddVox++;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
removeVoxArray[numRemoveVox]={x:wallX+i*VOXELSIZE, y:wallY+j*VOXELSIZE, z:wallZ};
|
||||
|
||||
numRemoveVox++;
|
||||
}
|
||||
|
||||
}
|
||||
k--;
|
||||
if(k<0)
|
||||
{
|
||||
k=wallWidth-1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for(var k=0;k<numAddVox;k++)
|
||||
{
|
||||
Voxels.setVoxel(addVoxArray[k].x,addVoxArray[k].y,addVoxArray[k].z,VOXELSIZE, red, green, blue);
|
||||
}
|
||||
|
||||
for(var k=0;k<numRemoveVox;k++)
|
||||
{
|
||||
Voxels.eraseVoxel(removeVoxArray[k].x,removeVoxArray[k].y,removeVoxArray[k].z,VOXELSIZE);
|
||||
}
|
||||
|
||||
numAddVox=0;
|
||||
numRemoveVox=0;
|
||||
|
||||
sampleIndex++;
|
||||
if(sampleIndex>=wallWidth)
|
||||
{
|
||||
sampleIndex=0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
//color properties (shade, direction, speed)
|
||||
|
||||
function changeColor(color)
|
||||
{
|
||||
|
||||
if (color.direction==1)
|
||||
{
|
||||
if(color.color<255)
|
||||
{
|
||||
color.color+=(color.speed);
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
color.direction=0;
|
||||
}
|
||||
|
||||
}
|
||||
else if(color.direction==0)
|
||||
{
|
||||
if(color.color>0)
|
||||
{
|
||||
color.color-=(color.speed);
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
color.direction=1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Script.update.connect(scratch);
|
||||
Voxels.setPacketsPerSecond(20000);
|
||||
|
103
examples/voxelwall.js
Normal file
103
examples/voxelwall.js
Normal file
|
@ -0,0 +1,103 @@
|
|||
|
||||
|
||||
|
||||
var wallX = 700;
|
||||
var wallY = 700;
|
||||
var wallZ = 700;//location
|
||||
|
||||
var VOXELSIZE=8;
|
||||
var red=225;
|
||||
var blue=0;
|
||||
var green=0;//color brightness
|
||||
var currentStep=0;//counting number of steps
|
||||
var direction=1;//left to right color change
|
||||
var height=8;
|
||||
var width=8;
|
||||
|
||||
|
||||
var currentStep=0;
|
||||
|
||||
|
||||
|
||||
|
||||
function step()
|
||||
{
|
||||
|
||||
|
||||
|
||||
currentStep++;
|
||||
|
||||
if(currentStep>6000)//how long it will run
|
||||
Script.stop();
|
||||
|
||||
|
||||
for(var i=0;i<width;i++)
|
||||
{
|
||||
for(var j=0;j<height;j++)
|
||||
{
|
||||
|
||||
Voxels.setVoxel(wallX+i*VOXELSIZE, wallY+j*VOXELSIZE, wallZ, VOXELSIZE, red,green,blue);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (direction==1)
|
||||
{
|
||||
if(blue<255)
|
||||
{
|
||||
blue++;
|
||||
red--;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
direction=0;
|
||||
}
|
||||
|
||||
}
|
||||
else if(direction==0)
|
||||
{
|
||||
if(blue>0)
|
||||
{
|
||||
blue--;
|
||||
red++;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
direction=1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Script.update.connect(step);
|
||||
Voxels.setPacketsPerSecond(20000);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in a new issue