The prototype of jigsaw puzzle--Segmentation of beautiful pictures
Last Update:2017-02-28
Source: Internet
Author: User
When you are bored, you have to split the beauty! [From hate original ==> boring + disorderly]
Can divide a picture into several parts, the number of copies is decided freely by the input number. Automatically randomly disturb the position after segmentation, can drag to, drag to the correct position automatically adsorption, do not allow to throw move. Basically can be counted as the embryonic form of a jigsaw puzzle game. But I didn't want to do it all over here. Can use the right button to load their own pictures. Here's the boring code:
Import flash.net.FileReference;
Import Flash.display.BitmapData;
Import Flash.geom.Matrix;
/////////////////////////////////
var img_bmp:bitmapdata = new BitmapData (mc._width, mc._height);
var txt_fmt:textformat = new TextFormat ();
Txt_fmt.color = 0xff00ff;
Txt_fmt.size = 22;
Txt_fmt.font = "XXFarEastFont-Arial New Wei";
/////////////////////
for (var d:number = 2; d>0; d--) {
This.createtextfield ("Wh_txt" +d, 9000+d, d*100, 20, 50, 26);
this["Wh_txt" +d].setnewtextformat (TXT_FMT);
this["Wh_txt" +d].border = true;
this["Wh_txt" +d].input = true;
this["Wh_txt" +d].type = "input";
this["Wh_txt" +d].maxchars = 1;
this["Wh_txt" +d].restrict ("0-9");
this["Wh_txt" +d].background = true;
this["Wh_txt" +d].bordercolor = 0xff9900;
this["Wh_txt" +d].backgroundcolor = 0X33CCCC;
}
Selection.setfocus ("Wh_txt1");
//////////////////
wh_txt1.onchanged = Wh_txt2.onchanged=function () {
if (Wh_txt1.text = = "") {
Selection.setfocus ("Wh_txt1");
else if (Wh_txt2.text = "") {
Selection.setfocus ("Wh_txt2");
} else {
Fenge_func (Wh_txt1.text, Wh_txt2.text);
}
};
////////////////////////
var xwpos:number = 0;
var yhpos:number = 0;
function Fuwei_func () {
for (var d:number = xwpos-1; d>=0; d--) {
for (var c:number = yhpos-1; c>=0; c--) {
this["PIC_MC" +d+c].removemovieclip ();
}
}
}
//////
function Fenge_func (Xw:number, Yh:number) {
Fuwei_func ();
Xwpos = XW;
Yhpos = YH;
Img_bmp.draw (MC, New Matrix ());
var xy_array:array = new Array ();
var b_num:number = new number ();
////////////////
for (var d:number = xw-1; d>=0; d--) {
for (var c:number = yh-1; c>=0; c--) {
This.createemptymovieclip ("PIC_MC" +d+c, 200+d+ "" +c);
this["PIC_MC" +d+c].linestyle (1, 0xfff000, 100);
this["PIC_MC" +d+c].beginbitmapfill (img_bmp, New Matrix (), false);
this["PIC_MC" +d+c].moveto (D*stage.width/xw, C*STAGE.HEIGHT/YH);
this["PIC_MC" +d+c].lineto ((d+1) *stage.width/xw, C*STAGE.HEIGHT/YH);
this["PIC_MC" +d+c].lineto ((d+1) *stage.width/xw, (c+1) *stage.height/yh);
this["PIC_MC" +d+c].lineto (D*stage.width/xw, (c+1) *stage.height/yh);
this["PIC_MC" +d+c].lineto (D*stage.width/xw, C*STAGE.HEIGHT/YH);
this["PIC_MC" +d+c].endfill ();
this["PIC_MC" +d+c].obj = new Object ();
this["PIC_MC" +d+c].obj = this["PIC_MC" +d+c].getbounds (_root);
this["PIC_MC" +d+c].xpos = this["PIC_MC" +d+c].obj.xmin;
this["PIC_MC" +d+c].ypos = this["PIC_MC" +d+c].obj.ymin;
////////////////
var xy2_array:array = new Array ();
Xy2_array.push (this["PIC_MC" +d+c].obj.xmin, this["PIC_MC" +d+c].obj.ymin);
Xy_array.push (Xy2_array);
this["PIC_MC" +d+c].id = d+ "" +C;
//////////////////
this["PIC_MC" +d+c].onpress = function () {
B_num = this.id;
This.swapdepths (This._parent.getnexthighestdepth ());
This.startdrag ();
};
}
}
////////////////
for (var d:number = xw-1; d>=0; d--) {
for (var c:number = yh-1; c>=0; c--) {
num = Math.floor (math.random () *xy_array.length);
this["PIC_MC" +d+c]._x = xy_array[num][0]-this["PIC_MC" +D+C].XPOS;
this["PIC_MC" +d+c]._y = xy_array[num][1]-this["PIC_MC" +D+C].YPOS;
Xy_array.splice (num, 1);
}
}
//////////////////
OnMouseUp = function () {
Stopdrag ();
if (this["PIC_MC" +b_num].hittest (this["PIC_MC" +b_num].xpos+this["PIC_MC" +b_num]._width/2, this["PIC_MC" +b_num]. ypos+this["PIC_MC" +B_NUM]._HEIGHT/2)) {
this["PIC_MC" +b_num]._x = 0;
this["PIC_MC" +b_num]._y = 0;
this["PIC_MC" +b_num].swapdepths (-this["PIC_MC" +b_num].getdepth ());
this["PIC_MC" +b_num].enabled = false;
}
};
////////////
Mc._visible = false;
}
/////////////////////////////
var listener:object = new Object ();
////////
var loadpic:moviecliploader = new Moviecliploader ();
Listener.onloadinit = function (target:movieclip) {
Target._width = Stage.width;
Target._height = Stage.height;
Fuwei_func ();
Wh_txt1.text = "";
Wh_txt2.text = "";
Selection.setfocus ("Wh_txt1");
};
Loadpic.addlistener (listener);
/////////////////
var fileref:filereference = new Filereference ();
var alltypes:array = [];
var browse type: Object = new Object ();
Browse type. Description = "Browse type (*.jpg)";
Browse type. Extension = "*.jpg";
Alltypes.push (browse type);
Listener.onselect = function (file:filereference) {
Loadpic.loadclip ("/" +file.name, MC);
};
Fileref.addlistener (listener);
/////////////////////////
var pic_menu:contextmenu = new ContextMenu ();
function Browse_func () {
Fileref.browse (alltypes);
}
Pic_menu.hidebuiltinitems ();
var loadpic_menu:contextmenuitem = new Contextmenuitem ("Load a picture", browse_func);
Pic_menu.customItems.push (Loadpic_menu);
_root.menu = Pic_menu;
SWF. FLA Downloads:
split picture. RAR