Exemplo n.º 1
0
        /// <summary>
        ///     The constructor.
        /// </summary>
        public UniverseDisplayCell(int paneWidth, int paneHeight, Label label)
        {
            int width = paneWidth
                        /Settings.Default.Zoom;
            int height = paneHeight
                         /Settings.Default.Zoom;

            _label = label;

            var universe = new UniverseHolder(height, width, 3);
            var physics = new MergePhysics(universe);

            universe.Randomize(_rnd);
            physics.Randomize();

            _universeRunner = new UniverseRunner(universe, physics);
            _visualizer = new UniverseVisualizer(universe,
                Settings.Default.Zoom);

            _bitmap = new WriteableBitmap(
                paneWidth,
                paneHeight,
                96,
                96,
                PixelFormats.Bgr32,
                null);
        }
Exemplo n.º 2
0
        /**
         * {@inheritDoc}
         */

        public Object Clone()
        {
            var result = new UniverseHolder(Height, Width,
                                            _cellSize);

            result.Copy(this);
            return(result);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Copy another universe into this one.
 /// </summary>
 /// <param name="source">The source universe.</param>
 public void Copy(UniverseHolder source)
 {
     for (int row = 0; row < Height; row++)
     {
         for (int col = 0; col < Width; col++)
         {
             for (int i = 0; i < _cellSize; i++)
             {
                 _data[row][col].Data[i] = source.Get(row, col).Data[i];
             }
         }
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Compare this universe to another and return the difference.  A value of zero indicates an identical universe.
        /// The lower the value, the more similar.
        /// </summary>
        /// <param name="otherUniverse">The other universe.</param>
        /// <returns>The difference between the universes.</returns>
        public double Compare(UniverseHolder otherUniverse)
        {
            int result = 0;
            int total  = 0;

            for (int row = 0; row < otherUniverse.Height; row++)
            {
                for (int col = 0; col < otherUniverse.Width; col++)
                {
                    int d1 = Math.Abs((int)(255 * Get(row, col).Avg));
                    int d2 = Math.Abs((int)(255 * otherUniverse.Get(row, col).Avg));
                    if (Math.Abs(d1 - d2) > 10)
                    {
                        result++;
                    }
                    total++;
                }
            }

            return(result / (double)total);
        }
Exemplo n.º 5
0
 /// <summary>
 ///     Construct the merge physics.
 /// </summary>
 /// <param name="theUniverse">The universe.</param>
 public MergePhysics(UniverseHolder theUniverse)
 {
     _data = new double[2*_colorTable.Length];
     _dataOrder = new int[_colorTable.Length];
     _universe = theUniverse;
 }
Exemplo n.º 6
0
        /// <inheritdoc />
        public void ProcessPixel(UniverseHolder outputUniverse, int row,
            int col)
        {
            double total = 0;
            int cnt = 0;

            for (int dir = 0; dir < _rowTransform.Length; dir++)
            {
                int otherRow = row + _rowTransform[dir];
                int otherCol = col + _colTransform[dir];
                if (_universe.IsValid(otherRow, otherCol))
                {
                    UniverseCell otherCell = _universe.Get(otherRow,
                        otherCol);
                    total += otherCell.Avg;
                    cnt++;
                }
            }

            total /= cnt;
            for (int i = 0; i < _colorTable.Length; i++)
            {
                int idx = _dataOrder[i];
                if (total < _data[idx*2])
                {
                    for (int j = 0; j < outputUniverse.CellSize; j++)
                    {
                        double d = _colorTable[idx][j]
                                   - _universe.Get(row, col).Data[j];
                        double pct = _data[1 + idx*2];
                        pct = (pct + 1.0)/2.0;
                        d *= pct;
                        outputUniverse.Add(row, col, j, d);
                    }
                    break;
                }
            }
        }
Exemplo n.º 7
0
 /// <summary>
 ///     The constructor.
 /// </summary>
 /// <param name="theUniverse">The universe.</param>
 /// <param name="thePhysics">The physics calculator.</param>
 public UniverseRunner(UniverseHolder theUniverse, IPhysics thePhysics)
 {
     _universe = theUniverse;
     _tempUniverse = (UniverseHolder) theUniverse.Clone();
     _physics = thePhysics;
 }
Exemplo n.º 8
0
        /// <summary>
        ///     The constructor.
        /// </summary>
        /// <param name="theUniverse">The universe.</param>
        /// <param name="theZoom">The zoom factor.</param>
        public UniverseVisualizer(UniverseHolder theUniverse, int theZoom)
        {
            _universe = theUniverse;

            _zoom = theZoom;
        }
Exemplo n.º 9
0
 /// <summary>
 ///     The constructor.
 /// </summary>
 /// <param name="theUniverse">The universe.</param>
 /// <param name="thePhysics">The physics calculator.</param>
 public UniverseRunner(UniverseHolder theUniverse, IPhysics thePhysics)
 {
     _universe     = theUniverse;
     _tempUniverse = (UniverseHolder)theUniverse.Clone();
     _physics      = thePhysics;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Copy another universe into this one.
 /// </summary>
 /// <param name="source">The source universe.</param>
 public void Copy(UniverseHolder source)
 {
     for (int row = 0; row < Height; row++)
     {
         for (int col = 0; col < Width; col++)
         {
             for (int i = 0; i < _cellSize; i++)
             {
                 _data[row][col].Data[i] = source.Get(row, col).Data[i];
             }
         }
     }
 }
Exemplo n.º 11
0
        /// <summary>
        /// Compare this universe to another and return the difference.  A value of zero indicates an identical universe.
        /// The lower the value, the more similar.
        /// </summary>
        /// <param name="otherUniverse">The other universe.</param>
        /// <returns>The difference between the universes.</returns>
        public double Compare(UniverseHolder otherUniverse)
        {
            int result = 0;
            int total = 0;
            for (int row = 0; row < otherUniverse.Height; row++)
            {
                for (int col = 0; col < otherUniverse.Width; col++)
                {
                    int d1 = Math.Abs((int) (255*Get(row, col).Avg));
                    int d2 = Math.Abs((int) (255*otherUniverse.Get(row, col).Avg));
                    if (Math.Abs(d1 - d2) > 10)
                    {
                        result++;
                    }
                    total++;
                }
            }

            return result/(double) total;
        }
Exemplo n.º 12
0
        /**
         * {@inheritDoc}
         */

        public Object Clone()
        {
            var result = new UniverseHolder(Height, Width,
                _cellSize);
            result.Copy(this);
            return result;
        }
Exemplo n.º 13
0
        /// <summary>
        ///     The constructor.
        /// </summary>
        /// <param name="theUniverse">The universe.</param>
        /// <param name="theZoom">The zoom factor.</param>
        public UniverseVisualizer(UniverseHolder theUniverse, int theZoom)
        {
            _universe = theUniverse;

            _zoom = theZoom;
        }