//////////////////////////////////////////////////

// 2DblankArray.thd

// Blank ether array with alternating colors

//////////////////////////////////////////////////

 

// set background color

scene.backColor=RGB(0,0,0);

 

// turn gravity off

scene.gravity={0,0,0};

 

// remove shadows for faster rendering

scene.shadow = false;

 

// use degrees as metric for angles

factory.useDegrees = true;

scene.windowSize = {250,250};

 

// turn collision detection off so things don't blow up

factory.detectCollision = false;

 

// set colors

var blue = RGB(100,100,255);

var white = RGB(200, 200, 200);

 

// choose some default material

//Material (density, springConstant, dampingConstant, staticFriction, dynamicFriction, thresholdVelocity);

var mat = Material(1e-8, .0001, .00001, 1, 1);

factory.material = mat ;

 

// set spring and damper constants

var spngCnst = .00000001;

var dmpCnst = .00000005;

 

// set dimensions of array

var width = 15; // enter number of balls for array width

var depth = 15; // enter number of balls for array depth

var spacing = 20; // enter spacing between balls

var ball = "";

var ballSize = 3;

 

// position camera in middle of array

// consider camera to be hovering over array looking down on x z plane

scene.camera = {spacing*width*0.5, spacing*width*1.5, spacing*depth*0.4};

// point camera down at middle of array

scene.lookAt = {spacing*width*0.5, 0, spacing*depth*0.4};

 

// build array of spheres

var s = array();

for (var x=0; x < width; x++) {

   s.append(array());

       for (var z=0; z < depth; z++) {

            var ball = Sphere(ballSize, {x*spacing,0,z*spacing});

            // color every 5th ball on z & x axis

            if(x%5 == 1 || z%5 == 1){

                ball.color = blue;

            }else{

                ball.color = white;

            }

            ball.visible = true;

          s[x].append(ball);

            // set all outer edge balls as stationary otherwise array collapses

            if (x==0||x==width-1||z==0||z==depth-1){

                ball.static = true;

            }

         }

}

 

// build array of springs and dampers attaching to spheres on x axis

var spx = array();

var dpx = array();

var dmpr = "";

var sprng = "";

for (x=0; x < width-1; x++) {

   spx.append(array());

    dpx.append(array());

       for (var z=0; z < depth; z++) {

            // make spring and attach to adjacent spheres

            sprng = Spring(s[x][z],{0,0,0},s[x+1][z],{0,0,0});

            sprng.springConstant = spngCnst;

             spx[x].append(sprng);

            // make damper and attach to adjacent spheres

            var dmpr = Damper(s[x][z],{0,0,0},s[x+1][z],{0,0,0});

            dmpr.damperConstant = dmpCnst;

            // color every 5th damper blue on x axis

            if(z%5 == 1){

                dmpr.color = blue;

            }else{

                dmpr.color = white;

            }

            dpx[x].append(dmpr);

         }

}

 

// build array of springs and dampers attaching to spheres on z axis

var spz = array();

var dpz = array();

for (x=0; x < width; x++) {

   spz.append(array());

    dpz.append(array());

       for (var z=0; z < depth-1; z++) {

            // make spring and attach to adjacent spheres

            var sprng = Spring(s[x][z],{0,0,0},s[x][z+1],{0,0,0});

            sprng.springConstant = spngCnst;

          spz[x].append(sprng);

            // make damper and attach to adjacent spheres

            var dmpr = Damper(s[x][z],{0,0,0},s[x][z+1],{0,0,0});

            dmpr.damperConstant = dmpCnst;

            // color every 5th damper blue on z axis

            if(x%5 == 1){

                dmpr.color = blue;

            }else{

                dmpr.color = white;

            }

            dpz[x].append(dmpr);

         }

}

 

// render image

WaitFrame();

2020 by Peter C.M. Hahn C.E.T.

ResearchGate