Ejemplo n.º 1
0
        public Simulation()
        {
            _environmentSeed = 20200803;
            _movementSeed    = 1622;
            _size            = new Size(256, 256);
            _strands         = new StrandCollection
            {
                Owner = this
            };
            _attractors = new ChemoeffectorCollection
            {
                Owner = this
            };
            _repellents = new ChemoeffectorCollection
            {
                Owner = this
            };
            _minimumAttractorStrength = 1;
            _maximumAttractorStrength = 128;
            _minimumRepellentStrength = 1;
            _maximumRepellentStrength = 128;
            _attractorCollisionAction = CollisionAction.ReduceSelf;
            _repellentCollisionAction = CollisionAction.ReduceOther;
            _respawnAttractor         = true;
            _wrap = true;

            this.Reset();
        }
Ejemplo n.º 2
0
        private void ProcessCollision(Strand strand, Chemoeffector chemoeffector, ChemoeffectorCollection container, CollisionAction action, Action createNew)
        {
            if (action == CollisionAction.ReduceSelf)
            {
                chemoeffector.Strength--;
                strand.Strength++;
            }
            else if (action == CollisionAction.ReduceOther)
            {
                strand.Strength--;
            }

            if (chemoeffector.Strength <= 0 || action == CollisionAction.DestroySelf)
            {
                container.Remove(chemoeffector);

                createNew();
            }

            if (strand.Strength <= 0 || action == CollisionAction.DestroyOther)
            {
                _strands.Remove(strand);
            }
        }
Ejemplo n.º 3
0
        private Chemoeffector GetStrongestChemoeffector(Strand strand, ChemoeffectorCollection container)
        {
            Chemoeffector result;
            int           strength;

            result   = null;
            strength = 0;

            for (int i = 0; i < container.Count; i++)
            {
                Chemoeffector chemoeffector;

                chemoeffector = container[i];

                if (Geometry.DoesPointIntersectCircle(strand.Position, chemoeffector.Position, (chemoeffector.Strength / 2) + 4) && // add a bit of a buffer so even the smallest have a gradient
                    chemoeffector.Strength > strength)
                {
                    strength = chemoeffector.Strength;
                    result   = chemoeffector;
                }
            }

            return(result);
        }