Write html5--eighth, image processing + particle effects using the syntax of ActionScript

Source: Internet
Author: User
Tags addchild

This paper is the official HTML5 training course for Brother Lian it educational institution, mainly introduces: writing html5--eighth, image processing + particle effect with the grammar of ActionScript

Eighth, image processing + particle effects


Using the syntax of ActionScript to write HTML5 series development to now, should be able to make something, the following first to study the various effects of the film
Preview various effects look




Effects and code see here, see the effect of the download support HTML5 browser

Http://fsanguo.comoj.com/html5/jstoas07/index.html

Added March 13, 2013

This series of articles is written early, and the methods summarized in this series are now encapsulated in the Lufylegend.js engine.

Download link for lufylegend.js engine http://lufylegend.com/lufylegend

Since the engine was encapsulated, some of the previous code was adjusted, some properties were deleted, and the following is the same particle effect I developed with the new engine

[HTML]View PlainCopy
  1. <! DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <Meta charset="UTF-8">
  5. <title> Particle effects </title>
  6. </head>
  7. <body>
  8. <div id="mylegend">loading ... </div>
  9. <script type="Text/javascript" src="Http://lufylegend.com/js/lufylegend-1.6.1.min.js" ></script>
  10. <script type="Text/javascript">
  11. Init (max, "Mylegend", 300,300,main);
  12. var imgdata = [{name: ' img ', path: ' Http://lufylegend.com/images/face.jpg '}];
  13. var imglist;
  14. var mainbitmap,mainbitmapheight;
  15. var windlist = [];
  16. var Backlayer;
  17. function Main () {
  18. Lloadmanage.load (
  19. Imgdata,
  20. function (Progress) {},
  21. Loadover
  22. );
  23. }
  24. function Loadover (Result) {
  25. imglist = result;
  26. Add a Lsprite Object
  27. Backlayer = new Lsprite ();
  28. AddChild (Backlayer);
  29. Add a Lbitmap object to display a large picture and load the picture onto the Backlayer object
  30. Mainbitmap = new Lbitmap (New Lbitmapdata (imglist["img"));
  31. Backlayer.addchild (MAINBITMAP);
  32. Save the initial height of the Lbitmap object
  33. mainbitmapheight = mainbitmap.getheight ();
  34. Loads a Lsprite object, that is, the timeline
  35. Backlayer.addeventlistener (Levent.enter_frame,onframe);
  36. }
  37. function Onframe () {
  38. var bitmapdata;
  39. var bitmap;
  40. var addy,addx;
  41. if (Mainbitmap) {
  42. The SetProperties function of the Lbitmapdata object is modified to modify the range of the Lbitmapdata object to display the picture, each time it is run, the display range moves down addy units from the start position in the y-axis direction.
  43. AddY = 3;
  44. Mainbitmap.y + = AddY;
  45. if (mainbitmap.y >= mainbitmapheight) {
  46. AddY + = MAINBITMAPHEIGHT-MAINBITMAP.Y;
  47. mainbitmap.y = mainbitmapheight;
  48. Remove a Lbitmapdata object from Backlayer when it shows that the range of pictures has changed to 0
  49. Backlayer.removechild (MAINBITMAP);
  50. }else{
  51. MainBitmap.bitmapData.setProperties (0,mainbitmap.y,mainbitmap.getwidth (), (MAINBITMAPHEIGHT-MAINBITMAP.Y));
  52. }
  53. The following is the decomposition of a row of pictures, one row per run
  54. var arr = [];
  55. For (i=0;i<mainbitmap.getwidth (); i + = 3) {
  56. ADDX = 3;
  57. if (I+addx > Mainbitmap.getwidth ()) {
  58. ADDX = mainbitmap.getwidth ()-I;
  59. }
  60. By setting the display range of the Lbitmapdata object, the exploded small picture is obtained, and the exploded small image is pressed into the ARR array
  61. bitmapdata = new Lbitmapdata (imglist["img"],i,mainbitmap.y-addy,addx,addy);
  62. bitmap = new Lbitmap (BitmapData);
  63. bitmap.x = i;
  64. bitmap.y = Mainbitmap.y-addy;
  65. Backlayer.addchild (bitmap);
  66. Arr.push (bitmap);
  67. }
  68. if (mainbitmap.y >= mainbitmapheight)mainbitmap=null;
  69. Presses the exploded line of small pictures into the windlist array
  70. Windlist.push (arr);
  71. }
  72. Windrun ();
  73. }
  74. function Windrun () {
  75. var i,j,flag,ml=1;
  76. Loop windlist Each small picture in the array, randomly moving to the left, right, etc.
  77. For (i=0;i<windlist.length;i++) {
  78. if (Windlist[i]. length = = 0) {
  79. Windlist.splice (i,1);
  80. i--;
  81. Continue
  82. }
  83. For (j=0;j<windlist[i].length;j++) {
  84. if (Windlist[i][j]. i = = null) windlist[i][j]. i=1;
  85. flag = math.random ();
  86. if (flag < 0.3) {
  87. windlist[i][j].x + = ml*windlist[i][j].i;
  88. }else if (flag < 0.6) {
  89. windlist[i][j].x- = ml*windlist[i][j].i;
  90. }else{
  91. WINDLIST[I][J].Y- = ml*windlist[i][j].i;
  92. }
  93. Windlist[i][j].alpha- = 0.05;
  94. WINDLIST[I][J].I + = 2;
  95. if (Windlist[i][j].alpha <= 0 | | windlist[i][j].x > Lglobal.width | | windlist[i][j].y > Lglobal.height) {
  96. Backlayer.removechild (Windlist[i][j]);
  97. Windlist[i].splice (j,1);
  98. j--;
  99. }
  100. }
  101. }
  102. }
  103. </Script>
  104. </body>
  105. </html>

Test connection

Http://lufylegend.com/demo/astojs/8.html

Here is a friend to ask me the principle, this particle effect is actually a large picture from the top and down, a line of decomposition, and then the decomposition of the broken image, along the random direction to disperse, while reducing the transparency, when the transparency is reduced to 0, remove it.

The above code I added a simple comment, it should not be difficult to understand.

Write html5--eighth, image processing + particle effects using the syntax of ActionScript

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.