Ejemplo n.º 1
0
 public void Add(Particle particle)
 {
     if (particle.Radius > 0)
     {
         Particles.Add(particle);
     }
 }
Ejemplo n.º 2
0
        public Particle CreateParticle(Vector3 pos, Vector3 velocity, Color tint, Vector3 direction)
        {
            Particle toAdd = new Particle
            {
                Velocity        = velocity,
                Scale           = Rand(Data.MinScale, Data.MaxScale),
                Angle           = Rand(Data.MinAngle, Data.MaxAngle),
                AngularVelocity = Rand(Data.MinAngular, Data.MaxAngular),
                LifeRemaining   = 1.0f,
                LightRamp       = tint,
                Position        = pos,
                TimeAlive       = 0.0f,
                Direction       = direction
            };

            toAdd.InstanceData = new InstanceData(Matrix.Identity, toAdd.LightRamp, true);

            Particles.Add(toAdd);

            if (toAdd.InstanceData != null)
            {
                Sprites[0].Add(toAdd.InstanceData);
            }
            return(toAdd);
        }
Ejemplo n.º 3
0
        public void Spawn(int number, float x, float y, float z, float xi, float yi, float zi)
        {
            Random rnd = new Random(Environment.TickCount);

            for (int i = 0; i < number; i++)
            {
                foreach (ParticleBase pbase in Bases)
                {
                    ParticleBase np = pbase.Clone();

                    np.W = W + rnd.Next(-( int )WJit / 2, ( int )WJit / 2);
                    np.H = H + rnd.Next(-( int )HJit / 2, ( int )HJit / 2);

                    np.X = x + rnd.Next(( int )-XSmall, ( int )XBig);
                    np.Y = y + rnd.Next(( int )-YSmall, ( int )YBig);

                    float zd = ZBig - ZSmall;

                    zd = zd * ( float )rnd.NextDouble( );

                    np.Z = z + zd;

                    np.Rot = rnd.Next(( int )SpawnRot1, ( int )SpawnRot2);

                    float xj = XIJit * (float)rnd.NextDouble();
                    float yj = YIJit * (float)rnd.NextDouble();
                    float zj = ZIJit * (float)rnd.NextDouble();

                    if (rnd.Next(0, 5) > 2)
                    {
                        xj = -xj;
                    }
                    if (rnd.Next(0, 5) > 2)
                    {
                        yj = -yj;
                    }
                    if (rnd.Next(0, 5) > 2)
                    {
                        zj = -zj;
                    }

                    float pw = (PowerBig - PowerSmall) * (float)rnd.NextDouble();

                    pw = PowerSmall + pw;

                    np.XI = (xi + xj) * pw;
                    np.YI = (yi + yj) * pw;
                    np.ZI = (zi + zj) * pw;

                    np.RI = rnd.Next(( int )-RJit, ( int )RJit);

                    //np.Life = 100.0f;
                    np.LifeRate = 0.03f;
                    np.LifeDrag = 0.98f;
                    np.Sys      = this;

                    Particles.Add(np);
                }
            }
        }
Ejemplo n.º 4
0
        public void AddParticle(Texture2D texture, int w, int h, float timer, float vx, float vy)
        {
            CEParticle p = new CEParticle(texture, w, h, timer, vx, vy);

            p.Rect = new Rectangle((int)Position.X, (int)Position.Y, p.Rect.Width, p.Rect.Height);
            Particles.Add(p);
        }
        public ParticleSwarmOptimization(int dimensions, int numberOfParticles, double[] upperBounds, double[] lowerBounds, Func <double[], double> CalculateFitness, Func <double, bool> TargetReached, FitnessMethod FitnessMethod, double velocityFactor = 0.5, double omega = 0.3, double fp = 1, double fg = 0.3)
        {
            if (dimensions < 1)
            {
                throw new ArgumentException("Dimensions should be > 1");
            }
            if (numberOfParticles < 1)
            {
                throw new ArgumentException("Number of particles should be > 1");
            }
            for (int i = 0; i < numberOfParticles; i++)
            {
                Particles.Add(new Particle(dimensions));
            }

            this.velocityFactor   = velocityFactor;
            this.omega            = omega;
            this.fp               = fp;
            this.fg               = fg;
            this.CalculateFitness = CalculateFitness;
            this.FitnessMethod    = FitnessMethod;
            this.TargetReached    = TargetReached;
            this.lowerBounds      = lowerBounds;
            this.upperBounds      = upperBounds;
            Initialize(upperBounds, lowerBounds);
        }
