#8 7セグ(flash on 2009-8-23)
7セグ
*
* ビットマスクとかを体が欲したので作成。
* 効率は良くないわ、分かりにくいわ……
* @author krogue
♥0 |
Line 58 |
Modified 2009-08-23 18:44:35 |
MIT License
archived:2017-03-20 15:25:02
ActionScript3 source code
/**
* Copyright krogue ( http://wonderfl.net/user/krogue )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/403K
*/
/**
* 7セグ
*
* ビットマスクとかを体が欲したので作成。
* 効率は良くないわ、分かりにくいわ……
* @author krogue
*/
package {
import flash.display.Sprite;
import flash.display.Shape;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class SevenSegment extends Sprite {
private const table:Array = [0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x27, 0x7F, 0x6F];
public function SevenSegment() {
var s:Shape = addChild(new Shape()) as Shape;
s.x = 50;
s.y = 50;
var size:int = 50;
var i:int = 0;
var timer:Timer = new Timer(100);
timer.addEventListener(TimerEvent.TIMER, function(event:TimerEvent):void {
if (i == 10) {
i = 0;
}
display(s, i, size);
i++;
});
timer.start();
}
private function display(s:Shape, n:int, l:int):void {
var m:int = table[n];
s.graphics.clear();
s.graphics.lineStyle(10, 0x000000);
if ((m & 0x01) != 0) {
s.graphics.moveTo(0, 0);
s.graphics.lineTo(l, 0);
}
if ((m & 0x02) != 0) {
s.graphics.moveTo(l, 0);
s.graphics.lineTo(l, l);
}
if ((m & 0x04) != 0) {
s.graphics.moveTo(l, l);
s.graphics.lineTo(l, 2 * l);
}
if ((m & 0x08) != 0) {
s.graphics.moveTo(l, 2 * l);
s.graphics.lineTo(0, 2 * l);
}
if ((m & 0x10) != 0) {
s.graphics.moveTo(0, 2 * l);
s.graphics.lineTo(0, l);
}
if ((m & 0x20) != 0) {
s.graphics.moveTo(0, l);
s.graphics.lineTo(0, 0);
}
if ((m & 0x40) != 0) {
s.graphics.moveTo(0, l);
s.graphics.lineTo(l, l);
}
}
}
}