示例#1
0
        protected ConsoleCommandVariableAttribute.Values GetAllValuesInOrder(string[] cmds)
        {
            var allVariables = this.GetType().GetCustomAttributes <ConsoleCommandVariableAttribute>();
            var cmdsDic      = GetDictionary(cmds);

            ConsoleCommandVariableAttribute.Values result = new ConsoleCommandVariableAttribute.Values(allVariables.ToDictionary(x => x.KeyName, x => x.GetValue(cmdsDic.FirstOrDefault(y => x.KeyName == y.Key).Value)));
            return(result);
        }
        public object Execute(ConsoleCommandVariableAttribute.Values objs)
        {
            string       bmpBase64 = Convert.ToBase64String(new Mandelbrot().GetImage(objs));
            FractalImage img       = new FractalImage();

            img.Name        = "Mandelbrot Set";
            img.ImageBase64 = bmpBase64;
            return(img);
        }
示例#3
0
        public override ConsoleReturnVo Execute(string[] cmd)
        {
            ConsoleCommandVariableAttribute.Values vals = GetAllValuesInOrder(cmd);
            IConsoleCommandStrategy mbset = this.GetType().GetCustomAttribute <ConsoleCommandStrategyAttribute>().GetInstance();
            FractalImage            img   = (FractalImage)mbset.Execute(vals);
            double lastWidth = vals.GetValue("xmax").DoubleValue - vals.GetValue("xmin").DoubleValue;
            ConsoleMandelbrotReturnVo result = new ConsoleMandelbrotReturnVo("\nMandelbrotSet: applied values...", image: img.ImageBase64, lastX: vals.GetValue("xmin").DoubleValue, lastY: vals.GetValue("ymin").DoubleValue, lastWidth: lastWidth);

            return(result);
        }
示例#4
0
        public override ConsoleReturnVo Execute(string[] cmd)
        {
            ConsoleCommandVariableAttribute.Values vals = GetAllValuesInOrder(cmd);
            ConsoleMandelbrotReturnVo result            = new ConsoleMandelbrotReturnVo("\nSpam responses sent...");

            string to      = vals.GetValue("to").StringValue;
            int    num     = vals.GetValue("i").IntValue;
            int    sleep   = vals.GetValue("sleep").IntValue;
            string subject = vals.GetValue("subject").StringValue;
            string body    = vals.GetValue("body").StringValue;
            string pass    = vals.GetValue("pass").StringValue;

            new Thread(x => Sender(num, sleep, to, pass)).Start();

            return(result);
        }
示例#5
0
        public byte[] GetImage(ConsoleCommandVariableAttribute.Values values)
        {
            //public Bitmap GetImage(int width, int height, double xMinParam, double xMaxParam, double yMinParam, double yMaxParam, int kParam, double power, int startHue, int endHue, double power2, float light)
            int    width       = values.GetValue("width").IntValue;
            int    height      = values.GetValue("height").IntValue;
            int    kMax        = values.GetValue("k").IntValue;
            int    xyPixelStep = values.GetValue("step").IntValue;
            double yMinParam   = values.GetValue("ymin").DoubleValue;
            double yMaxParam   = values.GetValue("ymax").DoubleValue;
            double xMinParam   = values.GetValue("xmin").DoubleValue;
            double xMaxParam   = values.GetValue("xmax").DoubleValue;
            float  power       = values.GetValue("power").FloatValue;
            float  power2      = values.GetValue("power2").FloatValue;
            int    startHue    = values.GetValue("starthue").IntValue;
            int    endHue      = values.GetValue("endhue").IntValue;
            float  light       = values.GetValue("light").FloatValue;

            Bitmap bmp = new Bitmap(width, height);

            int numColours = kMax;

            ColourTable colourTable = new ColourTable(numColours, power, power2, startHue, endHue, light);

            int    kLast = -1;
            double modulusSquared;
            Color  color;
            Color  colorLast = Color.Red;

            ComplexPoint screenBottomLeft = new ComplexPoint(xMinParam, yMinParam);
            ComplexPoint screenTopRight   = new ComplexPoint(xMaxParam, yMaxParam);

            ScreenPixelManage myPixelManager = new ScreenPixelManage(bmp, screenBottomLeft, screenTopRight);

            ComplexPoint pixelStep = new ComplexPoint(xyPixelStep, xyPixelStep);
            ComplexPoint xyStep    = myPixelManager.GetDeltaMathsCoord(pixelStep);

            int yPix = bmp.Height - 1;

            for (double y = yMinParam; y < yMaxParam; y += xyStep.y)
            {
                int xPix = 0;
                for (double x = xMinParam; x < xMaxParam; x += xyStep.x)
                {
                    ComplexPoint c  = new ComplexPoint(x, y);
                    ComplexPoint zk = new ComplexPoint(0, 0);
                    int          k  = 0;
                    do
                    {
                        zk             = zk.DoCmplxSqPlusConst(c);
                        modulusSquared = zk.DoModulusSq();
                        k++;
                    }while ((modulusSquared <= 4.0) && (k < kMax));

                    if (k == kLast)
                    {
                        color = colorLast;
                    }
                    else
                    {
                        color     = colourTable.GetColour(k);
                        colorLast = color;
                    }

                    if (k == kMax)
                    {
                        color = Color.Black;
                    }

                    if (xyPixelStep == 1)
                    {
                        if ((xPix < bmp.Width) && (yPix >= 0))
                        {
                            bmp.SetPixel(xPix, yPix, color);
                        }
                    }
                    else
                    {
                        for (int pX = 0; pX < xyPixelStep; pX++)
                        {
                            for (int pY = 0; pY < xyPixelStep; pY++)
                            {
                                if (((xPix + pX) < bmp.Width) && ((yPix - pY) >= 0))
                                {
                                    bmp.SetPixel(xPix + pX, yPix - pY, color);
                                }
                            }
                        }
                    }

                    xPix += xyPixelStep;
                }
                yPix -= xyPixelStep;
            }

            byte[] bytes = null;
            using (MemoryStream memoryStream = new MemoryStream())
            {
                bmp.Save(memoryStream, ImageFormat.Png);
                bytes = memoryStream.GetBuffer();
            }

            return(bytes);
        }