Ejemplo n.º 6
0
        public void HandleCollision(VoidShip voidShip, Particles particles)
        {
            Vector2 dist;
            Bullet  bullet;
            float   distSquared, hitDistSquared = (float)Math.Pow(voidShip.Radius + radius, 2);

            for (int i = 0; i < Count; i++)
            {
                bullet = array[(start + i) & 0x3FF];
                if (!bullet.Enabled)
                {
                    continue;
                }
                dist        = voidShip.Position - bullet.Position;
                distSquared = (dist.X * dist.X) + (dist.Y * dist.Y);
                if (distSquared < hitDistSquared)
                {
                    bullet.Visible = bullet.Enabled = false;
                    if (voidShip is VoidShipPC)
                    {
                        Sound.Fuzz((voidShip.Shield.Power * 2) - 1f);
                    }
                    if (voidShip.Shield.Power <= bullet.Power)
                    {
                        voidShip.Visible = voidShip.Enabled = false;
                        voidShip.Dead    = true;
                        particles.Add(voidShip.Position);
                    }
                    else
                    {
                        voidShip.Shield.Power -= bullet.Power;
                    }
                }
            }
        }
        public void Update(double dt, Dictionary <Guid, IShipController> controllers)
        {
            foreach (var ship in Ships)
            {
                if (!controllers.TryGetValue(ship.Uid, out var contr))
                {
                    contr = new EmptyShipController();
                }
                ship.Update(this, dt, contr);
            }

            for (int i = Ships.Count - 1; i >= 0; i--)
            {
                if (!Ships[i].Alive)
                {
                    Particles.Add(new Particle(Ships[i].Position, Ships[i].Model.ExplosionAnimation));
                    Ships[i] = Ships[Ships.Count - 1];
                    Ships.RemoveAt(Ships.Count - 1);
                }
            }

            for (int i = Particles.Count - 1; i >= 0; i--)
            {
                Particles[i].Update();
                if (Particles[i].IsFinished)
                {
                    Particles[i] = Particles[Particles.Count - 1];
                    Particles.RemoveAt(Particles.Count - 1);
                }
            }
        }
Ejemplo n.º 8
0
    void Start()
    {
        // Seeding random
        UnityEngine.Random.InitState(247943128);

        particles = new Particles(nbParticles);

        for (int i = 0; i < nbParticles; i++)
        {
            //Create particle i
            Vector3 particlePos = new Vector3(
                UnityEngine.Random.Range(-xRange, xRange),
                UnityEngine.Random.Range(-yRange, yRange)
                );

            GameObject go = Instantiate(particlePrefab, particlePos, Quaternion.identity);

            // Setting random mass from range [1f, 10f]
            float mass = UnityEngine.Random.Range(lowerMass, upperMass);

            // Setting velocity
            Vector3 velocity = (Vector3.up) * 10f;
            //particles[i].GetComponent<Particle>().velocity = (Vector3.up + Vector3.right) * 10f;

            // Setting color depending on mass / RED = high mass / BLUE = low mass
            float rangedMass = (((mass - lowerMass)) / (upperMass - lowerMass));
            Color current    = Color.Lerp(low, high, rangedMass);

            go.GetComponent <SpriteRenderer>().material.color = current;

            particles.Add(i, mass, velocity, Vector3.zero, particlePos, go);
        }
    }
Ejemplo n.º 9
0
        public Particle(Vector2 position, Vector2 direction)
        {
            Particles.Add(this);
            this.Position = position;
            this.Heading  = direction;

            Renderer = new ParticleRenderer(this);
        }
Ejemplo n.º 10
0
        public Particle SpawnParticle(string asset, Vector2 position)
        {
            var p = ContentLoader.Particles[asset].Clone();

            p.Position = position;
            Particles.Add(p);
            p.Spawn(this);
            return(p);
        }
