Esempio n. 1
0
        private void miGDIPerlin_Click(object sender, System.EventArgs e)
        {
            if (m_spProcedural == null)
            {
                #region Procedural noise bitmap

                Random rnd = new Random();
                Endogine.Procedural.Noise procedural = null;
                switch (rnd.Next(4))
                {
                case 0:
                    procedural           = new Endogine.Procedural.Plasma();
                    procedural.Decay     = 0.5f;
                    procedural.Frequency = 0.1f;
                    procedural.Octaves   = 3;
                    break;

                case 1:
                    procedural           = new Endogine.Procedural.Wood();
                    procedural.Decay     = 0.5f;
                    procedural.Frequency = 0.1f;
                    procedural.Octaves   = 3;
                    ((Endogine.Procedural.Wood)procedural).NumCircles = 5;
                    ((Endogine.Procedural.Wood)procedural).Turbulence = 0.3f;
                    break;

                case 2:
                    procedural           = new Endogine.Procedural.Marble();
                    procedural.Decay     = 0.5f;
                    procedural.Frequency = 0.1f;
                    procedural.Octaves   = 3;
                    ((Endogine.Procedural.Marble)procedural).Periods    = new EPointF(15, 30);
                    ((Endogine.Procedural.Marble)procedural).Turbulence = 3.3f;
                    break;

                case 3:
                    procedural           = new Endogine.Procedural.Noise();
                    procedural.Decay     = 0.5f;
                    procedural.Frequency = 1f;
                    procedural.Octaves   = 3;
                    break;
                }


                Bitmap   bmp;
                Graphics g;
                bmp = new Bitmap(200, 200);
                Endogine.BitmapHelpers.Canvas canvas = Endogine.BitmapHelpers.Canvas.Create(bmp);

                //create a color table that makes it look like lakes and mountains:
                System.Collections.SortedList aColors = new System.Collections.SortedList();
                aColors.Add(0.0, Color.FromArgb(0, 0, 190));
                aColors.Add(0.1, Color.FromArgb(0, 0, 255));
                aColors.Add(0.11, Color.FromArgb(0, 200, 0));
                aColors.Add(0.5, Color.FromArgb(150, 100, 0));
                aColors.Add(1.0, Color.FromArgb(255, 255, 255));
                procedural.SetColors(aColors);
                //write pixels to bitmap:
                canvas.Locked = true;
                procedural.WriteToBitmap(canvas);
                canvas.Locked = false;
                #endregion

                #region Create gradient bitmap
                //Create two gradients using GDI+, and merge them with my CopyPixels for special effects
                Bitmap bmpGradient = new Bitmap(200, 200);
                g = Graphics.FromImage(bmpGradient);
                LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(4, 0, bmpGradient.Width, bmpGradient.Height), Color.FromArgb(255, 0, 0), Color.FromArgb(0, 255, 0), 0f);
                g.FillRectangle(brush, brush.Rectangle);

                Bitmap bmp2 = new Bitmap(bmpGradient.Width, bmpGradient.Height);
                brush = new LinearGradientBrush(new Rectangle(0, 0, bmp2.Width, bmp2.Height), Color.FromArgb(0, 0, 255), Color.FromArgb(0, 0, 0), (float)90);
                Graphics g2 = Graphics.FromImage(bmp2);
                g2.FillRectangle(brush, brush.Rectangle);

                RasterOps.CopyPixels(bmpGradient, bmp2, (int)RasterOps.ROPs.AddPin, 255);
                RasterOps.CopyPixels(bmp, bmpGradient, (int)RasterOps.ROPs.Lightest, 255);
                g.Dispose();
                #endregion

                MemberSpriteBitmap mb = new MemberSpriteBitmap(bmp);

                m_spProcedural         = new Sprite();
                m_spProcedural.Name    = "Procedural";
                m_spProcedural.Member  = mb;
                m_spProcedural.Scaling = new EPointF(2, 2);
                m_spProcedural.Ink     = 0;
            }
            else
            {
                //TODO: the bitmap will still remain in memory, should have an "autodispose" option,
                //so that resources gets disposed when no sprites are using them
                m_spProcedural.Dispose();
                m_spProcedural = null;
            }
        }
