简体   繁体   English

绘制 Mandelbrot 集

[英]Drawing a Mandelbrot Set

I'm trying to make the function of the Mandelbrot Set, and I'm not sure what I'm doing wrong or right, here's the code:我正在尝试制作 Mandelbrot Set 的 function,但我不确定自己做错了什么或做对了什么,代码如下:

private void StartCircles()
{
    float savePower = BlackCircle.anchoredPosition.x;
    GameObject[] AllCircles = new GameObject[itarations];
    AllCircles[0] = BlackCircle.gameObject;
    for (int i = 1; i < itarations; i++)
    {
        GameObject Circle = Instantiate(BlackCircle.gameObject, Vector3.zero, Quaternion.identity);
        Circle.transform.SetParent(CanvasPerent);
        savePower = Mathf.Pow(savePower, 2);
        savePower += RedCircle.anchoredPosition.x;
        Circle.GetComponent<RectTransform>().anchoredPosition = new Vector2(savePower,
            AllCircles[i - 1].GetComponent<RectTransform>().anchoredPosition.y * -1);
        AllCircles[i] = Circle;
    }
    CleanSqud = new GameObject[itarations];
    CleanSqud = AllCircles;
}

I'm not sure what the y position should be and how could the x position be < 0 if it's a power of 2, it's automaticly > 0.我不确定 y position 应该是什么,如果 x position 是 2 的幂,它怎么会 < 0,它会自动 > 0。

Here's the display:这是显示:

只有2圈

大于 1

i manged to get my code working after some time and i got some answars to share if anyone has my problen:一段时间后,我设法让我的代码正常工作,如果有人遇到我的问题,我会分享一些答案:

well i only wanted to make the function of the zn + 1 = zn * zn + c i dident made the full set only this function, heres my code:好吧,我只想制作 zn + 1 = zn * zn + c 的 function,我只做了这个 function,这是我的代码:

    #region Actions
private void OnDestroy()
{
    MoveBlack.HasMoved -= HasMoved;
    MoveBlack.HasStoped -= HasStoped;

    MoveRed.HasMoved -= HasMoved;
    MoveRed.HasStoped -= HasStoped;
}
private void LateUpdate()
{
    if (moved) { updateCircles(); }
    if (hasparty)
    {
        foreach(GameObject game in CleanSqud)
        {
            game.GetComponent<Image>().color = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f));
        }
    }
}
private void HasMoved()
{
    moved = true;
}

private void HasStoped()
{
    moved = false;
}


#endregion

#region Updateing
private void updateCircles()
{
    foreach (GameObject Circle in CleanSqud) { if (Circle.gameObject.name != "BlackCirlce") { Destroy(Circle); } }
    StartCircles();
}


private void StartCircles()
{


    float x = BlackCircle.anchoredPosition.x;
    float y = BlackCircle.anchoredPosition.y;
    GameObject[] AllCircles = new GameObject[itarations];
    AllCircles[0] = BlackCircle.gameObject;
    for (int i = 1; i < itarations; i++)
    {

        GameObject Circle = Instantiate(BlackCircle.gameObject, Vector3.zero, Quaternion.identity);
        Circle.transform.SetParent(CanvasPerent);
        AllCircles[i] = Circle;

        x = Mathf.Pow(x, 2);
        x -= Mathf.Pow(AllCircles[i - 1].GetComponent<RectTransform>().anchoredPosition.y, 2);
        x += RedCircle.anchoredPosition.x;

        y = (2 * AllCircles[i - 1].GetComponent<RectTransform>().anchoredPosition.x
            * AllCircles[i - 1].GetComponent<RectTransform>().anchoredPosition.y) + RedCircle.anchoredPosition.y;

        Circle.GetComponent<RectTransform>().anchoredPosition = new Vector2(x, y);





    }
    CleanSqud = new GameObject[itarations];
    CleanSqud = AllCircles;
}
#endregion

so what you should do is instad of showing the y as a imaginary and the x as real show it using the equastion: this x = power of the old x - power of the old y + c.x this y = 2 * the old x * the old y + c.y所以你应该做的是将 y 显示为虚数,将 x 显示为实数,使用等式显示它:this x = power of the old x - power of the old y + c.x this y = 2 * the old x * 旧的 y + c.y

this should work.这应该工作。 thanks.谢谢。

在职的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM