分享
 
 
 

用Flash脚本生成的花朵

王朝other·作者佚名  2008-05-19
窄屏简体版  字體: |||超大  

今天无聊给大家讲个新玩意吧!如果有点程序基础的看看下面的,重要的我已经解释过半,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中心]。重复再重复的点击按钮,有不同的花开放,再轻轻移动自己的鼠标,花儿会向着你开放~

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有