root/as2/Emzah/src/com/emzah/display/Shape.as

リビジョン 306, 14.0 kB (コミッタ: gen, コミット時期: 8 ヶ月 前)

ToolT(C)ips AS 2.0

  • svn:executable 属性の設定値: *
Line 
1 /*======================================================================*//**
2 * com.emzah.display.Shape  Class for ActionScript 2.0
3 *
4 * @author       Copyright (c) 2007 gen:emzah.com
5 * @version      0.1
6 *
7 * @link         http://emzah.com
8 * @link         http://blog.emzah.com
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
19 * either express or implied. See the License for the specific language
20 * governing permissions and limitations under the License.
21 *//*=======================================================================*/
22
23 /**
24  * Shape はプリミティブな図形を描くためのクラスです
25  * @data 2007/05/21
26  * @usage
27  * <code>
28  * GenShape.box(mc,xp,yp,wp,hp,lp,lcp,pc);
29  * </code>
30  */
31  
32 class com.emzah.display.Shape {
33
34     /**
35      * ラインを描く
36      *
37      * mc 描画するMovieClip
38      * x1 開始点X値
39      * y1 開始点Y値
40      * x2 終止点X値
41      * y2 終止点Y値
42      * line[1] 線幅
43      * line[0] 線色「0xFFFFFF」
44      */
45     public static function line(mc :MovieClip,
46                                 x1 :Number,
47                                 y1 :Number,
48                                 x2 :Number,
49                                 y2 :Number,
50                                 line:Array) : Void {
51         if(line[1] == undefined){line[1] = 1;}
52         if(line[0] == undefined){line[0] = 0x000000;}
53         if (line[1] == 0) {
54             mc.lineStyle();
55         }else{
56             mc.lineStyle(line[1],line[0]);
57         }
58         mc.beginFill();
59         mc.moveTo(x1, y1);
60         mc.lineTo(x2, y2);
61         mc.lineTo(x1, y1);
62         mc.endFill();
63     }
64
65     /**
66      * 四角のボックスを描く
67      *
68      * mc 描画するMovieClip
69      * x1 四角の左上のX値
70      * y1 四角の左上のY値
71      * width 横幅
72      * hight 高さ
73      * line 線色「0xFFFFFF」,線幅「1] :Array
74      * base 塗りつぶす色,アルファ :Array
75      *        単色 (color,alpha)
76      *        グラデ色 (color,alpha)
77      */
78     public static function box(mc:MovieClip,
79                                x1 :Number,
80                                y1 :Number,
81                                width :Number,
82                                hight :Number,
83                                line :Array,
84                                base :Array) : Void {
85                                
86         if(line[1] == undefined){line[1] = 1 }                       
87         if(line[0] == undefined){line[0] = 0x000000;}
88
89         if (line[0] == 0) {
90             mc.lineStyle();
91         }else{
92             mc.lineStyle(line[1],line[0]);
93         }
94         //beginFill(色, アルファ);
95         //beginGradientFill(タイプ,色配列,アルファ配列,カラー分布配列、変換マトリックス);
96         if(base[0] == undefined || base[0]  == null){
97                 mc.beginFill();
98         }else{
99                 if(base.length > 2){
100                         mc.beginGradientFill(base[0],base[1],base[2],base[3],base[4]);
101                 }else{
102                
103                         mc.beginFill(Number(base[0]),Number(base[1]));
104                 }
105
106         }
107        
108         mc.moveTo(x1, y1);
109         mc.lineTo(x1 + width, y1);
110         mc.lineTo(x1 + width, y1 + hight);
111         mc.lineTo(x1, y1 + hight);
112         mc.lineTo(x1, y1);
113         mc.endFill();
114     }
115
116     /**
117      * 放射状(イチョウ型)の図形を描く
118      *
119      * ※角度はXの正の数軸が0度でしたに向かって+です。
120      *
121      * mc 描画するMovieClip
122      * nX 円の中心点X
123      * nY 円の中心点Y
124      * nR 半径
125      * nStD 開始角度(度数)
126      * nInD 扇角度(度数)
127      * line[1] 線幅
128      * line[0] 線色「0xFFFFFF」
129      * base 塗りつぶす色
130      *        単色 (color,alpha)
131      *        グラデ色 (color,alpha)
132      */
133     public static function ginkgoCircle(mc:MovieClip,
134                                         nX:Number,
135                                         nY:Number,
136                                         nR:Number,
137                                         nStD :Number,
138                                         nInD :Number,
139                                         line :Array,
140                                         base :Array) : Void {
141         if(line[1] == undefined){line[1] = 1;}
142         if(line[0] == undefined){line[0] = 0x000000;}
143         if (line[1] == 0) {
144             mc.lineStyle();
145         }else{
146             mc.lineStyle(line[1],line[0]);
147         }
148         //beginFill(色, アルファ);
149         //beginGradientFill(タイプ,色配列,アルファ配列,カラー分布配列、変換マトリックス);
150
151         if(base == undefined || base == null){
152                 mc.beginFill();
153         }else{
154
155                 if(base.length > 2){
156                         mc.beginGradientFill(base[0],base[1],base[2],base[3],base[4]);
157                 }else{
158                         mc.beginFill(Number(base[0]),Number(base[1]));
159                 }
160
161         }
162         /*
163          *segmentDegrees 曲線の精度のための区切りの角度(省略時:45度)
164          * ただし曲線の精度のため45度以上は円の弧がきれいにならない
165          * curveTo の仕様のため計算では非常に難しいようである。
166          */
167         var segmentDegrees :Number = 45;
168
169         if(nInD <= segmentDegrees){
170             var pointlist :Array
171                 = __ginkgoCircleBitPoint(nX,nY,nR,nStD,nInD);
172             mc.moveTo(pointlist[0], pointlist[1]);
173             mc.lineTo(pointlist[2], pointlist[3]);
174             mc.curveTo(pointlist[6], pointlist[7],
175                        pointlist[4], pointlist[5]);
176             mc.lineTo(pointlist[0], pointlist[1]);
177         }else{
178             var segme :Number = Math.floor(nInD / segmentDegrees);
179             var amari :Number = nInD % segmentDegrees;
180             if(amari != 0){
181                 var pointlist :Array
182                     = __ginkgoCircleBitPoint(nX,nY,nR,nStD,amari);
183                 mc.moveTo(pointlist[0], pointlist[1]);
184                 mc.lineTo(pointlist[2], pointlist[3]);
185                 mc.curveTo(pointlist[6], pointlist[7],
186                            pointlist[4], pointlist[5]);
187             };
188             var deg = amari;
189             for(var i=0;i<segme;i++){
190                 var pointlist :Array = __ginkgoCircleBitPoint
191                     (nX,nY,nR,
192                      nStD + deg + i * segmentDegrees,
193                      segmentDegrees);
194                 if(i == 0 && amari == 0){
195                     mc.moveTo(pointlist[0], pointlist[1]);
196                     mc.lineTo(pointlist[2], pointlist[3]);
197                 }
198                 mc.curveTo(pointlist[6], pointlist[7],
199                            pointlist[4], pointlist[5]);
200                 if(i == segme - 1){
201                     mc.lineTo(pointlist[0], pointlist[1]);
202                 }
203             }
204         }
205         mc.endFill();
206     }
207
208     /**
209      * 放射状に切られた円を描く
210      *
211      * 角度はXの正の数軸が0度でしたに向かって+です。
212      *
213      * nX 円の中心点X
214      * nY 円の中心点Y
215      * nR 半径
216      * nStD 開始角度(度数)
217      * nInD 扇角度(度数)
218      *
219      */
220     private static function __ginkgoCircleBitPoint(nX :Number,
221                                                    nY :Number,
222                                                    nR :Number,
223                                                    nStD :Number,
224                                                    nInD :Number) : Array {
225         //角度をラジアンに変換
226         var raStD = nStD * Math.PI / 180;
227         var raInD = nInD * Math.PI / 180;
228         // 中心から外周上に一番目に来る点
229         var nS1X :Number = nX + (nR * Math.cos(raStD));
230         var nS1Y :Number = nY + (nR * Math.sin(raStD));
231         // 中心に入る最後の外周上にある点
232         var nSLX :Number = nX + (nR * Math.cos(raStD + raInD));
233         var nSLY :Number = nY + (nR * Math.sin(raStD + raInD));
234         //コントロールポイント
235         var nCtlX :Number =  nSLX + nR * Math.tan(raInD/2)
236             * Math.cos(raStD + raInD - Math.PI/2);
237         var nCtlY :Number =  nSLY + nR * Math.tan(raInD/2)
238             * Math.sin(raStD + raInD - Math.PI/2);
239         return [nX,nY,nS1X,nS1Y,nSLX,nSLY,nCtlX,nCtlY];
240     }
241
242     /**
243      * 円
244      * まだ未完成
245      * target_mc
246      *
247      * nX 円の中心X軸
248      * nY 円の中心Y軸
249      * nR 円の
250      */
251     public static function circle(target_mc:MovieClip,
252                                   nX:Number,
253                                   nY:Number,
254                                   nR:Number,
255                                   line:Array,
256                                   base:Array):Void {
257     }
258    
259     /**
260      * 八角の図形
261      * target_mc
262      *
263      * 角値を1px等にすればアンチエイリアスをうけない角丸になります
264      *
265      * mc 描画するMovieClip
266      * x1 四角の左上のX値
267      * y1 四角の左上のY値
268      * width 横幅
269      * hight 高さ
270      * round 角
271      * line[1] 線幅
272      * line[0] 線色「0xFFFFFF」
273      * base 塗りつぶす色
274      *        単色 (color,alpha)
275      *        グラデ色 (color,alpha)
276      */
277     public static function octagonbox(mc:MovieClip,
278                                x1:Number,
279                                y1:Number,
280                                width:Number,
281                                hight:Number,
282                                round:Number,
283                                line:Array,
284                                base:Array) : Void {
285                                
286         if(line[1] == undefined){line[1] = 1;}
287         if(line[0] == undefined){line[0] = 0x000000;}
288         if (line[1] == 0) {
289             mc.lineStyle();
290         }else{
291             mc.lineStyle(line[1],line[0]);
292         }
293
294         //beginFill(色, アルファ);
295         //beginGradientFill(タイプ,色配列,アルファ配列,カラー分布配列、変換マトリックス);
296
297         if(base == undefined || base == null){
298                 mc.beginFill();
299         }else{
300
301                 if(base.length > 2){
302                         mc.beginGradientFill(base[0],base[1],base[2],base[3],base[4]);
303                 }else{
304                         mc.beginFill(Number(base[0]),Number(base[1]));
305                 }
306
307         }
308         //補正
309         if(round == undefined || isNaN(round) == true){
310                 round = 0;
311         }
312         if(0 > (width - round) || 0 > (hight - round) ){
313                 round = 0;
314         }
315
316         if(width > 0){
317                     mc.moveTo(x1 + round, y1);//1
318                 mc.lineTo(x1 + width - round, y1);//2
319                 mc.lineTo(x1 + width, y1 + round);//3
320                
321                 mc.lineTo(x1 + width, y1 + hight - round);//4
322                 mc.lineTo(x1 + width - round, y1 + hight);//5
323                
324                 mc.lineTo(x1 + round, y1 + hight);//6
325                 mc.lineTo(x1 , y1 + hight - round);//7
326                
327                 mc.lineTo(x1 , y1 + round);//8
328                
329                 mc.lineTo(x1 + round, y1);//9
330                 mc.endFill();
331                
332         }else{
333                 mc.moveTo(x1, y1);
334                 mc.lineTo(x1 + 1, y1);
335                 mc.lineTo(x1 + 1, y1 + hight);
336                 mc.lineTo(x1, y1 + hight);
337                 mc.lineTo(x1, y1);
338                 mc.endFill();
339         }
340
341
342     }
343     /**
344      * 正角丸の図形(角の縦横サイズが同じ)
345      * target_mc
346      *
347      * まだ途中
348      *
349      * mc 描画するMovieClip
350      * x1 四角の左上のX値
351      * y1 四角の左上のY値
352      * width 横幅
353      * hight 高さ
354      * round 角 右回り[1,2,3,4]
355      * line[1] 線幅
356      * line[0] 線色「0xFFFFFF」
357      * base 塗りつぶす色
358      *        単色 (color,alpha)
359      *        グラデ色 (color,alpha)
360      */   
361     public static function roundbox(mc:MovieClip,
362                                x1:Number,
363                                y1:Number,
364                                width:Number,
365                                hight:Number,
366                                round:Array,
367                                line:Array,
368                                base:Array) : Void {
369    
370         if(line[1] == undefined){line[1] = 1;}
371         if(line[0] == undefined){line[0] = 0x000000;}
372         if (line[1] == 0) {
373             mc.lineStyle();
374         }else{
375             mc.lineStyle(line[1],line[0]);
376         }
377        
378         //beginFill(色, アルファ);
379         //beginGradientFill(タイプ,色配列,アルファ配列,カラー分布配列、変換マトリックス);
380         if(base == undefined || base == null){
381                 mc.beginFill();
382         }else{
383                 if(base.length > 2){
384                         mc.beginGradientFill(base[0],base[1],base[2],base[3],base[4]);
385                 }else{
386                         mc.beginFill(Number(base[0]),Number(base[1]));
387                 }
388         }
389         //補正
390         if(round == undefined || round.length < 0 ){
391                 var round:Array = [0,0,0,0];
392         }
393
394         if(0 > (width - round[0]) || 0 > (hight - round[0]) ){
395                 var round:Array = [0,0,0,0];
396         }
397                
398         if(width  > 0){
399                 if(width - (round[2]*2) < 0){
400                         round[2] = width;
401                 }
402
403                     mc.moveTo(x1 + round[0], y1);//1
404
405                 mc.lineTo(x1 + width - round[2], y1);//2
406                 mc.curveTo(x1 + width , y1  ,x1 + width ,y1 + round[3]);
407                 mc.lineTo(x1 + width, y1 + round[3] );//3
408                
409                 mc.lineTo(x1 + width, y1 +  hight  - round[3] );//4
410                
411                 mc.curveTo(x1 + width , y1 + hight, x1 + width - round[2] , y1 + hight);
412                 mc.lineTo(x1 + width - round[2], y1 + hight);//5
413                
414                 mc.lineTo(x1 + round[0], y1 + hight );//6
415                
416                 mc.curveTo(x1, y1+ hight, x1,y1+hight- round[1]);
417                 mc.lineTo(x1 , y1 + hight - round[1]); //7
418                
419                 mc.lineTo(x1 , y1 + round[1]); //8
420                 mc.curveTo(x1, y1, x1 + round[0],y1);
421                
422                 mc.lineTo(x1 + round[0], y1);//9
423                 mc.endFill();
424        
425        
426         }else{
427                 mc.moveTo(x1, y1);
428                 mc.lineTo(x1 + 1, y1);
429                 mc.lineTo(x1 + 1, y1 + hight);
430                 mc.lineTo(x1, y1 + hight);
431                 mc.lineTo(x1, y1);
432                 mc.endFill();
433         }
434      }
435      
436 }
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。