void Update()
    {
        //Note not using background clear
        float dt = 0.01f;
        float dx = (a * (y - x)) * dt;
        float dy = (x * (b - z) - y) * dt;
        float dz = (x * y - c * z) * dt;

        x = x + dx;
        y = y + dy;
        z = z + dz;

        points.Add(new Vector3(x, y, z));

        //Note Could not add Hue change overtime,
        P5JSExtension.beginShape(MeshTopology.LineStrip);
        foreach (Vector3 v in points)
        {
            Vector3 offset = P5JSExtension.random3D();
            offset *= 0.1f;
            Vector3 a = v + offset;
            P5JSExtension.vertex(a.x, a.y, a.z);
        }
        gameObject.GetComponent <MeshFilter>().mesh = P5JSExtension.endShape();
    }
예제 #2
0
 public void grow()
 {
     for (var i = 0; i < leaves.Count; i++)
     {
         var    leaf          = leaves[i];
         Branch closestBranch = null;
         var    record        = Fractal_Trees_Space_Colonization.max_dist;
         for (var j = 0; j < branches.Count; j++)
         {
             var branch = branches[j];
             var d      = P5JSExtension.dist(leaf.pos, branch.pos);
             if (d < Fractal_Trees_Space_Colonization.min_dist)
             {
                 leaf.reached  = true;
                 closestBranch = null;
                 break;
             }
             else if (d < record)
             {
                 closestBranch = branch;
                 record        = d;
             }
         }
         if (closestBranch != null)
         {
             var newDir = leaf.pos - closestBranch.pos;
             newDir.Normalize();
             closestBranch.dir += newDir;
             closestBranch.count++;
         }
     }
     for (var i = leaves.Count - 1; i >= 0; i--)
     {
         if (leaves[i].reached)
         {
             leaves.RemoveAt(i);
         }
     }
     for (var i = branches.Count - 1; i >= 0; i--)
     {
         var branch = branches[i];
         if (branch.count > 0)
         {
             branch.dir /= branch.count + 1;
             Vector3 rand = P5JSExtension.random3D();
             rand.setMag(0.3f);
             branch.dir += rand;
             this.branches.Add(branch.next());
             branch.reset();
         }
     }
 }
예제 #3
0
 public Leaf()
 {
     pos          = P5JSExtension.random3D();
     pos         *= P5JSExtension.random(P5JSExtension.width / 2);
     this.reached = false;
 }