Functions and examples of character dot-dot character lattice

Source: Internet
Author: User
Tags date
Functions | example

When you write a program, suddenly think of the method, feel simple and easy to use, a utility function, so sent out, the following is this function:

function Txttoposarr (dt:string, W:number, H:number): Array {
/*
* Author:fanflash (www.fanflash.cn)
* DATE:2007-5-14
* Info: Convert text to dot matrix
*-----Parameters-------
* DT: Characters to be converted to strings
* W: two-point horizontal space between pixel points
* H: Two-point longitudinal axis spacing between pixel points
* Note: If you want to increase the density of the dots, you can set the text size larger
*/
Check the availability of parameters
W = (w!= undefined)? w:0;
h = (h!= undefined)? h:0;
var T_txt:textfield = _root.createtextfield ("Txttopostxt", _root.getnexthighestdepth (),-500,-500, 100, 100);
Set text
T_txt.autosize = true;
T_txt.multiline = false;
T_txt.wordwrap = false;
T_txt.selectable = false;
T_txt.text = DT;
T_txt._visible = false;
Generate picture data
var txtBmp:flash.display.BitmapData = new Flash.display.BitmapData (T_txt._width, T_txt._height, False, 0XFFFFFF);
Txtbmp.draw (T_txt);
Create an array of literals
var t_arr:array = new Array ();
var Pix:number;
for (var y = 0; y<t_txt._height; y++) {
for (var x = 0; x<t_txt._width; x + +) {
if (Txtbmp.getpixel (x, y)!= 0xffffff) {
T_arr.push ({x:x+x*w, y:y+y*h});
}
}
}
Delete the text you created
T_txt.removetextfield ();
Txtbmp.dispose ();
return T_arr;
}

The principle is very simple, using the bitmap class to select the black point, because the white is the background, so as long as the black point, then are strokes and lines. Here is a sample program with this function:



SOURCE program:

Welcome to Www.fanflash.cn
System.usecodepage = true;
Stage.scalemode = "Noscale";
Stage.showmenu = false;
function Main () {
var T:array;
ok_btn.onpress = function () {
REMOVEMC ();
t = Txttoposarr (Input_txt.text, 4, 4);
for (var i in t) {
CREATEMC (T.x, T.Y);
}
};
}
function Txttoposarr (dt:string, W:number, H:number): Array {
/*
* Author:fanflash (www.fanflash.cn)
* DATE:2007-5-14
* Info: Convert text to dot matrix
*-----Parameters-------
* DT: Characters to be converted to strings
* W: two-point horizontal space between pixel points
* H: Two-point longitudinal axis spacing between pixel points
* Note: If you want to increase the density of the dots, you can set the text size larger
*/
Check the availability of parameters
W = (w!= undefined)? w:0;
h = (h!= undefined)? h:0;
var T_txt:textfield = _root.createtextfield ("Txttopostxt", _root.getnexthighestdepth (),-500,-500, 100, 100);
Set text
T_txt.autosize = true;
T_txt.multiline = false;
T_txt.wordwrap = false;
T_txt.selectable = false;
T_txt.text = DT;
T_txt._visible = false;
Generate picture data
var txtBmp:flash.display.BitmapData = new Flash.display.BitmapData (T_txt._width, T_txt._height, False, 0XFFFFFF);
Txtbmp.draw (T_txt);
Create an array of literals
var t_arr:array = new Array ();
var Pix:number;
for (var y = 0; y<t_txt._height; y++) {
for (var x = 0; x<t_txt._width; x + +) {
if (Txtbmp.getpixel (x, y)!= 0xffffff) {
T_arr.push ({x:x+x*w, y:y+y*h});
}
}
}
Delete the text you created
T_txt.removetextfield ();
Txtbmp.dispose ();
return T_arr;
}
Import Flash.filters.GlowFilter;
Import Mx.transitions.Tween;
Import mx.transitions.easing.*;
function Createmc (X:number, Y:number) {
Point Chen Coordinate offset
x + 50;
Y + 150;
Tween Animation style
var tweenfun:function = back.easeout;
var d:number = _root.getnexthighestdepth ();
var _mc:movieclip = _root.attachmovie ("dot", "dot" +d, D);
_mc.cacheasbitmap = true;
_mc.filters = [New Glowfilter (Math.Round (Math.random () *0xffffff))];
_mc.filters = [New Glowfilter (0XFFFFFF)];
_mc._x = Math.random () *stage.width;
_mc._y = Math.random () *stage.height;
var xt:number = 1+math.round (Math.random () *2);
var yt:number = 1+math.round (Math.random () *2);
New Tween (_MC, "_x", Tweenfun, _mc._x, X, XT, True);
New Tween (_MC, "_y", Tweenfun, _mc._y, Y, YT, true);
}
function Removemc () {
For (var m in _root) {
if (_root[m]._name.substr (0, 3) = = "Dot") {
_root[m].removemovieclip ();
}
}
}
Main ();

source program Download: Click here to download the source file



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.