• 五角星(多角星)


    运用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;
        }
    }
    

      

  • 相关阅读:
    线段树节点到底开多大
    HDU4901 The Romantic Hero DP
    VIM 配置文件可执行命令
    codeforces159D
    codeforces416B
    codeforces165C
    codeforces332B
    Node.js权威指南 (9)
    iOS-android-windowsphone等移动终端平台开发流程图
    前端面试题细节问题
  • 原文地址:https://www.cnblogs.com/fengziwu/p/10914644.html
Copyright © 2020-2023  润新知