用FlashAS实现画图的周详讲解(3)

2008-04-02 11:06:20来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折



  while (l<ml) {

  l = 5;

  // 短线的长

  x = l*mx/ml;

  y = l*my/ml;

  _root.lineto(x, y);

  // 将绘图点移动到相当于短线长的,且和短线在同一直线的位置。即一个空格

  l = 5;

  x = l*mx/ml;

  y = l*my/ml;

  _root.moveto(x, y);

  }

  不错的画线函数,自定义点、线的样式、填充
function Shape() {

  this.points = [];

  this.lines = false;

  tthis.filled = false;

  tthis.lineStyle = null;

  this.t = eval(_target);

  }

  Shape.prototype.addPoint = function(x, y) {

  this.points[this.points.length] = {x:x, y:y};

  };

  Shape.prototype.removePoint = function() {

  this.points.pop();

  };

  Shape.prototype.draw = function(w, c, a) {

  if (this.points.length>1) {

  this.lineStyle = {w:w, c:c,a:a};

  this.t.lineStyle(w, c, a);var i = 0;

  var l = this.points.length;

  while (i<l) {

  this.t.lineTo(this.points[i].

  x,this.points[i].y);

   i;

  }

  this.lines = true;

  }

  };

  Shape.prototype.fill = function(c, a) {

  if (this.points.length>1) {

  if (this.lines) {

  this.clear();

  this.t.lineStyle(this.lineStyle.w,

  this.lineStyle.c, this.lineStyle.a);

  } else {

  this.t.lineStyle(0,0xFFFFFF, 0);

  if (this.filled){

  this.clear();

  }

  }

  this.t.beginFill(c, a);

  var i = 0;

  var l = this.points.length;

  while (i<l) {

  this.t.lineTo(this.points[i].x,this.points[i].y);

   i;

  }

  this.t.endFill();

  this.filled = true;

  }

  };

  Shape.prototype.getX = function() {

  if (this.points.length) {

  return this.points[this.points.length-1].x;

  }

  };

  Shape.prototype.getY = function() {

  if (this.points.length) {

  return this.points[this.points.length-1].y;

  }

  };

  g = new Shape();

  g.addPoint(0, 100);

  g.addPoint(100, 100);

  g.addPoint(100, 0);

  g.addPoint(0, 0);

  g.fill(0x339900, 100);

  g.draw(5, 0x000000, 100);


  系列讲座二,用AS脚本画羽毛、画正余弦、画心脏线、画螺旋线、画旋转的长方体、画烛光、画十四面体……

  action画羽毛 作者:东方暖阳

  代码:
onMouseDown=init;

  function init() {//创建羽毛,并配置羽毛各个参数及对函数的调用

  feather = createEmptyMovieClip("f" i, 10000 i );

  feather.swapDepths(Math.random()*10000);

  feather._x = _xmouse;

  feather._y = _ymouse;

  feather._rotation = -90 Math.random()*40-20;

  col = Math.random()*255 << 8;

  radius = Math.random()*20 20;

  twist = Math.random() .5;

  len = Math.random()*100 50;

  taper = Math.random()*.05 .95;

  x=0;

  onEnterFrame=grow;

  }

  function grow() {//创建函数来定义羽毛的生长、

  定义羽毛的停止生长条件

  angle = Math.sin(fa = twist)*Math.PI/4;

  feather.moveTo(x, y);

  feather.lineStyle(1, col, 50);

  feather.lineTo(x Math.cos(angle)*radius,

  y Math.sin(angle)*radius);

  radius *= taper;

  if (x >len) {

  delete onEnterFrame;

  }

  };


  用as画圆:

  代码:

  思路:用不间断的呗线形成一个圆,实际上一个正360度多边形

  应用:按此法可画任意的图像,如抛物线,螺旋线等,只需把方程修改即可,第2 个代码就是个应用,画椭圆。
_root.onLoad = function() {

  System.Usecodepage = true;

  // 这句我也不知道什么意思,加了以后就支持中文了,是从

  “好笨”那里学来的,侦知道告诉我,谢谢

  _root.createTextField("txtLoad", 151, 50, 280, 400, 30);

  // 建 一文本,名、层次、x、y、宽度、高度

  _root.txtLoad.text = "这是个画线的应用。

  zjs35制作。zjs35@163.com";

  // 文本中的内容

  daxiao = 100;//圆的半径

  yuanxin_x = 200;

  yuanxin_y = 150;//圆心的坐标

  };

  _root.onEnterFrame = function() {

  a = daxiao*Math.cos(n*Math.PI/180);

  b = daxiao*Math.sin(n*Math.PI/180);//根据圆的方程定义一个起点

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇: Flash使用技巧-用Flash制作转动的地球仪

下一篇: 新浪/闪客帝国图片效果解析