content/hifi-content/andrewh/dancefloor.js
2022-02-13 21:18:16 +01:00

491 lines
11 KiB
JavaScript

var time = 0;
var realTime = 0;
var blockSize = 1.0;
var gridSize = 10;
var width = (blockSize*gridSize);
var position = Vec3.sum(Vec3.sum(MyAvatar.position,{x:0,y:-1,z:0}), Vec3.multiply(Quat.getFront(MyAvatar.orientation),width+0));
var colorList = [{red: 255, green: 0, blue: 0},{red: 0, green: 255, blue: 0},{red: 0, green: 0, blue: 255},
{red: 255, green: 255, blue: 0},{red: 255, green: 0, blue: 255},{red: 0, green: 255, blue: 255}]
var colorScheme = 0;
//Make base
var properties = {
type: "Box",
name: "Dancefloor_base",
position: position,
color: { red: 0, green: 0, blue: 0},
collisionless: false,
grab: { grabbable: false },
localDimensions: {x:width+blockSize,y:0.25,z:width+blockSize}
};
base = Entities.addEntity(properties);
var tx = position.x;
var tz = position.z;
//spagonfetti particles
properties = {
type: "ParticleEffect",
name: "Dancefloor_confetti",
grab: { grabbable: false },
position: Vec3.sum(position,{x:0,y:7,z:0}),
textures: "https://hifi-content.s3.amazonaws.com/andrewh/Dancefloor_app/confetti.png",
maxParticles: 10000,
lifespan: 10,
emitRate: 50,
emitSpeed: 0,
speedSpread: 0,
emitOrientation: {
x: -0.0000152587890625,
y: -0.0000152587890625,
z: -0.0000152587890625,
w: 1
},
emitDimensions: {
x: 10,
y: 0,
z: 10
},
polarFinish: 3.1415927410125732,
emitAcceleration: {
x: 0,
y: -0.20000000298023224,
z: 0
},
accelerationSpread: {
x: 0,
y: 0.20000000298023224,
z: 0
},
particleRadius: 0.10000000149011612,
radiusStart: 0.10000000149011612,
radiusFinish: 0.10000000149011612,
colorSpread: {
red: 255,
green: 255,
blue: 255
},
colorStart: {
red: 255,
green: 255,
blue: 255
},
colorFinish: {
red: null,
green: null,
blue: null
},
alphaStart: 0,
alphaFinish: 1,
emitterShouldTrail: false,
particleSpin: 0.3490658402442932,
spinSpread: 6.2831854820251465,
spinStart: 0,
spinFinish: 0.6981316804885864,
parentID: base
};
var confetti = Entities.addEntity(properties);
properties = {
type: "ParticleEffect",
name: "Dancefloor_confetti_floor",
grab: { grabbable: false },
position: Vec3.sum(position,{x:0,y:0.42,z:0}),
textures: "https://hifi-content.s3.amazonaws.com/andrewh/Dancefloor_app/confetti.png",
maxParticles: 10000,
lifespan: 5,
emitRate: 0,
emitSpeed: 0,
speedSpread: 0,
emitOrientation: {
x: -0.0000152587890625,
y: -0.0000152587890625,
z: -0.0000152587890625,
w: 1
},
emitDimensions: {
x: 10,
y: 0,
z: 10
},
polarFinish: 3.1415927410125732,
emitAcceleration: {
x: 0,
y: 0,
z: 0
},
accelerationSpread: {
x: 0,
y: 0,
z: 0
},
particleRadius: 0.10000000149011612,
radiusStart: 0.10000000149011612,
radiusFinish: 0.10000000149011612,
colorSpread: {
red: 255,
green: 255,
blue: 255
},
colorStart: {
red: 255,
green: 255,
blue: 255
},
colorFinish: {
red: null,
green: null,
blue: null
},
alphaStart: 0,
alphaFinish: 1,
emitterShouldTrail: false,
spinSpread: 6.2831854820251465,
spinStart: 0,
spinFinish: 0,
parentID: base
};
var confettiFloor = Entities.addEntity(properties);
//light rotators
properties = {
type: "Sphere",
name: "Dancefloor_lightmover_1",
position: Vec3.sum(position,{
x: 1.5937108993530273,
y: 0.2123088836669922,
z: 0
}),
grab: { grabbable: false },
angularVelocity: {
x: 0,
y: -0.6,
z: 0
},
angularDamping: 0,
collisionless: true,
ignoreForCollisions: true,
parentID: base
}
var light_rotator1 = Entities.addEntity(properties);
properties = {
type: "Sphere",
name: "Dancefloor_lightmover_2",
position: Vec3.sum(position,{
x: 0,
y: 0,
z: 0.29303932189941406
}),
grab: { grabbable: false },
angularVelocity: {
x: 0,
y: 1.0,
z: 0
},
angularDamping: 0,
collisionless: true,
ignoreForCollisions: true,
parentID: base
}
var light_rotator2 = Entities.addEntity(properties);
//lights
properties = {
type: "Light",
name: "Dacefloor_light_1",
position: Vec3.sum(position,{
x: -2.5197582244873047,
y: 0.5514755249023438,
z: -0.6430681347846985
}),
dimensions: {
x: 5.1181488037109375,
y: 5.1181488037109375,
z: 5.1181488037109375
},
grab: { grabbable: false },
color: {
red: 0,
green: 0,
blue: 255
},
intensity: 75,
exponent: 1,
cutoff: 90,
falloffRadius: 100,
parentID: light_rotator1
}
var light1 = Entities.addEntity(properties);
properties = {
type: "Light",
name: "Dancefloor_light_2",
position: Vec3.sum(position,{
x: 1.535553216934204,
y: 0.5515842437744141,
z: 2.098341941833496
}),
dimensions: {
x: 5.1181488037109375,
y: 5.1181488037109375,
z: 5.1181488037109375
},
grab: { grabbable: false },
color: {
red: 255,
green: 0,
blue: 0
},
intensity: 75,
exponent: 1,
cutoff: 90,
falloffRadius: 100,
parentID: light_rotator2
}
var light2 = Entities.addEntity(properties);
//calzone
properties = {
type: "Zone",
name: "Dancefloor_zone",
position: position,
dimensions: {
x: 12,
y: 12,
z: 12
},
grab: { grabbable: false },
shapeType: "box",
keyLight: {
intensity: 2.0,
color: {
red: 255,
green: 0,
blue: 0
},
direction: {
x: 0,
y: -0.7071067690849304,
z: 0.7071067690849304
},
castShadows: false
},
bloom: {
bloomIntensity: 1,
bloomThreshold: 0.20000000298023224,
bloomSize: 1
},
keyLightMode: "enabled",
bloomMode: "enabled",
parentID: base
}
var partyZone = Entities.addEntity(properties);
//add tiles
var tiles = [];
for(var i=0;i<gridSize;i++){
for(var j=0;j<gridSize;j++){
print(JSON.stringify(i)+":"+JSON.stringify(j));
var evenOrOdd = j+i;
var tileColor;
if(evenOrOdd % 2 == 0){
tileColor = {
red: Math.random()*254,
green: Math.random()*254,
blue: Math.random()*254};
}
else{
tileColor = {
red: 0,
green: 0,
blue: 0
};
}
var x = (i*blockSize)-(width/2)+(blockSize/2);
var z = (j*blockSize)-(width/2)+(blockSize/2);
properties = {
type: "Box",
name: "Dancefloor_tile_"+JSON.stringify(i)+":"+JSON.stringify(j),
position: Vec3.sum(position,{x:x,y:0.25,z:z}),
color: tileColor,
collisionless: false,
grab: { grabbable: false },
localDimensions: {x:blockSize,y:0.25,z:blockSize},
parentID: base
};
tiles.push(Entities.addEntity(properties));
}
}
Script.update.connect(update);
function update(deltaTime){
time++;
realTime += deltaTime;
if(time % 100 == 0){
colorScheme++;
if (colorScheme > 3){
colorScheme = 0;
}
// swap to white solid tiles for pastel color scheme
if (colorScheme == 3){
for(var i=0;i<gridSize*gridSize;i++){
var clr = Entities.getEntityProperties(tiles[i],["color"]);
if (clr.color.red+clr.color.green+clr.color.blue == 0){
Entities.editEntity(tiles[i], {color: {red:255,green:255,blue:255}});
}
}
}
else{
for(var i=0;i<gridSize*gridSize;i++){
var clr = Entities.getEntityProperties(tiles[i],["color"]);
if (clr.color.red+clr.color.green+clr.color.blue == 765){
Entities.editEntity(tiles[i], {color: {red:0,green:0,blue:0}});
}
}
}
//environment change
var environment = {
l1:[0,0,0],
l2:[0,0,0],
amb:[0,0,0]
};
switch(colorScheme){
case 0: //red/purple/blue
environment = {
l1:[255,0,0],
l2:[0,0,255],
amb:[255,0,0]
};
break;
case 1: //red/orange/yellow
environment = {
l1:[255,64,0],
l2:[255,255,0],
amb:[255,128,0]
};
break;
case 2: //blue/cyan/white
environment = {
l1:[0,0,255],
l2:[0,255,255],
amb:[0,0,255]
};
break;
case 3: //vaporwave
environment = {
l1:[255,0,0],
l2:[0,255,0],
amb:[128,128,128]
};
break;
}
Entities.editEntity(light1,{color:environment.l1});
Entities.editEntity(light2,{color:environment.l2});
Entities.editEntity(partyZone,{keyLight:{color:environment.amb } });
}
//COLOR CHANGE
if(time%1 == 0){
for(var i=0;i<gridSize*gridSize;i++){
var rgbsplit = [0,0,0];
switch(colorScheme){
case 0: //red/purple/blue
rgbsplit[0] = Math.random()*255;
rgbsplit[2] = 255-rgbsplit[0];
break;
case 1: //red/orange/yellow
rgbsplit[0] = 255;
rgbsplit[1] = Math.random()*255;
break;
case 2: //blue/cyan/white
if (Math.floor(Math.random()*((gridSize*gridSize)/10)) == 0){
rgbsplit = [254,254,254];
}
else{
rgbsplit[1] = Math.random()*255;
rgbsplit[2] = 255;
};
break;
case 3: //vaporwave (never let tiles go completely white so they remain differentiated from solid color tiles)
if (Math.floor(Math.random()*((gridSize*gridSize)/10)) == 0){
rgbsplit = [128,255,170];
}
else{
rgbsplit[0] = (Math.random()*128)+127;
rgbsplit[1] = 127;
rgbsplit[2] = (Math.random()*128)+127;
};
break;
}
var clr = Entities.getEntityProperties(tiles[i],["color"]);
if(clr.color.red+clr.color.green+clr.color.blue != 0 && clr.color.red+clr.color.green+clr.color.blue != 765){
clr = {
red: rgbsplit[0],
green: rgbsplit[1],
blue: rgbsplit[2]};
//clr = colorList[Math.floor(Math.random()*6)];
Entities.editEntity(tiles[i], {color: clr});
}
}
}
//print(time);
var floorStarted = Entities.getEntityProperties(confettiFloor,"emitRate");
if(realTime > 6 && floorStarted.emitRate == 0){
//delay floor confetti to maintain the Great Illusion
Entities.editEntity(confettiFloor,{emitRate:50});
}
}
function cleanup() {
Entities.deleteEntity(base);
}
Script.scriptEnding.connect(cleanup);