コード例 #1
0
    private void VisualizeBezier(Bezier b, Color c, Color d)
    {
        Vector2 oldPos = b.Eval(0);

        for (int i = 1; i <= 100; ++i)
        {
            float time = i / 100f;
            Debug.DrawLine(oldPos, b.Eval(time), c);
            oldPos = b.Eval(time);
        }
    }
コード例 #2
0
 public BezierMap(Map map)
 {
     trunk = CreatePath(
         Vector2.zero,
         map.trunkPivotCount,
         map.trunkLength,
         Random.value * Mathf.PI * 2f
         );
     trunk.end = trunk.Eval(1.0);
     start     = trunk.Graph(map.trunkWidth);
 }
コード例 #3
0
    private void BrushBezier(Bezier bez, HashSet <Vector2Int> tiles, double width, bool brush)
    {
        Vector2 bPos;

        width += 0.5;
        float presInc = 1f / precision;

        for (int i = 0; i <= precision; ++i) // not += presInc bc float arith
        {
            bPos = bez.Eval(i * presInc);
            BrushPos(bPos, tiles, width, brush);
        }
    }
コード例 #4
0
    private void CreateBranches()
    {
        List <int> possibleGrafts = new List <int>();

        for (int i = 1; i < trunk.pivots.Length - 1; ++i)
        {
            possibleGrafts.Add(i);
        }
        Vector2 bStart, bEnd, dir; // todo dododo
        int     graftIndex;

        branches = new Bezier[branchCount];
        for (int i = 0; i < branchCount; ++i)
        {
            graftIndex = possibleGrafts[(int)(possibleGrafts.Count * Random.value)];
            possibleGrafts.Remove(graftIndex);

            bStart      = trunk.Eval((float)graftIndex / (float)trunkPivotCount);
            dir         = trunk.pivots[graftIndex] - bStart;
            bEnd        = bStart + dir.normalized * branchLength;
            branches[i] = CreatePath(bStart, bEnd, branchPivotCount);
        }
    }