Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
20 | reyssat | 1 | /* |
2 | DynAPI Distribution |
||
3 | CircleAnimation Class |
||
4 | |||
5 | The DynAPI Distribution is distributed under the terms of the GNU LGPL license. |
||
6 | |||
7 | requires: dynapi.functions.Math,dynapi.fx.Thread |
||
8 | */ |
||
9 | |||
10 | function CircleAnimation(dlyr) { |
||
11 | this.Thread = Thread; |
||
12 | this.Thread(dlyr); |
||
13 | |||
14 | this.offsetX = 0; |
||
15 | this.offsetY = 0; |
||
16 | this.playing = false; |
||
17 | this.radius = 100; |
||
18 | this.angle = 0; |
||
19 | this.setAngleIncrement(10); |
||
20 | }; |
||
21 | var p = dynapi.setPrototype('CircleAnimation','Thread'); |
||
22 | p.setRadius = function (r) { |
||
23 | this.hradius = this.vradius = r; |
||
24 | }; |
||
25 | p.setHRadius = function (r) { |
||
26 | this.hradius = r; |
||
27 | }; |
||
28 | p.setVRadius = function (r) { |
||
29 | this.vradius = r; |
||
30 | }; |
||
31 | p.setAngle = function (a) { |
||
32 | this.angle = dynapi.functions.degreeToRadian(a); |
||
33 | }; |
||
34 | p.setAngleIncrement = function (inc) { |
||
35 | this.angleinc = dynapi.functions.degreeToRadian(inc); |
||
36 | }; |
||
37 | p.playAnimation = function () { |
||
38 | this.playing = true; |
||
39 | if (this.dlyr!=null) { |
||
40 | this.offsetX = this.hradius*Math.cos(this.angle); |
||
41 | this.offsetY = -this.vradius*Math.sin(this.angle); |
||
42 | this.baseX = this.dlyr.x-this.offsetX; |
||
43 | this.baseY = this.dlyr.y+this.offsetY; |
||
44 | this.dlyr.invokeEvent("circlestart"); |
||
45 | } |
||
46 | this.start(); |
||
47 | }; |
||
48 | p.stopAnimation = function () { |
||
49 | this.playing = false; |
||
50 | this.stop(); |
||
51 | if (this.dlyr!=null) this.dlyr.invokeEvent("circlestop"); |
||
52 | }; |
||
53 | p.run = function () { |
||
54 | if (!this.playing || this.dlyr==null) return; |
||
55 | this.angle += this.angleinc; |
||
56 | this.offsetX = this.hradius*Math.cos(this.angle); |
||
57 | this.offsetY = -this.vradius*Math.sin(this.angle); |
||
58 | |||
59 | if (this.dlyr!=null) { |
||
60 | this.dlyr.invokeEvent("circlerun"); |
||
61 | this.dlyr.setLocation(this.baseX+this.offsetX,this.baseY+this.offsetY); |
||
62 | } |
||
63 | }; |
||
64 | p.reset = function () { |
||
65 | this.angle = this.offsetX = this.offsetY = 0; |
||
66 | }; |
||
67 | p.generatePath = function(centerX,centerY) { |
||
68 | if (centerX==null) centerX = this.dlyr!=null? this.dlyr.x : 0; |
||
69 | if (centerY==null) centerY = this.dlyr!=null? this.dlyr.y : 0; |
||
70 | var path = []; |
||
71 | var i = 0; |
||
72 | /* for (var a=this.angle;a<=this.angle+Math.PI*2;a+=this.angleinc) { |
||
73 | path[i] = Math.round(centerX + this.hradius*Math.cos(a)); |
||
74 | path[i+1] = Math.round(centerY - this.vradius*Math.sin(a)); |
||
75 | i+=2; |
||
76 | }*/ |
||
77 | |||
78 | if (this.angleinc>0) |
||
79 | for (var a=this.angle;a<=this.angle+Math.PI*2;a+=this.angleinc) { |
||
80 | path[i] = Math.round(centerX + this.hradius*Math.cos(a)); |
||
81 | path[i+1] = Math.round(centerY - this.vradius*Math.sin(a)); |
||
82 | i+=2; |
||
83 | } |
||
84 | else |
||
85 | for (var a=this.angle;a>=this.angle-Math.PI*2;a+=this.angleinc) { |
||
86 | path[i] = Math.round(centerX + this.hradius*Math.cos(a)); |
||
87 | path[i+1] = Math.round(centerY - this.vradius*Math.sin(a)); |
||
88 | i+=2; |
||
89 | } |
||
90 | return path; |
||
91 | }; |