// Cloned by jahangir alam on 24 Sep 2024 from World "Blank Three.js World" by Starter user
// Please leave this clone trail here.
// ==== Starter World =================================================================================================
// This code is designed for use on the Ancient Brain site.
// This code may be freely copied and edited by anyone on the Ancient Brain site.
// To include a working run of this program on another site, see the "Embed code" links provided on Ancient Brain.
// ====================================================================================================================
// 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?
const MUSICFILE = '/uploads/starter/SuspenseStrings.mp3';
AB.backgroundMusic ( MUSICFILE );
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/alamj2/1727021173.png",
"/uploads/alamj2/1727174292.png",
"/uploads/alamj2/1727174397.png",
"/uploads/alamj2/1727174342.png",
"/uploads/alamj2/1727174490.png"
];
const SKYCOLOR = 0xffffff; // a number, not a string
const ARMYSIZE = 100; // an "army" of objects
const objectsize = 300 ;
const WALKSTEP = 50; // 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 ABWorld defaults: -------------------------------
ABHandler.MAXCAMERAPOS = MAXPOS * 10 ; // allow camera go far away
ABWorld.drawCameraControls = false;
// ===================================================================================================================
// === End of tweaker's box ==========================================================================================
// ===================================================================================================================
// You will need to be some sort of JavaScript programmer to change things below the tweaker's box.
var THEARMY = new Array( ARMYSIZE );
var textureArray = new Array ( FILE_ARRAY.length );
function loadResources() // asynchronous file loads - call initScene() when all finished
{
for ( var i = 0; i < FILE_ARRAY.length; i++ )
startFileLoad ( i ); // launch n asynchronous file loads
}
function startFileLoad ( n ) // asynchronous file load of texture n
{
var loader = new THREE.TextureLoader();
loader.load ( FILE_ARRAY[n], function ( thetexture )
{
thetexture.minFilter = THREE.LinearFilter;
textureArray[n] = thetexture;
if ( asynchFinished() ) initArmy();
});
}
function asynchFinished() // all file loads returned
{
for ( var i = 0; i < FILE_ARRAY.length; i++ )
if ( ! textureArray[i] )
return false;
return true;
}
// Initialize the army of frogs instead of spheres
function initArmy() {
var t = 0;
for (var c = 1; c <= ARMYSIZE; c++) {
var frog = createFrog(); // Create a frog shape
frog.position.x = AB.randomIntAtoB(-MAXPOS, MAXPOS);
frog.position.z = AB.randomIntAtoB(-MAXPOS, MAXPOS);
frog.position.y = AB.randomIntAtoB(-MAXPOS, MAXPOS);
ABWorld.scene.add(frog);
THEARMY[t] = frog; // Save it for later movement
t++;
}
// Can start the run loop
ABWorld.render();
AB.removeLoading();
AB.runReady = true;
}
// Function to create a frog shape using various geometries
function createFrog() {
var frog = new THREE.Group(); // Group to combine body parts
// Frog body
var bodyGeometry = new THREE.SphereGeometry(objectsize * 0.6, 16, 16);
var bodyMaterial = new THREE.MeshBasicMaterial({ color: 0x228B22 }); // Green color
var body = new THREE.Mesh(bodyGeometry, bodyMaterial);
body.position.y = objectsize * 0.3;
frog.add(body); // Add body to the frog group
// Frog legs (cylinders)
var legGeometry = new THREE.CylinderGeometry(objectsize * 0.1, objectsize * 0.1, objectsize * 0.6, 12);
var legMaterial = new THREE.MeshBasicMaterial({ color: 0xFFC0CB }); // Same green as body
var leg1 = new THREE.Mesh(legGeometry, legMaterial);
leg1.position.set(-objectsize * 0.3, 0, -objectsize * 0.3);
leg1.rotation.z = Math.PI / 4;
frog.add(leg1); // Add front-left leg
var leg2 = leg1.clone();
leg2.position.set(objectsize * 0.3, 0, -objectsize * 0.3);
frog.add(leg2); // Add front-right leg
var leg3 = leg1.clone();
leg3.position.set(-objectsize * 0.3, 0, objectsize * 0.3);
frog.add(leg3); // Add back-left leg
var leg4 = leg1.clone();
leg4.position.set(objectsize * 0.3, 0, objectsize * 0.3);
frog.add(leg4); // Add back-right leg
// Frog eyes (small spheres)
var eyeGeometry = new THREE.SphereGeometry(objectsize * 0.15, 8, 8);
var eyeMaterial = new THREE.MeshBasicMaterial({ color: 0xFF0000 }); // White for the eyes
var eye1 = new THREE.Mesh(eyeGeometry, eyeMaterial);
eye1.position.set(-objectsize * 0.2, objectsize * 0.8, objectsize * 0.4);
frog.add(eye1); // Add left eye
var eye2 = eye1.clone();
eye2.position.set(objectsize * 0.2, objectsize * 0.8, objectsize * 0.4);
frog.add(eye2); // Add right eye
return frog; // Return the group representing the frog
}
// Update the movement function to move the frogs
function moveArmy() {
for (var i = 0; i < THEARMY.length; i++) {
if (THEARMY[i]) { // In case initArmy() not called yet
THEARMY[i].position.x = THEARMY[i].position.x + AB.randomIntAtoB(-WALKSTEP, WALKSTEP);
THEARMY[i].position.z = THEARMY[i].position.z + AB.randomIntAtoB(-WALKSTEP, WALKSTEP);
THEARMY[i].position.y = THEARMY[i].position.y + AB.randomIntAtoB(-WALKSTEP, WALKSTEP);
ABWorld.scene.add(THEARMY[i]);
}
}
}
AB.world.newRun = function()
{
AB.loadingScreen();
AB.runReady = false;
ABWorld.init3d ( startRadiusConst, maxRadiusConst, SKYCOLOR );
loadResources(); // aynch file loads
// calls initArmy() when it returns
};
AB.world.nextStep = function()
{
moveArmy();
};