zoukankan      html  css  js  c++  java
  • 中点画圆算法

    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);  
                    }
                } 
        }

    }

  • 相关阅读:
    BZOJ3252攻略——长链剖分+贪心
    BZOJ3522[Poi2014]Hotel——树形DP
    BZOJ4012[HNOI2015]开店——树链剖分+可持久化线段树/动态点分治+vector
    BZOJ3626[LNOI2014]LCA——树链剖分+线段树
    BZOJ2157旅游——树链剖分+线段树
    BZOJ3531[Sdoi2014]旅行——树链剖分+线段树
    BZOJ2243[SDOI2011]染色——树链剖分+线段树
    zookeeper(1)初识zookeeper
    任督二脉
    RPC框架之RMI
  • 原文地址:https://www.cnblogs.com/qqqeeebbb/p/3554541.html
Copyright © 2011-2022 走看看