3 Replies Latest reply on Jul 27, 2006 1:38 AM by Evil Sean 120%

    programming gears w/ ratios, dials

    Evil Sean 120%
      I made a dial, lets call it gear1. It functions adequately using mousemove and some trigonometry. If I want to have animation of a larger gear (gear2), lets say one with 5 times the perimeter, the logic is basically gear2._rotation = gear1._rotation/5, but since flash autoresolves _rotation to -180--+180 values, the rotation value for gear2 has a range of only -36 to +36.

      Questions:
      How do I get the value of the total rotation I have applied to gear1 or work without it?
      How do I make it a true dial, one that doesnt reset to the dial rotation to the angle to the mouse position, but rather retains the previous setting and adds to it with the new onpress onmousemove? like turning the volume pot on a walkman... you can only rotate it maybe 60 degrees each time, but the full 360 degrees is the range available to you.

      here is some sample that doesn't work adequately...

      gear1.onPress = function(){
      gear1.onMouseMove = function(){
      var angle = Math.atan2(this._parent._ymouse-this._y,this._parent._xmouse-this._x);
      var degrees = int(angle*180/Math.PI);
      this._rotation = degrees
      gear2._rotation = this._rotation/5

      }
      }
      gear1.onMouseUp = function(){
      if (this.onMouseMove) delete this.onMouseMove;
      }

      Thank you for looking at my problem.
        • 1. Re: programming gears w/ ratios, dials
          kglad Adobe Community Professional & MVP
          increment your large gear's _rotation property (based on the increment of gear2's _rotation property).
          • 2. Re: programming gears w/ ratios, dials
            Evil Sean 120% Level 1
            Thank you for replying.

            I don't understand how to use increment in this situation. The large gear would rotate 1/5 the amount of the small gear (which is the control, the user rotatable movieclip). THe user would have to rotate the small gear 5 times to rotate the large gear once. How do I use increment to effectively return 1/5 value of one gear and apply it to rotation of another?

            Thank you.
            • 3. Re: programming gears w/ ratios, dials
              Evil Sean 120% Level 1
              I figured it out.

              if (degrees >= 175){
              dega = 1
              if (dega == 1 && degb == 1){
              rotation = rotation + 360*int(-angle) + 720
              degb = 0
              }
              }
              if (degrees <= -175){
              degb = 1
              if (dega == 1 && degb == 1){
              rotation = rotation + 360*int(-angle) - 720
              dega = 0
              }
              }
              if (degrees < 175 && degrees > -175){
              dega = 0
              degb = 0
              }

              total = degrees + rotation;
              this._rotation = total
              ring._rotation = int(total/7.5);
              };

              Its a bit sloppy, but works. I hope this helps the next person that needs to do gears.