Пример #1
0
    /// <summary>
    /// 根据含有形参的Term以及各实参计算出最终的Term并返回。
    /// 如 F(length+1) 为含有形参的Term,length 为 1,则返回F(2)
    /// </summary>
    /// <param name="scrTerm">含有形参的Term,如F(length+1)</param>
    /// <param name="table">包含各实参的DataTable类</param>
    /// <returns>返回计算完成后的Term</returns>
    private LTerm GetResultTerm(LTerm scrTerm, DataTable table)
    {
        if (scrTerm == null)
        {
            return(null);
        }

        LTerm destTerm = new LTerm();

        destTerm.Symbol = scrTerm.Symbol;                                  //将符号赋值给新的term

        table.Rows[table.Rows.Count - 1]["RANDOM"] = RandomNumer.Single(); //写入随机数

        for (int i = 0; i < scrTerm.Params.Count; i++)
        {
            table.Columns["expression"].Expression = scrTerm.Params[i];             //根据参数中的公式进行赋值,如F(length + 1)中的length + 1
            destTerm.Params.Add(table.Rows[0][table.Columns.Count - 1].ToString()); //根据实参、公式计算出结果,并赋值给输出的term中的参数列表
        }

        return(destTerm);
    }
Пример #2
0
    public static Texture2D Create(int width, int height,
                                   int count_CenterPoints, int count_PointsPerGroup = 10, float radius = 15,
                                   Texture2D referenceTex = null, Texture2D barrierTex = null)
    {
        Texture2D texture = new Texture2D(width, height);

        PixelInfo[] PixelInfoes = new PixelInfo[width * height];        //用于存储各像素点的信息(最近特征点和与其的距离)

        Vector2[] CenterPoints = null;

        if (centerPoints == null)
        {
            CenterPoints = RandomPoints(count_CenterPoints, width, height, referenceTex);   //随机选择特征点
        }
        else
        {
            CenterPoints = centerPoints;
        }

        centerPoints = CenterPoints;

        Vector2[]   FeaturePoints     = new Vector2[CenterPoints.Length * count_PointsPerGroup];
        PixelInfo[] FeaturePointInfos = new PixelInfo[FeaturePoints.Length];
        PixelInfo[] FeaturePointInfos_FeaturePoint = new PixelInfo[FeaturePoints.Length];

        for (int i = 0; i < CenterPoints.Length; i++)
        {
            for (int j = 0; j < count_PointsPerGroup; j++)
            {
                Vector2 FeaturePoint = CenterPoints[i] + Random.insideUnitCircle * radius;

                while ((FeaturePoint.x < 0 || FeaturePoint.x > width - 1 ||
                        FeaturePoint.y < 0 || FeaturePoint.y > height - 1))
                {
                    FeaturePoint = CenterPoints[i] + Random.insideUnitCircle * radius;
                }

                FeaturePoint.x = (int)FeaturePoint.x;
                FeaturePoint.y = (int)FeaturePoint.y;

                FeaturePoints[i * count_PointsPerGroup + j] = FeaturePoint;
            }
        }

        FeaturePointInfos = ComputeDistance_FC(FeaturePoints, CenterPoints);
        FeaturePointInfos_FeaturePoint = ComputeDistance_FF(FeaturePoints, FeaturePointInfos);

        SortFeaturePoints(ref FeaturePoints, ref FeaturePointInfos, ref FeaturePointInfos_FeaturePoint);

        /*
         * 计算每个像素与其最近特征点之间的距离
         */
        PixelInfoes = ComputeDistanceFast(width, height, CenterPoints, FeaturePoints, FeaturePointInfos);

        /*
         * 计算最长的距离
         * 用于实现颜色变化
         */
        float MaxDistance = GetMaxDistance(PixelInfoes);

        /*
         * 为实现特征点有先后顺序,对中心点的颜色进行干扰
         */
        for (int i = 0; i < CenterPoints.Length; i++)
        {
            texture.SetPixel((int)CenterPoints[i].x, (int)CenterPoints[i].y,
                             DEC2Color((int)(MaxDistance * RandomNumer.Single() * 0.5f * SCALE)));
        }

        /*
         * 赋予每个特征点颜色
         */
        for (int i = 0; i < FeaturePoints.Length; i++)
        {
            Color FeaturePixel = texture.GetPixel((int)FeaturePointInfos_FeaturePoint[i].X_NearestPoint, (int)FeaturePointInfos_FeaturePoint[i].Y_NearestPoint);

            texture.SetPixel((int)FeaturePoints[i].x, (int)FeaturePoints[i].y, GetColor(FeaturePointInfos[i].Distance, MaxDistance, FeaturePixel));
        }

        /*
         * 赋予每个像素点颜色
         * 根据位置之间的关系,从近到远(黑到白)
         */
        for (int i = 0; i < width; i++)
        {
            for (int j = 0; j < height; j++)
            {
                Color FeaturePixel = texture.GetPixel((int)PixelInfoes[i * height + j].X_NearestPoint, (int)PixelInfoes[i * height + j].Y_NearestPoint);  //获取最近特征点的颜色

                Color pixel = GetColor(PixelInfoes[i * height + j].Distance, MaxDistance, FeaturePixel);

                pixel.a = 1.0f;

                texture.SetPixel(i, j, pixel);
            }
        }

        //添加障碍物像素
        if (barrierTex != null)
        {
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    if (barrierTex.GetPixel(x, y).a != 0)
                    {
                        texture.SetPixel(x, y, GetTransparentColor(texture.GetPixel(x, y)));
                    }
                }
            }
        }

        //添加轮廓像素
        if (referenceTex != null)
        {
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    if (referenceTex.GetPixel(x, y).a == 0)
                    {
                        texture.SetPixel(x, y, GetTransparentColor(texture.GetPixel(x, y)));
                    }
                }
            }
        }

        texture.Apply();

        return(texture);
    }