0 Replies Latest reply on Sep 18, 2009 1:22 AM by tallisnotnormal

    Kinematic Chain

    tallisnotnormal

      Hey i have code to make a Kinematic chain but am having trouble changeing it from Math.Random into a grid array with it still being a chain.i can get it into a grid but none of the chain is together and the pieces move seperatly any ideas what i can do? i'm still a bit new to flash but i know the basics.

       

      Code for chain

       

      move = function (parent) {
          if (parent==undefined) {this._x=_xmouse;this._y=_ymouse;}
          else makemove(this,parent);
          for (var a=0;a<this.nb.length;++a) {
              if (parent!=this.nb[a]) this.nb[a].move(this);
          }
      };
      makemove = function(child,parent) {
          var dx = child._x-parent._x;
          var dy = child._y-parent._y;
          var alpha = Math.atan2(dy, dx);
          child._x = parent._x+Math.cos(alpha)*d;
          child._y = parent._y+Math.sin(alpha)*d;
          child._rotation=(Math.PI+alpha)*180/Math.PI;
      }
      press = function () {
          this.onMouseMove = move;
      };
      release = function () {
          delete this.onMouseMove;
      };
      var d = 50;
      var num = 60;
      for (var a = 0; a<num; ++a) {
          attachMovie("pt","pt"+a,a,{_x:Math.random()*400,_y:Math.random()*200});
          this["pt"+a].onPress = press;
          this["pt"+a].onRelease = release;
          this["pt"+a].onReleaseOutside = release;
          this["pt"+a].move = move;
      }
      for (var a = 0; a<num-1; ++a) {
          this["pt"+a].nb = [this["pt"+(a-1)],this["pt"+(a+1)]];   
      }
      pt8.nb=[pt7];
      pt3.nb.push(pt9);
      pt9.nb=[pt3];
      pt0.move();

       

       

       

       

       

       

      Code altered into grid

       

      var row = 15;
      var column = 10;

       

      for (a=0; a<row; ++a) { /

       


         
          for (b=0; b<column; b++) {
              new_name = "pt_"+a+"_"+b;
              attachMovie("pt", new_name, this.getNextHighestDepth());
              this[new_name]._x = a * 50;
              this[new_name]._y = b * 50; //+a()*400,_y:Math.column+b()*200});
              this[new_name].onPress = pressed;
              this[new_name].onRelease = released;
              this[new_name].onReleaseOutside = released;
              this[new_name].move = move_me;
             
              move_me = function (parent) {
                  if (parent==undefined) {this._x=_xmouse;this._y=_ymouse;}
                  else makemove(this,parent);
                  for (var a=0;a<this.nb.length;++a) {
                      if (parent!=this.nb[a]) this.nb[a].move_me(this);
                  }

       

              }
             
              makemove = function(child,parent) {
                  var dx = child._x-parent._x;
                  var dy = child._y-parent._y;
                  var alpha = Math.atan2(dy, dx);
                  child._x = parent._x+Math.cos(alpha)*d;
                  child._y = parent._y+Math.sin(alpha)*d;
                  child._rotation=(Math.PI+alpha)*180/Math.PI;
              }
             
              pressed = function () {
                  this.onMouseMove = move_me;
              }
             
              released = function () {    
                  delete this.onMouseMove;
              }
          }
      }

       

       

      also is it possible to import an external image and attach it over top of a movie clip?