Ejemplo n.º 11
0
        public void Emit()
        {
            lifedurationRange = Game1.NextFloat(Game1.random, 0.01f, lifeDurationMax);
            Particle tempParticle = new Particle(lifedurationRange, 1, Color.Black, this.position, 2, 1);

            tempParticle.Scale    = 5;
            tempParticle.Velocity = new Vector2(-1, 0);
            tempParticle.Speed    = .04f;
            Particles.Add(tempParticle);
        }
Ejemplo n.º 12
0
 public ParticleSwarm(PgnGames pgnGames, Parameters parameters, int particles, int winScale)
 {
     // Create particles at random locations.
     Particles = new Particles();
     _winScale = winScale;
     for (var particle = 0; particle < particles; particle++)
     {
         Particles.Add(new Particle(pgnGames, parameters.DuplicateWithRandomValues()));
     }
 }
        public void AddBlood(float x, float y, Vec2 vector, int count)
        {
            for (var i = 0; i < count; i++)
            {
                var velocity = GetV2((float)(Math.PI * 5d * Random.NextDouble()), (float)Random.NextDouble());
                var part     = new CircleParticle(15, 0.2f, x, y, velocity.X, velocity.Y, 0, 0.01f, 200);

                Particles.Add(part);
            }
        }
Ejemplo n.º 14
0
        public FluidParticle AddParticle(Vector2 position)
        {
            FluidParticle particle = new FluidParticle(position)
            {
                Index = Particles.Count
            };

            Particles.Add(particle);
            return(particle);
        }
Ejemplo n.º 15
0
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // Load shaders
            fxParticles = Content.Load <Effect>("Shaders\\Particles");
            fxParticles.Parameters["Texture"].SetValue(Content.Load <Texture2D>("Textures\\Particle"));

            box = new TransparentBox(GraphicsDevice);

            // load font
            font = Content.Load <SpriteFont>("Fonts\\Debug");

            this.Components.Add(fpsCounter = new FPSCounter(this));


            int pCount = 0;

            // Particles
            particles = new Particles(fxParticles);
            float pOffset = particles.ParticleRadius * 2;
            Color color   = Color.White;

            for (int x = 0; x < 5; x++)
            {
                for (int z = 0; z < 5; z++)
                {
                    for (int y = 0; y < 10; y++)
                    {
                        if (pCount >= 50 && pCount < 100)
                        {
                            color = Color.Red;
                        }
                        else if (pCount >= 100 && pCount < 150)
                        {
                            color = Color.Yellow;
                        }
                        else if (pCount >= 150 && pCount < 200)
                        {
                            color = Color.Green;
                        }
                        else if (pCount >= 200 && pCount < 250)
                        {
                            color = Color.CornflowerBlue;
                        }

                        particles.Add(new Particle(new Vector3(x, y, z) * pOffset, particles.GetRandomVelocity(), color));
                        pCount++;
                    }
                }
            }

            color = Color.Red;
        }
