Ejemplo n.º 1
0
        /// <summary>
        /// Initializes the noise table
        /// </summary>
        /// <param name="_TableSize"></param>
        /// <param name="_GradientSeed"></param>
        /// <param name="_PermutationSeed"></param>
        public void             Init(int _TableSize, int _GradientSeed, int _PermutationSeed)
        {
            m_NoiseSize = (uint)_TableSize;
            Random GradientRNG    = new Random(_GradientSeed);
            Random PermutationRNG = new Random(_PermutationSeed);

            // Build the noise & permutation tables
            m_NoiseTable       = new WMath.Vector4D[2 * m_NoiseSize];
            m_PermutationTable = new uint[2 * m_NoiseSize];

            for (uint SlotIndex = 0; SlotIndex < m_NoiseSize; SlotIndex++)
            {
                m_NoiseTable[SlotIndex] = m_NoiseTable[m_NoiseSize + SlotIndex] = new WMath.Vector4D(2.0f * (float)GradientRNG.NextDouble() - 1.0f,
                                                                                                     2.0f * (float)GradientRNG.NextDouble() - 1.0f,
                                                                                                     2.0f * (float)GradientRNG.NextDouble() - 1.0f,
                                                                                                     2.0f * (float)GradientRNG.NextDouble() - 1.0f);
                m_PermutationTable[SlotIndex] = SlotIndex;
            }

            // Mix the permutation table by exchanging indices at random
            for (uint SlotIndex = 0; SlotIndex < m_NoiseSize; SlotIndex++)
            {
                uint RandomIndex = (uint)PermutationRNG.Next((int)m_NoiseSize);

                uint Temp = m_PermutationTable[RandomIndex];
                m_PermutationTable[RandomIndex] = m_PermutationTable[SlotIndex];
                m_PermutationTable[SlotIndex]   = Temp;
            }

            // Finalize the permutation table by doubling its size
            for (uint SlotIndex = 0; SlotIndex < m_NoiseSize; SlotIndex++)
            {
                m_PermutationTable[m_NoiseSize + SlotIndex] = m_PermutationTable[SlotIndex];
            }
        }
Ejemplo n.º 2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            e.Graphics.FillRectangle(Brushes.Black, 0, 0, Width, Height);
            if (m_SourceImage != null)
            {
                e.Graphics.DrawImage(m_SourceImage, ImageClientRectangle, new RectangleF(0, 0, m_SourceImage.Width, m_SourceImage.Height), GraphicsUnit.Pixel);
            }


            // Show custom swatches' location
            RectangleF R = ImageClientRectangle;

            for (int SwatchIndex = 0; SwatchIndex < m_CustomSwatches.Length; SwatchIndex++)
            {
                if (m_CustomSwatches[SwatchIndex] != null)
                {
                    WMath.Vector4D Location = m_CustomSwatches[SwatchIndex];

                    PointF TopLeft     = new PointF(R.Left + Location.x * R.Width, R.Top + Location.y * R.Height);
                    PointF BottomRight = new PointF(R.Left + Location.z * R.Width, R.Top + Location.w * R.Height);

                    e.Graphics.DrawRectangle(Pens.Red, TopLeft.X, TopLeft.Y, 1 + BottomRight.X - TopLeft.X, 1 + BottomRight.Y - TopLeft.Y);
                    e.Graphics.DrawString(SwatchIndex.ToString(), Font, Brushes.Red, 0.5f * (TopLeft.X + BottomRight.X - Font.Height), 0.5f * (TopLeft.Y + BottomRight.Y - Font.Height));
                }
            }
        }
Ejemplo n.º 3
0
 protected float Dot(WMath.Vector4D _Op0, float _Op1x, float _Op1y, float _Op1z, float _Op1w)
 {
     return(_Op0.x * _Op1x + _Op0.y * _Op1y + _Op0.z * _Op1z + _Op0.w * _Op1w);
 }