Esempio n. 2
0
        private void miGDIPerlin_Click(object sender, System.EventArgs e)
        {
            if (m_spProcedural == null)
            {
                #region Procedural noise bitmap

                Random rnd = new Random();
                Endogine.Procedural.Noise procedural = null;
                switch (rnd.Next(4))
                {
                    case 0:
                        procedural = new Endogine.Procedural.Plasma();
                        procedural.Decay = 0.5f;
                        procedural.Frequency = 0.1f;
                        procedural.Octaves = 3;
                        break;
                    case 1:
                        procedural = new Endogine.Procedural.Wood();
                        procedural.Decay = 0.5f;
                        procedural.Frequency = 0.1f;
                        procedural.Octaves = 3;
                        ((Endogine.Procedural.Wood)procedural).NumCircles = 5;
                        ((Endogine.Procedural.Wood)procedural).Turbulence = 0.3f;
                        break;
                    case 2:
                        procedural = new Endogine.Procedural.Marble();
                        procedural.Decay = 0.5f;
                        procedural.Frequency = 0.1f;
                        procedural.Octaves = 3;
                        ((Endogine.Procedural.Marble)procedural).Periods = new EPointF(15, 30);
                        ((Endogine.Procedural.Marble)procedural).Turbulence = 3.3f;
                        break;
                    case 3:
                        procedural = new Endogine.Procedural.Noise();
                        procedural.Decay = 0.5f;
                        procedural.Frequency = 1f;
                        procedural.Octaves = 3;
                        break;
                }

                Bitmap bmp;
                Graphics g;
                bmp = new Bitmap(200, 200);
                Endogine.BitmapHelpers.Canvas canvas = Endogine.BitmapHelpers.Canvas.Create(bmp);

                //create a color table that makes it look like lakes and mountains:
                System.Collections.SortedList aColors = new System.Collections.SortedList();
                aColors.Add(0.0, Color.FromArgb(0, 0, 190));
                aColors.Add(0.1, Color.FromArgb(0, 0, 255));
                aColors.Add(0.11, Color.FromArgb(0, 200, 0));
                aColors.Add(0.5, Color.FromArgb(150, 100, 0));
                aColors.Add(1.0, Color.FromArgb(255, 255, 255));
                procedural.SetColors(aColors);
                //write pixels to bitmap:
                canvas.Locked = true;
                procedural.WriteToBitmap(canvas);
                canvas.Locked = false;
                #endregion

                #region Create gradient bitmap
                //Create two gradients using GDI+, and merge them with my CopyPixels for special effects
                Bitmap bmpGradient = new Bitmap(200, 200);
                g = Graphics.FromImage(bmpGradient);
                LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(4, 0, bmpGradient.Width, bmpGradient.Height), Color.FromArgb(255, 0, 0), Color.FromArgb(0, 255, 0), 0f);
                g.FillRectangle(brush, brush.Rectangle);

                Bitmap bmp2 = new Bitmap(bmpGradient.Width, bmpGradient.Height);
                brush = new LinearGradientBrush(new Rectangle(0, 0, bmp2.Width, bmp2.Height), Color.FromArgb(0, 0, 255), Color.FromArgb(0, 0, 0), (float)90);
                Graphics g2 = Graphics.FromImage(bmp2);
                g2.FillRectangle(brush, brush.Rectangle);

                RasterOps.CopyPixels(bmpGradient, bmp2, (int)RasterOps.ROPs.AddPin, 255);
                RasterOps.CopyPixels(bmp, bmpGradient, (int)RasterOps.ROPs.Lightest, 255);
                g.Dispose();
                #endregion

                MemberSpriteBitmap mb = new MemberSpriteBitmap(bmp);

                m_spProcedural = new Sprite();
                m_spProcedural.Name = "Procedural";
                m_spProcedural.Member = mb;
                m_spProcedural.Scaling = new EPointF(2, 2);
                m_spProcedural.Ink = 0;
            }
            else
            {
                //TODO: the bitmap will still remain in memory, should have an "autodispose" option,
                //so that resources gets disposed when no sprites are using them
                m_spProcedural.Dispose();
                m_spProcedural = null;
            }
        }