论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > Flash教程
Tag:flash cs,flash 8,鼠绘,as,手绘,工具,文字,loading,入门,初学,mc,影片剪辑,声音,mtv,游戏,引导,遮罩,菜单,补间,广告条,时钟,视频教程

用flash脚本生成的花朵

文章类别:Flash | 发表日期:2008-9-21 19:42:23

  今天无聊给大家讲个新玩意吧!
假如有点程序基础的看看下面的,重要的我已经解释过半,flash 8.0勿试!
效果:

先看看下面的代码:
// [Action in Frame 1]
function initFlower()//init一个在开始循环序列前要计算的表达式/init(初始化)表达式
{
FLOOR_POS = flowerDot_mc._y - 1;
fNum = -1;
tipScale = growScale = tipSlow = growSlow = 0;//开始了
flower = false;//花儿
growing = true;//生长
flowerDot_mc._visible = false;
tip = new Array();//记录叶子的数组
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函数在使用中可以用语句Randomize进行初始化
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();//清除随机绘画内容
if (flower)
{
lineStyle(growScale * leafLength / 12, midColor[midNum]);//lineStyle(粗细,RGB颜色,alpha透明度):更改当前线条样式
moveTo(fx, fy);//moveTo(x坐标,y坐标) :移动当前绘画位置。
lineTo(fx, fy - 1);//lineTo(x坐标,y坐标):开始绘制条段
} // beginGradientFill(填充类型、颜色、透明度、比率、矩阵):标识渐变填充的开始
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(填充类型、颜色、透明度、比率、矩阵):标识渐变填充的开始。
填充类型:字符串值,表示填充的类型。
颜色:数组,表示颜色的填充范围。
透明度:数组,表示透明度的填充范围。
比率:数组,表示填充的过渡范围。
矩阵:自定义对象,表示填充的宽度、高度和方向
{
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(控制点X坐标,控制点Y坐标,锚点X坐标,锚点Y坐标):绘制曲线。
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;
};//顶点旋转定义
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];//随机的支架颜色
sin = Math.sin;//Math.sin()取得正弦值
cos = Math.cos;//Math.cos()取得余弦值。
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;
};

首先新建四层,分别命名。

新建一个矢量图形如下图

再制作一个按钮UP-OVER-DOWN都为空,最后一桢放个可以遮盖整个场景的正方形在里面。

从下往上依次是矢量图形-----文字[Click to grow a new flower ……]动态文本命名click_txt------按钮从库拖入场景叫grow_btn。

在场景中把矢量椭圆图形建在电影剪辑中拖入场景命名为flowerDot_mc,就完工了,很简单吧。

注重把矢量椭圆最好放正[随机在定义花朵3D中心]。
重复再重复的点击按钮,有不同的花开放,再轻轻移动自己的鼠标,花儿会向着你开放~!
看效果

视频教程列表
文章教程搜索
 
Flash推荐教程
Flash热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058