zoukankan      html  css  js  c++  java
  • 五角星(多角星)

    运用for循环画五角星(多角星):

    /***
     * 多角星
     * @param vertex 顶点 角的个数
     * @param radius 半径
     * @param color  填充颜色
     ***/
      
     //方法:
    star(12);
     
    function star(vertex:int=5,radius:int=100,color:uint=0xff0000)
    {
        if (vertex>=2)
        {
            //初始点
            graphics.moveTo(radius,0);
            //填充颜色;
            graphics.beginFill(color);
            //for循环画线条 vertex*2需要经过的顶点数;
            for (var i:int = 1; i < vertex*2; i++)
            {
                //半径
                var radius2:Number = radius;
                //求模,余数不等于0,这里其实就是奇、偶数的判断
                if (i % 2 !=0)
                {
                    //i为奇数的时候半径减半
                    radius2 = radius / 2;
                }
                //当前角度
                var angle:Number = Math.PI * 2 / (vertex * 2) * i;
                //点的坐标(通过角度与半径计算每一个顶点的坐标)
                graphics.lineTo(Math.cos(angle) * radius2,Math.sin(angle) * radius2);
            }
            //结束画图
            this.graphics.endFill();
            //移动图形坐标;
            x = y = radius;
            //旋转图形
            //rotation = -90;
        }
    }
    

      

  • 相关阅读:
    第三周学习进度条
    软件工程个人作业02
    构建之法阅读笔记02
    学习进度条
    构建之法阅读笔记01
    软件工程个人作业01
    构建之法粗读
    第一次作业
    动手动脑接口与继承
    大道至简第七章第八章
  • 原文地址:https://www.cnblogs.com/fengziwu/p/10914644.html
Copyright © 2011-2022 走看看