예제 #1
0
                public override bool TryRun(BMyDrawingCommand command, BMyCanvas canvas, BMyEnvironment Env)
                {
                    int r;

                    if (int.TryParse(command.Args, out r))
                    {
                        circle(r, canvas);
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
예제 #2
0
                public override bool TryRun(BMyDrawingCommand command, BMyCanvas canvas, BMyEnvironment Env)
                {
                    string[] argv = command.Args.Split(new char[] { ',' });
                    int      x;
                    int      y;

                    if (
                        argv.Length == 2 &&
                        int.TryParse(argv[0], out x) &&
                        int.TryParse(argv[1], out y)
                        )
                    {
                        return(canvas.TrySetPixel(x, y));
                    }
                    else
                    {
                        return(false);
                    }
                }
예제 #3
0
                public override bool TryRun(BMyDrawingCommand command, BMyCanvas canvas, BMyEnvironment Env)
                {
                    byte r;
                    byte g;
                    byte b;

                    string[] argv = command.Args.Split(new char[] { ',' });

                    if (argv.Length == 3 &&
                        byte.TryParse(argv[0], out r) &&
                        byte.TryParse(argv[1], out g) &&
                        byte.TryParse(argv[2], out b)
                        )
                    {
                        canvas.color = new BMyColor(r, g, b);
                        return(true);
                    }
                    return(false);
                }
예제 #4
0
                public bool TryRunDraw(BMyDrawingCommand command, BMyCanvas canvas)
                {
                    Log?.PushStack("BMyEnvironment.TryRunDraw(BMyDrawingCommand command, BMyCanvas canvas)");
                    List <BMyDrawPlugin> DrawPluginsForCommand = DrawPlugins.FindAllByName(command.Key);

                    Log?.Debug("found {0} commands for {1}", DrawPluginsForCommand.Count, command.Key);
                    bool successfull = false;

                    if (DrawPluginsForCommand.Count > 0)
                    {
                        for (int i = 0; i < DrawPluginsForCommand.Count && !successfull; i++)
                        {
                            successfull = DrawPluginsForCommand[i].TryRun(command, canvas, this);
                            Log?.Debug("{0}: Plugin {1}/{2} with \"{3}\"", successfull?"OK":"FAIL", DrawPluginsForCommand[i].Vendor, DrawPluginsForCommand[i].Name, command);
                        }
                    }
                    Log?.Debug("{0}: Drawing of \"{1}\"", successfull ? "OK" : "FAIL", command);
                    Log?.PopStack();
                    return(successfull);
                }
예제 #5
0
                public override bool TryRun(BMyDrawingCommand command, BMyCanvas canvas, BMyEnvironment Env)
                {
                    string[] argv = command.Args.Split(new char[] { ',' });
                    int      x;
                    int      y;

                    if (
                        argv.Length == 2 &&
                        int.TryParse(argv[0], out x) &&
                        int.TryParse(argv[1], out y)
                        )
                    {
                        canvas.Position = new BMyPoint(x, y);
                        return(canvas.Position.X == x && canvas.Position.Y == y);
                    }
                    else
                    {
                        return(false);
                    }
                }
예제 #6
0
                public override bool TryRun(BMyDrawingCommand command, BMyCanvas canvas, BMyEnvironment Env)
                {
                    string[] argv = command.Args.Split(new char[] { ',' });
                    int      x;
                    int      y;

                    if (
                        argv.Length == 2 &&
                        int.TryParse(argv[0], out x) &&
                        int.TryParse(argv[1], out y)
                        )
                    {
                        BMyPoint target = new BMyPoint(x, y);
                        lineTo(target, canvas);
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
예제 #7
0
                public override bool TryRun(BMyDrawingCommand command, BMyCanvas canvas, BMyEnvironment Env)
                {
                    string[] argv = command.Args.Split(new char[] { ',' });
                    int      x;
                    int      y;

                    if (
                        argv.Length == 2 &&
                        int.TryParse(argv[0], out x) &&
                        int.TryParse(argv[1], out y)
                        )
                    {
                        bool              success       = false;
                        BMyPoint          origin        = canvas.Position;
                        BMyDrawingCommand linetoCommand = new BMyDrawingCommand(string.Format(@"lineto {0},{1}", x, origin.Y));
                        if (Env.TryRunDraw(linetoCommand, canvas))
                        {
                            linetoCommand = new BMyDrawingCommand(string.Format(@"lineto {0},{1}", x, y));
                            if (Env.TryRunDraw(linetoCommand, canvas))
                            {
                                linetoCommand = new BMyDrawingCommand(string.Format(@"lineto {0},{1}", origin.X, y));
                                if (Env.TryRunDraw(linetoCommand, canvas))
                                {
                                    linetoCommand = new BMyDrawingCommand(string.Format(@"lineto {0},{1}", origin.X, origin.Y));
                                    if (Env.TryRunDraw(linetoCommand, canvas))
                                    {
                                        success = true;
                                    }
                                }
                            }
                        }

                        canvas.Position = new BMyPoint(x, y);
                        return(success);
                    }
                    else
                    {
                        return(false);
                    }
                }
예제 #8
0
                public override bool TryRun(BMyDrawingCommand command, BMyCanvas canvas, BMyEnvironment Env)
                {
                    bool success = false;

                    string[] argv = command.Args.Split(new char[] { ' ' });
                    foreach (string arg in argv)
                    {
                        string[] _pos = arg.Split(new char[] { ',' }, 2);
                        int      x;
                        int      y;
                        if (_pos.Length == 2 &&
                            int.TryParse(_pos[0], out x) &&
                            int.TryParse(_pos[1], out y)
                            )
                        {
                            success = success && Env.TryRunDraw(new BMyDrawingCommand(string.Format(@"lineto {0},{1}", x, y)), canvas);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    return(success);
                }
예제 #9
0
            public BMyCanvas run(string[] source, Program Assembly)
            {
                #region Environment
                BMyEnvironment Env = new BMyEnvironment(Assembly);
                Env.Log?.PushStack("run(string[] source, Program Assembly)");
                #endregion Environment

                #region build plugins
                // prepare pluginhandlers
                Env.Log?.Debug("START - Preparing Plugins");
                Env.DrawPlugins.AddPlugin(new BMyDrawPlugin_Background()); // "background R,G,B" where R G B is 0-6
                Env.DrawPlugins.AddPlugin(new BMyDrawPlugin_Circle());     // "circle RADIUS" where RADIUS is integer
                Env.DrawPlugins.AddPlugin(new BMyDrawPlugin_LineTo());     // "lineto x,y" where x y is integer
                Env.DrawPlugins.AddPlugin(new BMyDrawPlugin_MoveTo());     // "moveto x,y" where x y is integer
                Env.DrawPlugins.AddPlugin(new BMyDrawPlugin_Rect());       // "rect x,y" where x y is integer
                Env.DrawPlugins.AddPlugin(new BMyDrawPlugin_Polygon());    // "poly x,y x,y x,y" where x y is integer
                Env.DrawPlugins.AddPlugin(new BMyDrawPlugin_Color());      // "color R,G,B" where R G B is 0-6
                Env.DrawPlugins.AddPlugin(new BMyDrawPlugin_Dot());        // "dot x,y" where x y is integer
                foreach (KeyValuePair <string, List <BMyDrawPlugin> > _pluginlist in Env.DrawPlugins)
                {
                    Env.Log?.Debug(@"{0} Plugins for {1}", _pluginlist.Value.Count, _pluginlist.Key);
                }
                Env.Log?.Debug("END - Preparing Plugins");
                #endregion build plugins

                #region build code queue
                Env.Log?.Debug("START - Building Code queue");
                Queue <BMyDrawingCommand> codeQueue = new Queue <BMyDrawingCommand>();
                Env.Log?.Debug("code has {0} lines", source.Length);
                foreach (string currentLine in source)
                {
                    Env.Log?.Debug("enqueue command: {0}", currentLine);
                    codeQueue.Enqueue(new BMyDrawingCommand(currentLine));
                }
                Env.Log?.Debug("END - Building Code queue");
                #endregion build code queue

                #region make canvas
                BMyCanvas canvas = new BMyCanvas(50, 50, new BMyColor(0, 0, 0));
                Env.Log?.Debug("created canvas. {0}x{1}", canvas.Width, canvas.Height);
                #endregion make canvas

                #region progress codeQueue
                Env.Log?.Debug("START - progressing code");
                while (codeQueue.Count > 0)
                {
                    // break if over limits
                    BMyDrawingCommand command = codeQueue.Dequeue();
                    if (Env.TryRunDraw(command, canvas))
                    {
                        Env.Log?.Debug("OK: command \"{0}\"", command);
                    }
                    else
                    {
                        Env.Log?.Debug("FAIL: command \"{0}\"", command);
                    }
                }
                Env.Log?.Debug("END - progressing code");

                Env.Log?.PopStack();
                return(canvas);

                #endregion progress codeQueue
            }
예제 #10
0
 abstract public bool TryRun(BMyDrawingCommand command, BMyCanvas canvas, BMyEnvironment Env);