root/as3/ColorLog/trunk/examples/TestColorLog3.as

リビジョン 2610, 2.6 kB (コミッタ: saqoosha, コミット時期: 3 年 前)

flashlog.txt をカラーにするライブラリ。

Line 
1 package {
2        
3         import com.trick7.utils.TeraClock;
4        
5         import flash.display.Bitmap;
6         import flash.display.BitmapData;
7         import flash.display.Sprite;
8         import flash.events.Event;
9        
10         import net.saqoosha.colorlog.ColorLog;
11         import net.saqoosha.colorlog.SGR;
12        
13         [SWF(width=500, height=500, backgroundColor=0x0, frameRate=15)]
14
15         public class TestColorLog3 extends Sprite {
16                
17                 private var _canvas:BitmapData;
18                 private var _clock:TeraClock;
19                
20                 public function TestColorLog3() {
21                         ColorLog.hideCursor();
22                        
23                         this._canvas = new BitmapData(100, 50, false, 0);
24                         var b:Bitmap = new Bitmap(this._canvas);
25                         b.scaleX = 5;
26                         b.scaleY = 10;
27                         this.addChild(b);
28                        
29                         this._clock = new TeraClock();
30                         this._clock.addEventListener(TeraClock.SECONDS_CHANGED, this._update);
31                 }
32                
33                 private function _update(e:Event):void {
34                         ColorLog.clearScreen();
35                         this._canvas.fillRect(this._canvas.rect, 0x0);
36                         this._canvas.lock();
37                        
38                         var a:Number;
39                         var x:int;
40                         var y:int;
41                        
42                         // seconds
43                         ColorLog.setColor(SGR.BG_BRIGHT_YELLOW);
44                         a = (this._clock.secondsDegree - 90) * Math.PI / 180;
45                         x = Math.round(Math.cos(a) * 40);
46                         y = Math.round(Math.sin(a) * 20);
47                         this.drawLine(50, 25, 50 + x, 25 + y);
48                        
49                         // minutes
50                         ColorLog.setColor(SGR.BG_BRIGHT_MAGENTA);
51                         a = (this._clock.minutesDegree - 90) * Math.PI / 180;
52                         x = Math.round(Math.cos(a) * 30);
53                         y = Math.round(Math.sin(a) * 15);
54                         this.drawLine(50, 25, 50 + x, 25 + y);
55                        
56                         // hours
57                         ColorLog.setColor(SGR.BG_BRIGHT_CYAN);
58                         a = (this._clock.hoursDegree - 90) * Math.PI / 180;
59                         x = Math.round(Math.cos(a) * 20);
60                         y = Math.round(Math.sin(a) * 10);
61                         this.drawLine(50, 25, 50 + x, 25 + y);
62                        
63                         this._canvas.unlock();
64                         ColorLog.flush();
65                 }
66                
67                 private function drawLine(x0:int, y0:int, x1:int, y1:int):void {
68                         var steep:Boolean = Math.abs(y1 - y0) > Math.abs(x1 - x0);
69                         var tmp:int;
70                         if (steep) {
71                                 tmp = x0;
72                                 x0 = y0;
73                                 y0 = tmp;
74                                 tmp = x1;
75                                 x1 = y1;
76                                 y1 = tmp;
77                         }
78                         if (x0 > x1) {
79                                 tmp = x0;
80                                 x0 = x1;
81                                 x1 = tmp;
82                                 tmp = y0;
83                                 y0 = y1;
84                                 y1 = tmp;
85                         }
86                         var deltax:int = x1 - x0;
87                         var deltay:int = Math.abs(y1 - y0);
88                         var error:int = deltax / 2;
89                         var ystep:int;
90                         var y:int = y0;
91                         if (y0 < y1) {
92                                 ystep = 1;
93                         } else {
94                                 ystep = -1;
95                         }
96                         for (var x:int = x0; x <= x1; x++) {
97                                 if (steep) {
98                                         this._canvas.setPixel(y, x, 0xffffff);
99                                         ColorLog.moveTo(x, y);
100                                         ColorLog.out(' ');
101                                 } else {
102                                         this._canvas.setPixel(x, y, 0xffffff);
103                                         ColorLog.moveTo(y, x);
104                                         ColorLog.out(' ');
105                                 }
106                                 error = error - deltay;
107                                 if (error < 0) {
108                                         y = y + ystep;
109                                         error = error + deltax;
110                                 }
111                         }
112                 }
113         }
114 }
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。