• 中点画圆算法


    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;

    public class test : MonoBehaviour {



     Texture2D alphaTest;


        void Start () {
        
                alphaTest = (Texture2D)this.GetComponent<GUITexture>().texture;
                Debug.Log(Screen.width+"  "+Screen.height);
        }
        
        // Update is called once per frame
        void Update () {
        
            if(Input.GetMouseButton(0))
            {
                Debug.Log(Input.mousePosition);
                
                int x = (int)Input.mousePosition.x;
                int y = (int)Input.mousePosition.y;
                
                x=(x*1024)/Screen.width;
                y=(y*768)/Screen.height;
            
                Color cc = alphaTest.GetPixel(x,y);    
                Debug.Log(cc);
                
                alphaTest.SetPixel(x,y,new Color(1,0,0,1));
                
    //            for(int i=0 ; i<30 ; ++i)
    //            {
    //                circleMidpoint(x,y,i,new Color(1,0,0,0));
    //            }
                
                roundMidpoint(x,y,30,new Color(0,1,0,1));
                
                alphaTest.Apply();
                
                
                
            }    
        
        }
        
        
        ///把屏幕座标转换成NGUI的座标,此方法只适用于基于屏幕宽度缩放。参数:screenPosition - 鼠标或手指在屏幕上的座标。widthBased - 基于缩放的宽度是多少。
        public Vector2 convertScreenToNguiPositionBasedOnWidth(Vector3 screenPosition,float widthBased)
        {
        return new Vector2((screenPosition.x - Screen.width / 2f) * widthBased / Screen.width,(screenPosition.y - Screen.height / 2f) * widthBased / Screen.width);
        }
        
        ///把屏幕座标转换成左 → 右 , 上 ↓ 下的座标,此方法只适用于基于屏幕宽度缩放。参数:screenPosition - 鼠标或手指在屏幕上的座标。widthBased - 基于缩放的宽度是多少。
        public Vector2 convertScreenToTexture(Vector3 screenPosition,float widthBased)
        {
        return new Vector2(( screenPosition.x ) * widthBased / Screen.width,( Screen.height -screenPosition.y ) * widthBased / Screen.width);
        }
        
        
        
        
        private void circlePoints(int cx, int cy, int x, int y, Color pix)
        {
            
            if (x == 0) {
                alphaTest.SetPixel(cx, cy + y,pix );  
                alphaTest.SetPixel(cx, cy - y,pix );  
                alphaTest.SetPixel(cx + y, cy,pix );  
                alphaTest.SetPixel(cx - y, cy,pix );                 
            } else 
            if (x == y) {
                alphaTest.SetPixel(cx + x, cy + y,pix );
                alphaTest.SetPixel(cx - x, cy + y,pix );
                alphaTest.SetPixel(cx + x, cy - y,pix );
                alphaTest.SetPixel(cx - x, cy - y,pix );
            } else                            
            if (x < y) {                      
                alphaTest.SetPixel(cx + x, cy + y,pix );
                alphaTest.SetPixel(cx - x, cy + y,pix );
                alphaTest.SetPixel(cx + x, cy - y,pix );
                alphaTest.SetPixel(cx - x, cy - y,pix );
                alphaTest.SetPixel(cx + y, cy + x,pix );
                alphaTest.SetPixel(cx - y, cy + x,pix );
                alphaTest.SetPixel(cx + y, cy - x,pix );
                alphaTest.SetPixel(cx - y, cy - x,pix );
            }
        }

        public void circleMidpoint(int xCenter, int yCenter, int radius, Color c)
        {
            int x = 0;
            int y = radius;
            int p = (5 - radius*4)/4;

            circlePoints(xCenter, yCenter, x, y, c);
            while (x < y) {
                x++;
                if (p < 0) {
                    p += 2*x+1;
                } else {
                    y--;
                    p += 2*(x-y)+1;
                }
                circlePoints(xCenter, yCenter, x, y, c);
            }
        }
        
        public void roundMidpoint(int xCenter, int yCenter, int radius, Color c)
        {
            for(int i=-radius ; i<=+radius ; ++i)
                {
                    for(int j =-radius ; j<=+radius ; ++j)
                    {
                        if((i*i+j*j)<=(radius*radius))
                                alphaTest.SetPixel(i+xCenter, j+yCenter,c);  
                    }
                } 
        }

    }

  • 相关阅读:
    yum只下载不安装
    知乎的 Flink 数据集成平台建设实践
    饿了么EMonitor演进史
    手机淘宝轻店业务 Serverless 研发模式升级实践
    独家对话阿里云函数计算负责人不瞋:你所不知道的 Serverless
    一文详解物化视图改写
    业务团队如何统一架构设计风格?
    Fluid 给数据弹性一双隐形的翅膀 -- 自定义弹性伸缩
    开源 1 年半 star 破 1.2 万的 Dapr 是如何在阿里落地的?
    Service Mesh 从“趋势”走向“无聊”
  • 原文地址:https://www.cnblogs.com/qqqeeebbb/p/3554541.html
Copyright © 2020-2023  润新知