// Cloned by test2 on 11 May 2018 from World "Blank Three.js World" by Starter user
// Please leave this clone trail here.
// ==== Starter World ===============================================================================================
// (c) Ancient Brain Ltd. All rights reserved.
// This code is only for use on the Ancient Brain site.
// This code may be freely copied and edited by anyone on the Ancient Brain site.
// This code may not be copied, re-published or used on any other website.
// To include a run of this code on another website, see the "Embed code" links provided on the Ancient Brain site.
// ==================================================================================================================
// Starter World for Three.js experiments
// No Mind
// Just World
// ===================================================================================================================
// === Start of tweaker's box ========================================================================================
// ===================================================================================================================
// The easiest things to modify are in this box.
// You should be able to change things in this box without being a JavaScript programmer.
// Go ahead and change some of these. What's the worst that could happen?
// These 3 have default values, so this section is optional:
AB.clockTick = 100;
// Speed of run: Step every n milliseconds. Default 100.
AB.maxSteps = 1000;
// Length of run: Maximum length of run in steps. Default 1000.
AB.screenshotStep = 50;
// Take screenshot on this step. (All resources should have finished loading.) Default 50.
const FILE_ARRAY = [
"/uploads/starter/earth.1.jpg",
"/uploads/starter/earth.2.jpg",
"/uploads/starter/earth.3.jpg",
"/uploads/starter/earth.4.jpg",
"/uploads/starter/earth.5.jpg"
];
const SKYCOLOR = 0xffffff; // a number, not a string
const ARMYSIZE = 3000; // an "army" of objects
const objectsize = 300 ;
const WALKSTEP = 500; // bounds of the random move per timestep
// try 50 (vibrating sheet) versus 1000 (cloud)
const MAXPOS = 4000 ; // start things within these bounds
const startRadiusConst = MAXPOS * 2 ; // distance from centre to start the camera at
const maxRadiusConst = MAXPOS * 5 ; // maximum distance from camera we will render things
//--- change threeworld defaults: -------------------------------
threehandler.MAXCAMERAPOS = MAXPOS * 10 ; // allow camera go far away
// ===================================================================================================================
// === End of tweaker's box ==========================================================================================
// ===================================================================================================================
// You will need to be some sort of JavaScript programmer to change things below the tweaker's box.
function randomfloatAtoB ( A, B )
{
return ( A + ( Math.random() * (B-A) ) );
}
function randomintAtoB ( A, B )
{
return ( Math.round ( randomfloatAtoB ( A, B ) ) );
}
function World() {
var THEARMY = new Array( ARMYSIZE );
function initArmy()
{
var t = 0;
for ( var c=1 ; c <= ARMYSIZE ; c++ )
{
var shape = new THREE.SphereGeometry ( objectsize, 10, 10 );
// var shape = new THREE.BoxGeometry( objectsize, objectsize, objectsize );
var theobject = new THREE.Mesh( shape );
theobject.position.x = randomintAtoB ( -MAXPOS, MAXPOS );
theobject.position.z = randomintAtoB ( -MAXPOS, MAXPOS );
theobject.position.y = 0;
threeworld.scene.add(theobject);
THEARMY[t] = theobject; // save it for later
t++;
}
}
function paintArmy() // paint objects with random textures
{
var textureArray = [
( new THREE.ImageUtils.loadTexture( FILE_ARRAY[0] ) ),
( new THREE.ImageUtils.loadTexture( FILE_ARRAY[1] ) ),
( new THREE.ImageUtils.loadTexture( FILE_ARRAY[2] ) ),
( new THREE.ImageUtils.loadTexture( FILE_ARRAY[3] ) ),
( new THREE.ImageUtils.loadTexture( FILE_ARRAY[4] ) )
];
for ( var i = 0; i < textureArray.length; i++ ) // for all textures
{
textureArray[i].minFilter = THREE.LinearFilter;
}
for ( var i = 0; i < THEARMY.length; i++ ) // for all objects
{
if ( THEARMY[i] )
{
var t = randomintAtoB ( 0, textureArray.length - 1 ); // random texture
THEARMY[i].material = new THREE.MeshBasicMaterial ( { map: textureArray[t] } );
}
}
}
function moveArmy() // move all the objects
{
for ( var i = 0; i < THEARMY.length; i++ )
{
if ( THEARMY[i] )
{
THEARMY[i].position.x = THEARMY[i].position.x + randomintAtoB(-WALKSTEP,WALKSTEP) ;
THEARMY[i].position.z = THEARMY[i].position.z + randomintAtoB(-WALKSTEP,WALKSTEP) ;
THEARMY[i].position.y = THEARMY[i].position.y + randomintAtoB(-WALKSTEP,WALKSTEP) ;
threeworld.scene.add( THEARMY[i] );
}
}
}
this.endCondition = false;
this.newRun = function()
{
threeworld.init3d ( startRadiusConst, maxRadiusConst, SKYCOLOR );
initArmy();
paintArmy(); // comment out for random coloured objects
};
this.nextStep = function()
{
moveArmy();
};
this.endRun = function()
{
};
}