我正在创建一个根据Maurer玫瑰轨道运行的生成器,但没有得到理想的结果。它基于编程列车频道的这个视频:https://youtu.be/4uU9lZ-HSqA?si=468dVWSdSfMFU1aa。代码是在p5.js上完成的,我想知道如何将其转换为.cs格式。

以下是我的代码:

#不工作的C#代码
using UnityEngine;

public class rosepattenrenhancesystemwihtlerpandslrep: MonoBehaviour
{
    public Transform center;           
    public Transform[] orbitingObjects;
    public float smallradius= 2f;  
    public float bigradius= 10f;

    public float radius= 3f;      
    public float rotationSpeed= 30f;   
    public bool clockwise=true;      
    public bool start=false;
    public float radiustime;
    public float orbittime;
    public int n=9;
    public int d=71;

    void OnEnable()
    {
        start=true;
        radiustime=0f;
        orbittime=0f;
    }

    void Update()
    {
        if(start)
        {
            radiustime+=Time.deltaTime;
            orbittime+=Time.deltaTime;
            radius= Mathf.Lerp(bigradius,smallradius,Mathf.PingPong(radiustime*0.2f,1f));

            if(center==null||orbitingObjects==null||orbitingObjects.Length==0)
            {
                return;
            }

            float direction=clockwise?1f:-1f;
            float baseAngle=orbittime*rotationSpeed*direction;

            float angleStep=360f/orbitingObjects.Length;

            for(int i=0; i<orbitingObjects.Length; i++)
            {
                if (orbitingObjects[i]==null) continue;

                //float angle=baseAngle + angleStep*i;
                //float rad =angle*Mathf.Deg2Rad;
                float k=i*d;
                float radius2=Mathf.Sin(n*k); // 创建相同的单位

                // 在圆上的位置
                Vector3 offset=new Vector3(
                    Mathf.Cos(k)*radius2,
                    Mathf.Sin(k)*radius2,
                    0f
                );

                orbitingObjects[i].position=center.position + offset;

                // 沿切线旋转子弹
                Vector2 tangent = new Vector2(
                    -Mathf.Sin(k),
                     Mathf.Cos(k)
                );

                float zRot=Mathf.Atan2(tangent.y,tangent.x) * Mathf.Rad2Deg;
                orbitingObjects[i].rotation=Quaternion.Euler(0,0,zRot);
            }
        }
    }
}

#可工作的p5.js代码
let n=9
let d=71
function setup() {
  createCanvas(600, 600);
  background(255);
  noFill();
  stroke(255, 0, 100);

  translate(width / 2, height / 2);

  beginShape();
  for (let a = 0; a < TWO_PI * 5; a += 0.01) {
    let k =a*d;
    let r = 150*sin(n* k);
    let x = r * cos(k);
    let y = r * sin(k);
    vertex(x, y);
  }
  endShape();
}
#-----------------------

​如果有人能帮我一下,非常感谢:)