예제 #1
0
        public void Run(ILSystem lSystem, IDrawContext drawCtx, int generation, string c, ref GenerationState genState)
        {
            // Standard command symbols:
            // f signifies a move,
            // + and - rotate either left or right, | rotates 180 degrees,
            // [ and ] are for push() and pop(), e.g. offshoot branches,
            // < and > decrease or increases the segment length,
            // ( and ) decrease or increases the rotation angle.
            if (c == "f")
            {
                drawCtx.Translate(this.SegmentAxis * -Math.Min(genState.length, genState.length * genState.time));
            }
            else if (c == "-")
            {
                drawCtx.Rotate(this.AngleAxis, Math.Min(+genState.angle, +genState.angle * genState.time));
            }
            else if (c == "+")
            {
                drawCtx.Rotate(this.AngleAxis, Math.Max(-genState.angle, -genState.angle * genState.time));
            }
            else if (c == "|")
            {
                drawCtx.Rotate(this.AngleAxis, 180f);
            }
            else if (c == "[")
            {
                drawCtx.Push();
            }
            else if (c == "]")
            {
                drawCtx.Pop();
            }

            // Non-drawing constants
            else if (c == "!")
            {
                genState.angle -= genState.angle;
            }
            else if (c == "(")
            {
                genState.angle *= 1.1f;
            }
            else if (c == ")")
            {
                genState.angle *= 0.9f;
            }
            else if (c == "<")
            {
                genState.length *= 0.9f;
            }
            else if (c == ">")
            {
                genState.length *= 1.1f;
            }
        }