flash on 2010-1-21
♥0 |
Line 84 |
Modified 2010-01-21 16:53:08 |
MIT License
archived:2017-03-20 01:46:02
ActionScript3 source code
/**
* Copyright nausicaa ( http://wonderfl.net/user/nausicaa )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/20rL
*/
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Point;
import caurina.transitions.Tweener;
[swf(width="465",height="465",backgroundColor="0x0")]
public class Contraction extends Sprite {
private var msgString:String;
private var typoWidth:Number;
private var typoHeight:Number;
private var pixelSprite:Array = new Array();
public function Contraction() {
i:nitMotion=new initMotion("aaa","0x0",18,"_sans");
}
// "表示文字列", "フォントカラー", フォントサイズ, "フォントタイプ"
public function initMotion(msg:String, fontColor:String, fontSize:Number, fontType:String, chrMargin:Number) {
msgString = msg;
var typoFmt:TextFormat = new TextFormat();
typoFmt.color = Number("0x" + fontColor);
typoFmt.size = fontSize;
typoFmt.font = fontType;
var TypoChrTmp:Sprite = new Sprite();
var MotionTypo = new TextField();
MotionTypo.autoSize = TextFieldAutoSize.LEFT;
MotionTypo.text = msg;
MotionTypo.embedFonts = true;
MotionTypo.setTextFormat(typoFmt);
TypoChrTmp.addChild(MotionTypo);
TypoChrTmp.y = 50;
addChild(TypoChrTmp);
var TypoChr:Sprite = new Sprite();
var myBitmapData:BitmapData = new BitmapData(TypoChrTmp.width, TypoChrTmp.height, true, 0x00000000);
myBitmapData.draw(TypoChrTmp);
var bmp:Bitmap = new Bitmap(myBitmapData);
TypoChr.addChild(bmp);
addChild(TypoChr);
TypoChr.y = 80;
typoWidth = TypoChr.width;
typoHeight = TypoChr.height;
trace(typoWidth);
trace(typoHeight);
for(var i = 0; i < typoWidth; i++) {
for(var j = 0; j < typoHeight; j++) {
var myPixelData:BitmapData = new BitmapData(1, 1, true, 0x00000000);
myPixelData.copyPixels(myBitmapData, new Rectangle(i, j, i + 1, j+ 1), new Point(0, 0));
if(myPixelData.getPixel32(0, 0) != 0) {
var PixelTypo:Sprite = new Sprite();
var PixelBmp:Bitmap = new Bitmap(myPixelData);
PixelTypo.addChild(PixelBmp);
addChild(PixelTypo);
PixelTypo.x = randRange(i - 40, i + 40);
PixelTypo.y = randRange(j - 40, j + 40);
PixelTypo.alpha = 0;
targetX[i] = i;
targetY[j] = j;
pixelSprite.push([i, j, PixelTypo]);
}else {
myPixelData.dispose();
targetX[i] = -1;
targetY[j] = -1;
}
}
}
//TypoChrTmp.removeMovieClip();
//TypoChr.removeMovieClip();
motion(1.5, 1.5);
}
public function motion(motionDelay:Number, motionTime:Number) {
for (var i:String in pixelSprite) {
Tweener.addTween(pixelSprite[i][2], {x:pixelSprite[i][0], y:pixelSprite[i][1], alpha:1, transition:"easeincubic", time:motionTime, delay: randRangeNoFloor(0, motionDelay)});
}
}
private function randRange(min:Number, max:Number):Number {
var randomNum:Number = Math.floor(Math.random() * (max - min + 1)) + min;
return randomNum;
}
private function randRangeNoFloor(min:Number, max:Number):Number {
var randomNum:Number = Math.random() * (max - min + 1) + min;
return randomNum;
}
}
}