home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 February / Chip_2003-02_cd1.bin / firmy / acomw / js / dynlayer-glide.js < prev    next >
Text File  |  2002-11-29  |  3KB  |  76 lines

  1. // DynLayer Glide Methods
  2. // alternative DynLayer animation methods with an acceleration effect
  3. // 19990531
  4.  
  5. // Copyright (C) 1999 Dan Steinman
  6. // Distributed under the terms of the GNU Library General Public License
  7. // Available at http://www.dansteinman.com/dynapi/
  8.  
  9. function DynLayerGlideTo(startSpeed,endSpeed,endx,endy,angleinc,speed,fn) {
  10.     if (endx==null) endx = this.x
  11.     if (endy==null) endy = this.y
  12.     var distx = endx-this.x
  13.     var disty = endy-this.y
  14.     this.glideStart(startSpeed,endSpeed,endx,endy,distx,disty,angleinc,speed,fn)
  15. }
  16. function DynLayerGlideBy(startSpeed,endSpeed,distx,disty,angleinc,speed,fn) {
  17.     var endx = this.x + distx
  18.     var endy = this.y + disty
  19.     this.glideStart(startSpeed,endSpeed,endx,endy,distx,disty,angleinc,speed,fn)
  20. }
  21. function DynLayerGlideStart(startSpeed,endSpeed,endx,endy,distx,disty,angleinc,speed,fn) {
  22.     if (this.glideActive) return
  23.     if (endx==this.x) var slantangle = 90
  24.     else if (endy==this.y) var slantangle = 0
  25.     else var slantangle = Math.abs(Math.atan(disty/distx)*180/Math.PI)
  26.     if (endx>=this.x) {
  27.         if (endy>this.y) slantangle = 360-slantangle
  28.     }
  29.     else {
  30.         if (endy>this.y) slantangle = 180+slantangle
  31.         else slantangle = 180-slantangle
  32.     }
  33.     slantangle *= Math.PI/180
  34.     var amplitude = Math.sqrt(Math.pow(distx,2) + Math.pow(disty,2))
  35.     if (!fn) fn = null
  36.     this.glideActive = true
  37.     if (startSpeed == "fast") {
  38.         if (endSpeed=="fast") this.glide(1,amplitude/2,0,90,this.x,this.y,slantangle,endx,endy,distx,disty,angleinc,speed,fn)
  39.         else this.glide(0,amplitude,0,90,this.x,this.y,slantangle,endx,endy,distx,disty,angleinc,speed,fn)
  40.     }
  41.     else {
  42.         if (endSpeed=="fast") this.glide(0,amplitude,-90,0,this.x+distx,this.y+disty,slantangle,endx,endy,distx,disty,angleinc,speed,fn)
  43.         else this.glide(0,amplitude/2,-90,90,this.x+distx/2,this.y+disty/2,slantangle,endx,endy,distx,disty,angleinc,speed,fn)
  44.     }
  45. }
  46. function DynLayerGlide(type,amplitude,angle,endangle,centerX,centerY,slantangle,endx,endy,distx,disty,angleinc,speed,fn) {
  47.     if (angle < endangle && this.glideActive) {
  48.         angle += angleinc
  49.         var u = amplitude*Math.sin(angle*Math.PI/180)
  50.         var x = centerX + u*Math.cos(slantangle)
  51.         var y = centerY - u*Math.sin(slantangle)
  52.         this.moveTo(x,y)
  53.         this.onGlide()
  54.         if (this.glideActive) setTimeout(this.obj+'.glide('+type+','+amplitude+','+angle+','+endangle+','+centerX+','+centerY+','+slantangle+','+endx+','+endy+','+distx+','+disty+','+angleinc+','+speed+',\''+fn+'\')',speed)
  55.         else this.onGlideEnd()
  56.     }
  57.     else {
  58.         if (type==1) this.glide(0,amplitude,-90,0,this.x+distx/2,this.y+disty/2,slantangle,endx,endy,distx,disty,angleinc,speed,fn)
  59.         else {
  60.             this.glideActive = false
  61.             this.moveTo(endx,endy)
  62.             this.onGlide()
  63.             this.onGlideEnd()
  64.             eval(fn)
  65.         }
  66.     }
  67. }
  68. DynLayerGlideInit = new Function()
  69. DynLayer.prototype.glideInit = new Function()
  70. DynLayer.prototype.glideTo = DynLayerGlideTo
  71. DynLayer.prototype.glideBy = DynLayerGlideBy
  72. DynLayer.prototype.glideStart = DynLayerGlideStart
  73. DynLayer.prototype.glide = DynLayerGlide
  74. DynLayer.prototype.onGlide = new Function()
  75. DynLayer.prototype.onGlideEnd = new Function()
  76.