Code viewer for World: Refactored World
// refactored version of
// https://ancientbrain.com/world.php?world=6173193650 
// using AB functionality 


var pointLight, pointLight2;
var shapes = [];
var cantidad = 60;



AB.world.newRun = function() 
{
    ABWorld.init3d ( 100, 1000, 'black' ); 

    pointLight = new THREE.PointLight( "#A905FA", 60, 100 );
    pointLight.position.set( 0,0, 50 );
    ABWorld.scene.add(pointLight);

    pointLight2 = new THREE.PointLight( "#08FAA0", 40, 100 );
    pointLight2.position.set( 0,0, -60 );
    ABWorld.scene.add(pointLight2);

 for (var i = 0; i < cantidad; i++) 
 {
    var geometry, material;
 
    if(Math.random()<0.1)   geometry = new THREE.RingGeometry( 6, 50, 8 );
    else                    geometry = new THREE.RingGeometry( 4, 60, 9 );

    if(i%7===0)         material = new THREE.MeshPhongMaterial( { color: "#ffffff"} );
    else if(i%2===0)    material = new THREE.MeshPhongMaterial( { color: "#666555"} );
    else                material = new THREE.MeshPhongMaterial( { color: "#333444"} );
    
    var mesh = new THREE.Mesh(geometry,material);
    mesh.position.z = -i*2;
    mesh.rotation.z=i;
    shapes.push(mesh);
    ABWorld.scene.add(mesh);
 }
};




AB.world.nextStep = function() 
{ 
 for (var i = 0; i < cantidad; i++) 
 {
        shapes[i].position.z+=0.2;
        shapes[i].rotation.z+=0.02;

        shapes[i].scale.x=1+Math.sin(i+AB.step*0.1)*0.2;
        shapes[i].scale.y=1+Math.sin(i+AB.step*0.1)*0.337;

        var valor = 0.5 + Math.sin(AB.step*0.05)*0.5;

        if(Math.random()<valor)
        {
            shapes[i].material.wireframe = true;
            shapes[i].material.wireframeLinewidth = Math.random()*3;
        }
        else
            shapes[i].material.wireframe = false;

        if(shapes[i].position.z>10)
        {
            shapes[i].position.z = -70;
            shapes[i].rotation.z=i;
        }
 }

    pointLight.intensity = Math.abs(Math.sin(AB.step*1)*2);
    pointLight2.intensity = Math.abs(Math.cos(AB.step*5)*2);
    pointLight.position.z = Math.abs(Math.sin(AB.step*0.1)*30);
    pointLight2.position.z = Math.abs(Math.cos(AB.step*0.3)*30);
};