Ejemplo n.º 16
0
        public override void Explode(int qty = 100)
        {
            base.Explode();


            while (Busy)
            {
                ;
            }
            Busy = true;
            lock (Particles)
            {
                Particles.Clear();

                for (int i = 0; i < qty; i++)
                {
                    double angle = rng.NextDouble() * 2 * Math.PI;
                    double xVel  = (rng.NextDouble() * ExplosionMag) * Math.Cos(angle);
                    double yVel  = (rng.NextDouble() * ExplosionMag) * Math.Sin(angle);

                    Particles.Add(new Particle2D(Color,
                                                 (Vector2D)Position.Clone(),
                                                 new Vector2D(xVel, yVel)));
                    //Console.WriteLine("Added a particle, now there are " + Particles.Count);
                }
            }
            Busy = false;

            /*
             * Task.Factory.StartNew(() =>
             * {
             *  while (Busy) ;
             *  Busy = true;
             *  lock (Particles)
             *  {
             *      Particles.Clear();
             *
             *      for (int i = 0; i < qty; i++)
             *      {
             *          double angle = rng.NextDouble() * 2 * Math.PI;
             *          double xVel = (rng.NextDouble() * ExplosionMag) * Math.Cos(angle);
             *          double yVel = (rng.NextDouble() * ExplosionMag) * Math.Sin(angle);
             *
             *          Particles.Add(new Particle2D(Color,
             *              ((Vector2D)Position.Clone()),
             *              new Vector2D(xVel, yVel),
             *              ((Vector2D)Acceleration.Clone())));
             *          //Console.WriteLine("Added a particle, now there are " + Particles.Count);
             *      }
             *  }
             *  Busy = false;
             * });
             */
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Initialise a ParticleMotionComponent, generating particles from the
 /// specified nodes.
 /// </summary>
 /// <param name="nodes"></param>
 public ParticleGravityComponent(NodeCollection nodes)
 {
     foreach (Node node in nodes)
     {
         if (!node.HasData <Particle>())
         {
             node.Data.Add(new Particle(node));
         }
         Particles.Add(node.GetData <Particle>());
     }
 }
Ejemplo n.º 18
0
        public void Update(GameTime gameTime)
        {
            //Spawning Particles
            if (timeElapsed <= emmisionRate)
            {
                timeElapsed += gameTime.ElapsedGameTime.TotalMilliseconds;
            }
            else
            {
                //Console.WriteLine("Spawned Particle");
                switch (eShape)
                {
                case EmmisionShape.Circle:
                    break;

                case EmmisionShape.Line:
                    Particles.Add(new Particle(new Vector2(origin.X + ran.Next(0, emmisionRadius), origin.Y), initialVelocity + (float)(ran.NextDouble() - 0.5) * initialVelocityRandom, texture, particleStartingSize));
                    break;

                case EmmisionShape.Box:
                    Particles.Add(new Particle(new Vector2(origin.X + ran.Next(0, emmisionRadius), origin.Y + ran.Next(0, emmisionRadius)), initialVelocity + (float)(ran.NextDouble() - 0.5) * initialVelocityRandom, texture, particleStartingSize));
                    break;

                default:
                    break;
                }
                timeElapsed = 0;
            }

            //Updating the Particles
            if (Particles.Count != 0)
            {
                //foreach (Particle p in Particles)
                for (int i = 0; i < Particles.Count; i++)
                {
                    //Particle Pos and Size adjustments
                    Particles[i].position += Particles[i].velocity * gameTime.ElapsedGameTime.Milliseconds; // new Point(forceOverTime.X * gameTime.ElapsedGameTime.Milliseconds, forceOverTime.Y * gameTime.ElapsedGameTime.Milliseconds); //Might have to * everything by "gT.ElapsedGameTime.Milliseconds"
                    Particles[i].velocity += new Vector2(forceOverTime.X, forceOverTime.Y);
                    Particles[i].size     += sizeOverTime;

                    //Particle Death
                    if (particleLifeTime < Particles[i].timeTillDeath)
                    {
                        Particles.Remove(Particles[i]);
                    }
                    else
                    {
                        Particles[i].timeTillDeath += 1;
                    }
                }
            }
        }
Ejemplo n.º 19
0
        public override void Explode(int qty = 2000)
        {
            Task.Factory.StartNew(() =>
            {
                Exploded = true;

                while (Busy)
                {
                    ;
                }
                Busy = true;
                lock (Particles)
                {
                    List <Tuple <int, int> > coords = sprite.Coordinates;  // Can take a while the first time that it executes
                    qty = (int)(coords.Count * (rng.NextDouble() * 0.2 + 0.1));
                    Particles.Clear();

                    for (int i = 0; i < qty; i++)
                    {
                        // Gets coordinate out of the list of coordinates supplied by the sprite
                        Tuple <int, int> coord;
                        do
                        {
                            int randomT = rng.Next(0, (coords.Count > 0) ? coords.Count - 1 : 0);
                            coord       = coords[randomT];
                            if (coord == null)
                            {
                                coords.RemoveAt(randomT);
                            }
                        } while (coord == null);

                        double targetX = coord.Item1 * sprite.Zoom;
                        double targetY = ExplosionPlacementRadius *
                                         coord.Item2 * sprite.Zoom;


                        double angle = (targetX == 0) ? (targetY > 0) ? Math.PI / 2 : (targetY == 0) ? 0 : -1 * Math.PI / 2 :                         // Coordinate is on the Y-Axis
                                       (targetY == 0) ? (targetX < 0) ? Math.PI : 0 :                                                                 // coordinate is on the X-axis
                                       (targetY > 0) ? (targetX > 0) ? Math.Atan(targetY / targetX) : -1 * (Math.PI - Math.Atan(targetY / targetX)) : // Coordinate is above the X-axis
                                       (targetX > 0) ? Math.Atan(targetY / targetX) : -1 * (Math.PI - Math.Atan(targetY / targetX));                  // Coordinate is below the X-axis
                        double xVel = (rng.NextDouble() * ExplosionMag) * Math.Cos(angle);
                        double yVel = -1 * (rng.NextDouble() * ExplosionMag) * Math.Sin(angle);

                        Particles.Add(new Particle2D(Color,
                                                     new Vector2D(((Vector2D)Position).X + targetX, ((Vector2D)Position).Y - targetY),
                                                     new Vector2D(xVel, yVel)));
                    }
                }
                Busy = false;
            });
        }
Ejemplo n.º 20
0
        private void GenerateParticle()
        {
            var random = new Random();

            Particles.Add(new Particle(
                              Transform.Position,
                              ParticleTextures[random.Next(ParticleTextures.Length)],
                              ParticleScale + ((float)random.NextDouble() - .5f) * ParticleScaleRandomness,
                              ParticleRotation + ((float)random.NextDouble() - .5f) * ParticleRotationRandomness,
                              LifeTime,
                              ParticleVelocity + new Vector2(((float)random.NextDouble() - .5f) * ParticleVelocityRandomness.X, ((float)random.NextDouble() - .5f) * ParticleVelocityRandomness.Y),
                              ParticleAngularVelocity + ((float)random.NextDouble() - .5f) * ParticleAngularVelocityRandomness,
                              ParticleColour
                              ));
        }
Ejemplo n.º 21
0
        private void UpdateParticles()
        {
            foreach (Particle o in DeadParticles)
            {
                o.Die(this);
                Particles.Remove(o);
            }
            DeadParticles.Clear();

            foreach (Particle o in NewParticles)
            {
                Particles.Add(o);
            }
            NewParticles.Clear();
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Creates the particles.
        /// This method is made to be overwriten
        /// By customising this function, the particle
        /// behavior can be customized
        /// </summary>
        protected virtual void CreateParticles(int number, TimeSpan lifeTime)
        {
            for (int i = 0; i < number; ++i)
            {
                DrawableParticle particle = new DrawableParticle(lifeTime, ParticleInitialVelocity, ParticleForce,
                                                                 ParticleLifeTimeRandomizer, ParticleVelocityRandomizer, ParticleForceRandomizer,
                                                                 ParticleAlphaPercent)
                {
                    Origin = new Vector2(0.5f * ParticleTexture.Width, 0.5f * ParticleTexture.Height),
                    Scale  = ParticleScale
                };
                particle.Tint = Tint;

                Particles.Add(particle);
            }
        }
Ejemplo n.º 23
0
        public Particle CreateParticle(IRectangle hitBox)
        {
            var body = _physics.CreateBody(new BoxCollider(hitBox),
                                           new PhysicalMaterial
            {
                Absorption        = 0.01,
                Restoring         = 0.01,
                Viscosity         = 1.0,
                Density           = 1000,
                Friction          = 0.2,
                MovementEmitter   = false,
                MovementRecipient = true,
            });
            var entity = new Particle(this, body);

            Particles.Add(entity);
            return(entity);
        }
Ejemplo n.º 24
0
        public void Trigger(int num, Vector3 origin, Color tint)
        {
            for (int i = 0; i < num; i++)
            {
                if (Particles.Count < Data.MaxParticles)
                {
                    Particle toAdd = new Particle();

                    bool sampleFound = false;

                    Vector3 sample = new Vector3(99999, 99999, 9999);

                    while (!sampleFound)
                    {
                        sample = RandVec(Data.EmissionRadius);

                        if (sample.Length() < Data.EmissionRadius)
                        {
                            sampleFound = true;
                        }
                    }


                    toAdd.Position = sample + origin;
                    toAdd.Velocity = (sample);
                    toAdd.Velocity.Normalize();
                    toAdd.Velocity *= Data.EmissionSpeed;

                    toAdd.Scale           = Rand(Data.MinScale, Data.MaxScale);
                    toAdd.Angle           = Rand(Data.MinAngle, Data.MaxAngle);
                    toAdd.AngularVelocity = Rand(Data.MinAngular, Data.MaxAngular);
                    toAdd.LifeRemaining   = 1.0f;
                    toAdd.Tint            = tint;
                    toAdd.InstanceData    = new InstanceData(Matrix.Identity, toAdd.Tint, true);

                    Particles.Add(toAdd);

                    if (toAdd.InstanceData != null)
                    {
                        Sprites.Add(toAdd.InstanceData);
                    }
                }
            }
        }
Ejemplo n.º 25
0
        private void CreateSwarm()
        {
            var r = (decimal)random.NextDouble();

            for (int i = 0; i < N; i++)
            {
                var firstValue = Manager.RandomDecimal();
                var valueModel = new ValueModel(firstValue, Manager.CalculateFx(firstValue));
                Particles.Add(new Particle
                {
                    Values = new List <ValueModel>()
                    {
                        valueModel
                    },
                    Bi = valueModel,
                    Bg = valueModel
                });
            }
        }
Ejemplo n.º 26
0
        public void Update(Level level, float deltaTime)
        {
            _shaderTimer += deltaTime;

            if (_headerTimer < _headerTime)
            {
                _headerTimer += deltaTime;
            }

            Entities.Update(level, deltaTime);
            _waterView.Update(deltaTime);
            Particles.Update(deltaTime);

            if (_showLoseScreen)
            {
                _loseScreenOpacity += 0.3f * deltaTime;
                _loseScreenOpacity  = MathHelper.Min(_loseScreenOpacity, 1f);
            }

            if (_fadeOut)
            {
                _fadeOutOpacity += 1f * deltaTime;
                _fadeOutOpacity  = MathHelper.Min(_fadeOutOpacity, 1f);
            }

            _flickerTimer += deltaTime;
            if (_flickerTimer >= _flickerTime)
            {
                _flickerTimer -= _flickerTime;
                _lightRadius   = _radius + (float)_random.NextDouble() * 20f;
            }

            for (int i = 0; i < level.WindChannels.Count; i++)
            {
                float channel = level.WindChannels[i];

                Particles.Add(_particleFactory.CreateWindParticle(
                                  new Vector2((i % 2 == 0 ? -500f : 500f) + level.TileMap.Width * GraphicsConstants.TileSize * (float)_random.NextDouble(),
                                              GraphicsConstants.PhysicsToView(channel) - GraphicsConstants.TileSize * 4f + (float)_random.NextDouble() * 8f * GraphicsConstants.TileSize),
                                  new Vector2(i % 2 == 0 ? 1f : -1f, 0f)));
            }
        }
        public void InitializeParticles()
        {
            Particles.Clear();

            TSPParticle firstParticle = TSPParticle.RandomGenerate(this, Map);

            Particles.Add(firstParticle);
            gBest = (TSPParticle)firstParticle.Clone();

            // Inicializar cada Partícula
            for (int pCount = 1; pCount < ParticleCount; ++pCount)
            {
                TSPParticle newParticle = TSPParticle.RandomGenerate(this, Map);
                Particles.Add(newParticle);
                if (newParticle.Fitness < gBest.Fitness)
                {
                    gBest = (TSPParticle)newParticle.Clone();
                }
            }
        }
Ejemplo n.º 28
0
        private void MyControlDeviceOnDestTriggeredEvent(object sender, ControlDevice.TriggerEventArgs e)
        {
            Particles.Add(new Particle
            {
                X        = (int)(e.FloatX * myControlDevice.GridWidth),
                Y        = (int)(e.FloatY * myControlDevice.GridHeight),
                Distance = 0,
                Strength = 1,
                R        = 255, G = 0, B = 255
            });

            Particles.Add(new Particle
            {
                X        = (int)(e.FloatX * myControlDevice.GridWidth),
                Y        = (int)(e.FloatY * myControlDevice.GridHeight),
                Distance = 1,
                Strength = 1,
                R        = 0, G = 0, B = 0
            });
        }
Ejemplo n.º 29
0
        internal XSModelGroup(XmlSchemaGroupBase groupBase)
            : this()
        {
            _group = groupBase;

            if (_group.Annotation is XmlSchemaAnnotation annotation)
            {
                _annotation = XMLSchemaSerializer.CreateXSAnnotation(annotation);
                _annotation.BindToContainer(RootContainer, this);
            }

            if (groupBase is XmlSchemaAll)
            {
                _compositor = XSCompositor.All;
            }

            else if (groupBase is XmlSchemaChoice)
            {
                _compositor = XSCompositor.Choice;
            }

            else if (groupBase is XmlSchemaSequence)
            {
                _compositor = XSCompositor.Sequence;
            }

            Particles.Inserted -= Particles_Inserted;

            foreach (XmlSchemaObject item in _group.Items)
            {
                IXSComponent component = XMLSchemaSerializer.CreateInstance(item);
                component.BindToContainer(RootContainer, this);
                Particles.Add(component);
                Components.Add(component);
            }

            Particles.Inserted += Particles_Inserted;
        }
Ejemplo n.º 30
0
        public double CalcMax(int numOfFormula)
        {
            Random rand = new Random();

            for (int i = 0; i < SwarmSize; i++)
            {
                Particles.Add(new Particle(0, 0, MinValue + rand.NextDouble() * (MaxValue - MinValue)));
            }
            GlobalMaxSpeed = Particles[0].LocalMaxSpeed;
            foreach (Particle p in Particles)
            {
                if (functionValue(p.X, numOfFormula) > functionValue(p.LocalMaxSpeed, numOfFormula))
                {
                    p.LocalMaxSpeed = p.X;
                    if (functionValue(p.LocalMaxSpeed, numOfFormula) > functionValue(GlobalMaxSpeed, numOfFormula))
                    {
                        GlobalMaxSpeed = p.LocalMaxSpeed;
                    }
                }
            }
            for (int i = 0; i < iter; i++)
            {
                //Подсчитать скорость
                foreach (Particle p in Particles)
                {
                    p.NextIterationMax(GlobalMaxSpeed, MinValue, MaxValue, numOfFormula);
                }
                foreach (Particle p in Particles)
                {
                    if (Swarm.functionValue(p.LocalMaxSpeed, numOfFormula) > Swarm.functionValue(GlobalMaxSpeed, numOfFormula))
                    {
                        GlobalMaxSpeed = p.LocalMaxSpeed;
                    }
                }
                //Вычислить лучшую скорость, значение функции в ней должно быть минимально
            }
            return(GlobalMaxSpeed);
        }
Ejemplo n.º 31
0
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // Load shaders
            fxParticles = Content.Load<Effect>("Shaders\\Particles");
            fxParticles.Parameters["Texture"].SetValue(Content.Load<Texture2D>("Textures\\Particle"));

            box = new TransparentBox(GraphicsDevice);

            // load font
            font = Content.Load<SpriteFont>("Fonts\\Debug");

            this.Components.Add(fpsCounter = new FPSCounter(this));

            int pCount = 0;
            // Particles
            particles = new Particles(fxParticles);
            float pOffset = particles.ParticleRadius * 2;
            Color color = Color.White;
            for (int x = 0; x < 5; x++)
            {
                for (int z = 0; z < 5; z++)
                {
                    for (int y = 0; y < 10; y++)
                    {
                        if (pCount >= 50 && pCount < 100)
                            color = Color.Red;
                        else if (pCount >= 100 && pCount < 150)
                            color = Color.Yellow;
                        else if (pCount >= 150 && pCount < 200)
                            color = Color.Green;
                        else if(pCount >= 200 && pCount < 250)
                            color = Color.CornflowerBlue;

                        particles.Add(new Particle(new Vector3(x, y, z) * pOffset, particles.GetRandomVelocity(), color));
                        pCount++;
                    }
                }
            }

            color = Color.Red;
        }