Flowers created with flash scripts

Source: Internet
Author: User
Tags abs definition cos range sin
The script is boring today to tell us a new thing! If there is a program based on the look below, important I have explained more than half, flash 8.0 do not try! Effect: (can be clicked continuously with the mouse)


Let's look at the following code:
[Action in Frame 1]
function Initflower ()//init An expression/init (initialization) expression to evaluate before starting the loop sequence
{
Floor_pos = flowerdot_mc._y-1;
Fnum =-1;
Tipscale = Growscale = Tipslow = Growslow = 0;//started
Flower = false;//Flowers
growing = true;//growth
Flowerdot_mc._visible = false;
tip = new Array ()//array of leaf records
C1 = new Array ();
C2 = new Array ();
M1 = new Array ();
m2 = new Array ();
C3 = New Array ();
C4 = new Array ();
This.createemptymovieclip ("FLOWER_MC", 0);
flower_mc._x = flowerdot_mc._x;
leaftotal = Int (rnd () * 5) + 3;//rnd function can be initialized with statement randomize in use
Leaflength = Rnd () * 80 + 20;
Leafwidth = leaflength/leaftotal * 3.141593 * RND ();
Leafnextnum = leafnum = Int (rnd () * leafcolor.length);
Petalnextnum = petalnum = Int (rnd () * petalcolor.length);
midnum = Int (rnd () * midcolor.length);
Flower_color = new Color ("FLOWERDOT_MC");
Flower_color.setrgb (Leafline[leafnum]);
}//End of the function
function Newflower ()
{
Flowerdot_mc._visible = true;
if (Fnum = 1)
{
Flower = true;
}//End If
if (Fnum = 2)
{
growing = false;
return (undefined);
}//End If
fnum++;
Flower_mc.createemptymovieclip (Fnum, Fnum). Createemptymovieclip ("STEM_MC",-1);
Flower_mc[fnum].ox = 0;
Flower_mc[fnum].oy = Fnum = = 0? (Floor_pos): (Flower_mc[fnum-1].oy);
Tip[fnum] = new Array ();
C1[fnum] = new Array ();
C2[fnum] = new Array ();
M1[fnum] = new Array ();
M2[fnum] = new Array ();
C3[fnum] = new Array ();
C4[fnum] = new Array ();
var _l18 = rnd () * 1.500000;
var _l17 = rnd () * 1.500000;
var _l16 = rnd () * 1.500000;
var _l14 = rnd () * 0.400000 + 0.200000;
var _l13 = rnd () * 0.400000 + 0.600000;
var _l15 = rnd () * 0.900000 + 0.100000;
if (_l15 < 0.200000)
{
_l14 = 0;
_l13 = 0;
_l15 = 0;
}//End If
if (flower)
{
var _l24 = rnd () * 80-100;
var _l21 = 0;
var _l23 = rnd () * 100-50;
var _l22 = 0;
leaftotal = Int (rnd () * 7) + 3;
Leaflength = Rnd () * 80 + 20;
Leafwidth = Leafwidth + 20;
}
Else
{
_l24 = Rnd () * 80-40;
_l21 = Rnd () * 40-20;
_l23 = Rnd () * 40-20;
_l22 = Rnd () * 30-15;
}//End If
Tipscale = 0;
Tipslow = 0.050000;
Growscale = 0.250000;
Growslow = 0.050000;
var _l1 = leaftotal;
while (_l1--)
{
var _l7 = _l1/leaftotal * 6.283185;
TIP[FNUM][_L1] = new Vertex (cos (_L7) * leaflength, sin (_l7) * leaflength, _L24);
var _l8 = tip[fnum][_l1].x;
var _l6 = tip[fnum][_l1].y;
var _l12 = cos (_l7-1.570796);
var _l10 = cos (_l7 + 1.570796);
var _l11 = sin (_l7-1.570796);
var _l9 = sin (_l7 + 1.570796);
C1[FNUM][_L1] = new Vertex (_L8 * _l14 + _l12 * leafwidth * _l18, _L6 * _l14 + _l11 * leafwidth * _l18, _L21);
C2[FNUM][_L1] = new Vertex (_L8 * _l13 + _l12 * leafwidth * _l17, _L6 * _l13 + _l11 * leafwidth * _l17, _l23);
M1[FNUM][_L1] = new Vertex (_L8 * _l15 + _l12 * leafwidth * _l16, _L6 * _l15 + _l11 * leafwidth * _l16, _l22);
M2[FNUM][_L1] = new Vertex (_L8 * _l15 + _l10 * leafwidth * _l16, _L6 * _l15 + _l9 * leafwidth * _l16, _l22);
C3[FNUM][_L1] = new Vertex (_L8 * _l13 + _l10 * leafwidth * _l17, _L6 * _l13 + _l9 * leafwidth * _l17, _l23);
C4[FNUM][_L1] = new Vertex (_L8 * _l14 + _l10 * leafwidth * _l18, _L6 * _l14 + _l9 * leafwidth * _l18, _L21);
var _l19 = flower? (-0.785398): (-1.570796);
var _l20 = 0;
var _l3 = cos (_l19);
var _l2 = sin (_l19);
var _l5 = cos (_L20);
var _l4 = sin (_l20);
Tip[fnum][_l1].rotate (_L5, _l4, _l3, _L2);
C1[fnum][_l1].rotate (_L5, _l4, _l3, _L2);
C2[fnum][_l1].rotate (_L5, _l4, _l3, _L2);
M1[fnum][_l1].rotate (_L5, _l4, _l3, _L2);
M2[fnum][_l1].rotate (_L5, _l4, _l3, _L2);
C3[fnum][_l1].rotate (_L5, _l4, _l3, _L2);
C4[fnum][_l1].rotate (_L5, _l4, _l3, _L2);
Tip[fnum][_l1].scale (Tipscale);
C1[fnum][_l1].scale (Growscale);
C2[fnum][_l1].scale (Growscale);
M1[fnum][_l1].scale (Growscale);
M2[fnum][_l1].scale (Growscale);
C3[fnum][_l1].scale (Growscale);
C4[fnum][_l1].scale (Growscale);
Flower_mc[fnum].createemptymovieclip (_L1, _L1);
}//End While
}//End of the function
function Updateflower ()
{
Flower_mc[fnum].oy = Flower_mc[fnum].oy-sin (Growscale * 3.141593) * LEAFLENGTH/24;
var fx = 0;
var fy = Flower_mc[fnum].oy;
var slow = flower? ( -0.000500): (Tipslow *-0.010000);
var ax = Flower_mc._xmouse * SLOW;
var ay = 0;
var cy = cos (ay);
var sy = sin (ay);
var cx = cos (AX);
var sx = sin (ax);
var h = ABS (Flower_mc[fnum].getbounds (FLOWER_MC). Ymin-fy) * 2;
With (FLOWER_MC[FNUM].STEM_MC)
{
Clear ();
LineStyle (3, leafline[leafnum]);
MoveTo (0, fnum = 0?) (Floor_pos): (Flower_mc[fnum-1].oy));
LineTo (0, FY);
}//End of With
if (Growscale < 1)
{
Growslow = Growslow * 0.950000;
Growscale = Growscale + growslow;
}
Else
{
Growscale = 1;
}//End If
if (Tipscale < 1)
{
Tipslow = Tipslow * 0.960000;
Tipscale = Tipscale + tipslow;
}
else if (growing)
{
Tipscale = 1;
Newflower ();
}//End If
var Midscale = (Growscale + tipscale)/2;
var i = leaftotal;
while (i--)
{
Tip[fnum][i].rotate (CX, SX, CY, SY);
C2[fnum][i].rotate (CX, SX, CY, SY);
M1[fnum][i].rotate (CX, SX, CY, SY);
M2[fnum][i].rotate (CX, SX, CY, SY);
C3[fnum][i].rotate (CX, SX, CY, SY);
Tip[fnum][i].scale (Tipscale);
C2[fnum][i].scale (Growscale);
M1[fnum][i].scale (Midscale);
M2[fnum][i].scale (Midscale);
C3[fnum][i].scale (Growscale);
Tip[fnum][i].perspective ();
C2[fnum][i].perspective ();
M1[fnum][i].perspective ();
M2[fnum][i].perspective ();
C3[fnum][i].perspective ();
var tx = Tip[fnum][i].rx;
var ty = Tip[fnum][i].ry;
With (Flower_mc[fnum][i])
{
Clear ();//purge random painting content
if (flower)
{
LineStyle (Growscale * LEAFLENGTH/12, Midcolor[midnum]);//linestyle (thickness, RGB color, alpha transparency): Change the current line style
MoveTo (FX, FY);//moveto (x coordinates, y coordinates): Moves the current painting position.
LineTo (FX, fy-1);//lineto (x coordinate, y coordinate): Start drawing section
}//Begingradientfill (fill type, color, transparency, ratio, matrix): Identifying the beginning of a gradient fill
LineStyle (Growscale * 5, Flower?) (Petalline[petalnum]): (Leafline[leafnum]), 10);
MoveTo (FX, FY);
Begingradientfill ("Radial", flower?) (Petalcolor[petalnum]): (Leafcolor[leafnum]), [100, 100], [20, 255],
{matrixtype: "box", x: -100, Y:fy-h/2, w:200, H:h, r:0});
if (flower)//begingradientfill (fill type, color, transparency, ratio, matrix): Identifies the beginning of a gradient fill.
Fill type: A string value that represents the type of the fill.
Color: An array that represents the fill range for a color.
Transparency: An array that represents the range of padding for transparency.
Ratio: An array that represents the transition range for a fill.
Matrix: Custom object that represents the width, height, and orientation of the fill
{
Curveto (C2[fnum][i].rx, C2[fnum][i].ry, TX, Ty);
Curveto (C3[fnum][i].rx, C3[fnum][i].ry, FX, FY);
}
Else
{
C1[fnum][i].rotate (CX, SX, CY, SY);
C4[fnum][i].rotate (CX, SX, CY, SY);
C1[fnum][i].scale (Growscale);
C4[fnum][i].scale (Growscale);
C1[fnum][i].perspective ();
C4[fnum][i].perspective ();
Curveto (C1[fnum][i].rx, C1[fnum][i].ry, M1[fnum][i].rx, M1[fnum][i].ry);
Curveto (C2[fnum][i].rx, C2[fnum][i].ry, TX, Ty);
Curveto (C3[fnum][i].rx, C3[fnum][i].ry, M2[fnum][i].rx, M2[fnum][i].ry);
Curveto (C4[fnum][i].rx, C4[fnum][i].ry, FX, FY);
//Curveto (Control point x Coordinate, control point y-coordinate, anchor X coordinate, Anchor point y coordinate): Draw curve.
Endfill ();
var a = 1-tip[fnum][i].z + i;
Swapdepths (a);
_alpha = A/2 + 100;
}//End of With
}//End While
Updateafterevent ();
}//End of the function
Vertex = function (x, y, z)
{
this.x = x;
This.y = y;
This.z = Z;
This.rx = This.ry = this.wx = This.wy = 0;
};
Vertex.prototype.perspective = function ()
{
var _l2 = this.wz/400 + 1;
This.rx = THIS.WX/_l2;
This.ry = (This.wy + flower_mc[fnum].oy)/_l2;
};
Vertex.prototype.rotate = function (CX, SX, CY, SY)
{
var _l3 = this.y * cy-this.z * SY;
var _l2 = this.y * sy + this.z * CY;
var _l4 = this.x * cx + _L2 * SX;
_L2 = _L2 * cx-this.x * SX;
This.x = _l4;
This.y = _L3;
This.z = _L2;
};
Vertex.prototype.scale = function (W)
{
THIS.WX = this.x * W;
This.wy = This.y * W;
THIS.WZ = this.z * W;
};//vertex rotation definition
Leafcolor = [[2267392, 5622784], [7833634, 10079232], [3368482, 2280567], [6697728, 15628032], [7803170, 13373781]];
Leafline = [30464, 6719488, 39219, 7816192, 5570611];
Petalcolor = [[16711680, 16751001], [16750984, 16772829], [16763955, 16777113], [16777113, 16777215],
[10078432, 15663103], [10066380, 14540270]];
Petalline = [10027008, 16737860, 13399808, 15658581, 5605563, 7829435];
Midcolor = [16777062, 16763904, 16724787, 3381555, 0];//random bracket color
Sin = Math.sin;//math.sin () get the sine value
cos = Math.cos;//math.cos () gets the cosine value.
ABS = Math.Abs;
Rnd = Math.random;
Flowerdot_mc._visible = false;
grow_btn.onpress = function ()
{
Initflower ();
Newflower ();
Clearinterval (flowertimeout);
Flowertimeout = SetInterval (Updateflower, 8);
Click_txt._visible = false;
};
First, create a new four layer, named separately.

Create a new vector graphic as shown below

Then make a button Up-over-down are empty, the last frame put a can cover the whole scene of the square inside.

From the bottom up, in turn, vector graphics-----text [Click to grow a new flower ...] Dynamic text named Click_txt------button dragged from the library into the scene called Grow_btn.

In the scene, the vector ellipse graph is built in the movie clip to drag into the scene named FLOWERDOT_MC, it is finished, very simple.

Note that the vector ellipse is best placed [randomly in the definition of Flower 3D center]. Repeat the click button, there are different flowers open, and then gently move their own mouse, flowers will open to you ~!



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.