コード例 #1
0
        public Form1()
        {
            InitializeComponent();

            mGen = new Generator();
            mGen.AddRule('F', "FFF+F+FFF+F+F+FF-F-FFF-F-F");
            mGen.AddAction('F', moveForward);
            mGen.AddAction('+', turnLeft);
            mGen.AddAction('-', turnRight);
            mGen.AddAction('[', pushToStack);
            mGen.AddAction(']', popFromStack);
            mGen.TraversalComplete += (() => { mDrawingPanel.Refresh(); });

            mState = new CurrentState();
            mState.currentLocation = new Point(256, 256);
            mState.currentAngle    = 90.0f;

            targetLocation = mState.currentLocation;

            executionStack = new Stack <CurrentState>();

            drawingBitmap = new Bitmap(mDrawingPanel.Width, mDrawingPanel.Height);

            mDrawingPanel.Paint += mDrawingPanel_Paint;
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Generator gen = new Generator();

            gen.AddRule('A', "AB");
            gen.AddRule('B', "BA");
            gen.AddAction('A', () => {
                Console.WriteLine("Visited A");
            });
            gen.AddAction('B', () =>
            {
                Console.WriteLine("Visited B");
            });

            string generatedSystem = gen.GenerateSystem(3, "A");

            Console.WriteLine("Generated System: " + generatedSystem);

            gen.TraverseSystem(generatedSystem);


            Console.ReadKey();
        }