Пример #1
0
    // see https://en.wikipedia.org/wiki/Torus_knot
    void TorusKnot(GeometricObject obj)
    {
        System.Func <float, Vector3> f = (phi) => {
            var o = new Vector3();
            var p = 3f;
            var q = 8f;
            var r = Mathf.Cos(q * phi) + 2f;
            o.x = r * Mathf.Sin(p * phi);
            o.y = r * Mathf.Cos(p * phi);
            o.z = -Mathf.Sin(q * phi);
            return(o);
        };

        var alpha       = 1.0f;
        var n           = 1200;
        var frontColors = new List <Color32> ();
        var points      = new List <Vector3> ();

        frontColors.Clear();
        for (var i = 0; i < n; ++i)
        {
            var hue = (float)i / n;
            var cl  = Color.HSVToRGB(hue, 1f, 1f);
            cl.a = alpha;
            frontColors.Add(cl);
        }

        points.Clear();
        for (var i = 0; i < n; ++i)
        {
            var w = 2f * Mathf.PI * (float)i / n;
            points.Add(f(w));
        }

        obj.Begin();
        obj.SetLineRadius(0.3f);
        obj.SetLineTopology(Pen.Topology.Close);
        obj.AddLine(points, frontColors);
        obj.End();
    }