コード例 #1
0
        public ComplexPoint DoCmplxAdd(ComplexPoint arg)
        {
            x += arg.x;
            y += arg.y;

            return(this);
        }
コード例 #2
0
        public ComplexPoint GetAbsoluteMathsCoord(ComplexPoint pixelCoord)
        {
            ComplexPoint result = new ComplexPoint(
                (convConstX2 + pixelCoord.x) / convConstX1,
                (convConstY1 - pixelCoord.y) / convConstY2);

            return(result);
        }
コード例 #3
0
        public ComplexPoint GetDeltaMathsCoord(ComplexPoint pixelCoord)
        {
            ComplexPoint result = new ComplexPoint(
                pixelCoord.x / convConstX1,
                pixelCoord.y / convConstY2);

            return(result);
        }
コード例 #4
0
        public PixelCoord GetPixelCoord(ComplexPoint cmplxPoint)
        {
            PixelCoord result = new PixelCoord();

            result.xPixel = (int)(convConstX1 * cmplxPoint.x - convConstX2);
            result.yPixel = (int)(convConstY1 - convConstY2 * cmplxPoint.y);
            return(result);
        }
コード例 #5
0
        public ScreenPixelManage(Bitmap graphics, ComplexPoint screenBottomLeftCorner, ComplexPoint screenTopRightCorner)
        {
            convConstX1 = graphics.Width / (screenTopRightCorner.x - screenBottomLeftCorner.x);
            convConstX2 = convConstX1 * screenBottomLeftCorner.x;

            convConstY1 = graphics.Size.Height * (1.0 + screenBottomLeftCorner.y / (screenTopRightCorner.y - screenBottomLeftCorner.y));
            convConstY2 = graphics.Size.Height / (screenTopRightCorner.y - screenBottomLeftCorner.y);
        }
コード例 #6
0
        public ComplexPoint DoCmplxSq()
        {
            ComplexPoint result = new ComplexPoint(0, 0);

            result.x = x * x - y * y;
            result.y = 2 * x * y;

            return(result);
        }
コード例 #7
0
        public ComplexPoint DoCmplxSqPlusConst(ComplexPoint arg)
        {
            ComplexPoint result = new ComplexPoint(0, 0);

            result.x  = x * x - y * y;
            result.y  = 2 * x * y;
            result.x += arg.x;
            result.y += arg.y;
            return(result);
        }
コード例 #8
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);
        }