Example #1
0
        public Point get_menos_concurrido(Vector location)
        {
            int   min   = Logica.nro_boids + 10;
            int   n     = 0;
            Point final = objetivos [0];

            foreach (Point p in objetivos)
            {
                n = 0;
                foreach (Boid b in Logica.objects)
                {
                    if (b.Location.distance(new Vector(p.X, Logica.mapeo(p.Y))) <= Constantes.radio_objetivos * 2)
                    {
                        n++;
                    }
                }
                if (n < min)
                {
                    final = p;
                    min   = n;
                }
                else if (n == min)
                {
                    if (location.distance(new Vector(p.X, Logica.mapeo(p.Y))) < location.distance(new Vector(final.X, Logica.mapeo(final.Y))))
                    {
                        final = p;
                    }
                }
            }
            return(final);
        }
Example #2
0
        private Vector cohesion(BoidCollection boids)         //promedio de las posiciones de los vecinos dentro del radio
        {
            Vector sum       = new Vector(0, 0);
            int    neighbors = 0;
            int    n         = 0;

            if (Logica.puntos_objetivo.Count > 0 && objetivo < Logica.puntos_objetivo.Count)
            {
                Vector nuevo = new Vector(intermedio.X, Logica.mapeo(intermedio.Y));
                sum.add(nuevo);
                neighbors++;
            }

            else
            {
                foreach (Boid b in boids)
                {
                    double d = Location.distance(b.Location);
                    if ((Logica.mouse && n == 0) || (n != 0 && d > 0 && d < Logica.radioCoh))
                    {
                        sum.add(b.Location);
                        neighbors++;
                    }
                    n++;
                }
            }

            if (neighbors > 0)
            {
                sum.div(neighbors);
                return(seek(sum));
            }

            return(sum);
        }
Example #3
0
        public static bool avoid_rectangulo(double newx, double newy, Vector velocity, Cairo.Rectangle r, Vector location)
        {
            bool reboto;

            reboto = Logica.avoid_linea(newx, newy, velocity, new Cairo.Rectangle(r.X, r.Y, r.X + r.Width, r.Y), location);
            if (reboto)
            {
                return(true);
            }
            reboto = Logica.avoid_linea(newx, newy, velocity, new Cairo.Rectangle(r.X + r.Width, r.Y, r.X + r.Width, r.Y + r.Height), location);
            if (reboto)
            {
                return(true);
            }
            reboto = Logica.avoid_linea(newx, newy, velocity, new Cairo.Rectangle(r.X + r.Width, r.Y + r.Height, r.X, r.Y + r.Height), location);
            if (reboto)
            {
                return(true);
            }
            reboto = Logica.avoid_linea(newx, newy, velocity, new Cairo.Rectangle(r.X, r.Y + r.Height, r.X, r.Y), location);
            if (reboto)
            {
                return(true);
            }
            return(false);
        }
        protected void OnButtonOkPressed(object sender, EventArgs e)
        {
            Constantes.escenario  = false;
            Constantes.simulacion = true;

            mainw.tb1.Sensitive                   = true;
            mainw.tb2.Sensitive                   = false;
            mainw.nivel.Sensitive                 = false;
            mainw.etiquetaNivel.Sensitive         = false;
            mainw.intermitencia.Sensitive         = false;
            mainw.etiquetaIntermitencia.Sensitive = false;
            mainw.calor.Active       = false;
            mainw.trayectoria.Active = false;

            Logica.nro_boids             = (int)this.spinbutton1.Value;
            Constantes.lapsos            = (int)this.spinbuttonLapsos.Value;
            Constantes.iteraciones_lapso = (int)this.spinbuttonIteraciones.Value;
            Constantes.tiempos_boids.Clear();
            Constantes.tiempo            = 0;  //Comienzo a contar las iteraciones de nuevo
            Constantes.iteraciones_total = 0;

            Constantes.resetEstadisticas();

            Logica.crear_boids();
            Logica.play                 = true;
            mainw.tb1.Sensitive         = true;
            mainw.grilla.Active         = false;
            mainw.calor.Active          = false;
            mainw.estadistica.Sensitive = true;
            this.Destroy();
        }
Example #5
0
 public override void calculateVelocity(BoidCollection s, DrawingArea area)
 {
     area.GetPointer(out x, out y);
     y               = (int)Logica.mapeo(y);
     Velocity.X      = x - Location.X;
     Velocity.Y      = y - Location.Y;
     LocationNueva.X = x;
     LocationNueva.Y = y;
 }
Example #6
0
        private void update_objetivo()
        {
            if (Logica.puntos_objetivo.Count > 0 && objetivo < Logica.puntos_objetivo.Count)
            {
                double distancia = Location.distance(new Vector(intermedio.X, Logica.mapeo(intermedio.Y)));
                if (distancia <= Constantes.radio_objetivos)                   //ver cuando cambiar el objetivo
                {
                    objetivo++;
                    if (objetivo < Logica.puntos_objetivo.Count && Logica.puntos_objetivo [objetivo].Objetivos().Count > 0)
                    {
                        if (criterio == 0)
                        {
                            intermedio = Logica.puntos_objetivo [objetivo].get_cercano(Location);
                        }
                        else if (criterio == 1)
                        {
                            intermedio = Logica.puntos_objetivo [objetivo].get_menos_concurrido(Location);
                        }
                        else
                        {
                            intermedio = Logica.puntos_objetivo [objetivo].get_random(random);
                        }
                    }

                    else
                    {
                        objetivo = 0;
                        actualizarMetricas();

                        if (Constantes.simulacionContinua)
                        {
                            ubicar_boid_punto_inicio();
                            trayectoria.Clear();
                        }
                        else
                        {
                            llego = true;
                        }

                        if (criterio == 0)
                        {
                            intermedio = Logica.puntos_objetivo [objetivo].get_cercano(LocationNueva);
                        }
                        else if (criterio == 1)
                        {
                            intermedio = Logica.puntos_objetivo[objetivo].get_menos_concurrido(LocationNueva);
                        }
                        else
                        {
                            intermedio = Logica.puntos_objetivo [objetivo].get_random(random);
                        }
                    }
                }
            }
        }
Example #7
0
        private Vector align(BoidCollection boids)         //promedio de las velocidades de los vecinos
        {
            Vector sum       = new Vector(0, 0);
            int    neighbors = 0;
            int    n         = 0;

            if (Logica.puntos_objetivo.Count > 0 && objetivo < Logica.puntos_objetivo.Count)
            {
                Vector v;
                if (intermedio.X > Location.X)
                {
                    v = new Vector(intermedio.X - Location.X, Logica.mapeo(intermedio.Y) - Location.Y);
                }
                else
                {
                    v = new Vector(Location.X - intermedio.X, Location.Y - Logica.mapeo(intermedio.Y));
                }
                v.normalize();
                v.mult(0.5);
                sum.add(v);
                neighbors++;
            }

            else
            {
                foreach (Boid b in boids)
                {
                    double d = Location.distance(b.Location);
                    if ((Logica.mouse && n == 0) || (n != 0 && d > 0 && d < Logica.radioAli))
                    {
                        sum.add(b.Velocity);
                        neighbors++;
                    }
                    n++;
                }
            }

            if (neighbors > 0)
            {
                sum.div(neighbors);
                sum.normalize();
                sum.mult(Logica.max_speed);
                Vector steer = sum.sub(sum, this.Velocity);
                steer.limit(Logica.max_force);
                return(steer);
            }
            else
            {
                return(new Vector(0, 0));
            }
        }
Example #8
0
//		Vector locacion_temp;
//		bool mover = true;
//

        public BoidAutonomo(int lapso, Random r)
        {
            ogreRef       = IntPtr.Zero;
            rotacion      = 0;
            llego         = false;
            nro_iteracion = 0;
            this.objetivo = 0;
            random        = r;
            tiempo_inicio = Constantes.tiempo;
            seleccionarCriterio(r);
            trayectoria       = new List <Point> ();
            this.vecinos      = 0;
            this.Acceleration = new Vector(0, 0);
            double angle = r.NextDouble() * 2 * Math.PI;

            this.Velocity = new Vector(Math.Cos(angle), Math.Sin(angle));
            this.Velocity.mult(4);
//			this.Location = new Vector(Constantes.limites.Width/2, Constantes.limites.Height/2);
//			this.Velocity = new Vector(0, 1);
            if (Logica.puntos_inicio.Count > 0)
            {
                Point p = Logica.puntos_inicio.ElementAt((int)((lapso - 1) % Logica.puntos_inicio.Count));                  //el punto de inicio es numero de lapso MOD cantidad ptos inicio
                this.Location = new Vector(p.X, Logica.mapeo(p.Y));
            }
            else
            {
                this.Location = new Vector(Constantes.limites.Width / 2, Constantes.limites.Height / 2);
            }
            //this.Location = new Vector (r.NextDouble () * Constantes.limites.Width, r.NextDouble () * Constantes.limites.Height);

//			locacion_temp = new Vector (Location.X,Location.Y);

            LocationNueva = new Vector(Location.X, Location.Y);

            if (Logica.puntos_objetivo.Count > 0)               //Comprobar si elige el objetivo mas corto

            {
                if (criterio == 0)
                {
                    intermedio = Logica.puntos_objetivo [objetivo].get_cercano(Location);
                }
                else if (criterio == 1)
                {
                    intermedio = Logica.puntos_objetivo [objetivo].get_menos_concurrido(Location);
                }
                else
                {
                    intermedio = Logica.puntos_objetivo [objetivo].get_random(random);
                }
            }
        }
Example #9
0
        private void ubicar_boid_punto_inicio()
        {
            Random r = new Random();

            if (Logica.puntos_inicio.Count > 0)
            {
                double nro = Math.Round(r.NextDouble() * (Logica.puntos_inicio.Count - 1));
                Point  p   = Logica.puntos_inicio[(int)nro];              //el punto de inicio es numero de lapso MOD cantidad ptos inicio
                this.LocationNueva = new Vector(p.X, Logica.mapeo(p.Y));
            }
            else
            {
                this.LocationNueva = new Vector(Constantes.limites.Width / 2, Constantes.limites.Height / 2);
            }
        }
Example #10
0
        public Point get_cercano(Vector location)
        {
            double distancia = 10000;
            Point  final     = objetivos[0];

            foreach (Point p in objetivos)
            {
                double temporal = location.distance(new Vector(p.X, Logica.mapeo(p.Y)));
                if (temporal < distancia)
                {
                    final     = p;
                    distancia = temporal;
                }
            }
            return(final);
        }
Example #11
0
        private void triangulo(Cairo.Context cr, Boid b, double rot)
        {
            reset(cr);

            cr.Save();

            r.Rotate(rot);
            t.Translate(b.Location.X, Logica.mapeo(b.Location.Y));

            r.TransformPoint(ref Ax, ref Ay);
            t.TransformPoint(ref Ax, ref Ay);

            r.TransformPoint(ref Bx, ref By);
            t.TransformPoint(ref Bx, ref By);

            r.TransformPoint(ref Cx, ref Cy);
            t.TransformPoint(ref Cx, ref Cy);

            //			System.Diagnostics.Debug.WriteLine (Ax+", "+Ay);

            cr.MoveTo(Ax, Ay);
            cr.LineTo(Bx, By);
            cr.LineTo(Cx, Cy);

            cr.LineWidth = 2;

            if (b.criterio == 0)
            {
                cr.SetSourceRGBA(0.5, 0, 0, 0.5);                  //cercano
            }
            else if (b.criterio == 1)
            {
                cr.SetSourceRGBA(0, 0.5, 0, 0.5);                  //menos concurrido
            }
            else
            {
                cr.SetSourceRGBA(0, 0, 0.5, 0.5);                  //random
            }
            cr.ClosePath();
            cr.FillPreserve();
            cr.Stroke();

            cr.Restore();
        }
Example #12
0
 private void limpiarPantalla()
 {
     if (Constantes.viewSurface != null)
     {
         Constantes.viewSurface.Dispose();
         Constantes.viewSurface = new Cairo.ImageSurface(Cairo.Format.ARGB32, Constantes.limites.Width, Constantes.limites.Height);
     }
     Logica.objects.Clear();
     Logica.circulos.Clear();
     Logica.rectangulos.Clear();
     Logica.lineas.Clear();
     Logica.puntos_inicio.Clear();
     Logica.clear_puntos_objetivo();
     Logica.grilla.limpiar_obstaculos();
     Logica.grilla.limpiar_boids();
     this.spinbuttonIntermitencia.Value = 0;
     Constantes.max_nivel    = 1;
     Constantes.nivel_actual = 1;
     this.spinbuttonNivel.SetRange(1, 1);
     zoom_reset();
 }
        public DialogoMetricas()
        {
            this.Build();
            if (!Constantes.sin_movimiento_estadistica())
            {
                this.max_tiempo.Text   = Constantes.max_tiempo.ToString() + " it x 60 ms";
                this.min_tiempo.Text   = Constantes.min_tiempo.ToString() + " it x 60 ms";
                this.tiempo_prom.Text  = Math.Round((Constantes.tiempo_acum / Constantes.nro_trayectorias), 2).ToString() + " it x " + Constantes.milisegundos_iteracion + " ms";
                this.labelMiliseg.Text = "(it: iteraciĆ³n)";
            }
            else
            {
                this.max_tiempo.Text   = "No existen registros";
                this.min_tiempo.Text   = "No existen registros";
                this.tiempo_prom.Text  = "No existen registros";
                this.labelMiliseg.Text = "";
            }

            this.min_vecinos.Text = Logica.calcular_vecinos_estadistica().X.ToString();
            this.max_vecinos.Text = Logica.calcular_vecinos_estadistica().Y.ToString();
        }
Example #14
0
 private void dibujar_trayectorias(DrawingArea area, Cairo.Context cr)
 {
     System.Drawing.Point punto;
     for (int i = 1; i < Logica.objects.Count; i++)
     {
         if (((BoidAutonomo)Logica.objects[i]).trayectoria.Count > 0)
         {
             punto = ((BoidAutonomo)Logica.objects[i]).trayectoria [0];
             foreach (System.Drawing.Point p in ((BoidAutonomo)Logica.objects[i]).trayectoria)
             {
                 cr.Save();
                 cr.LineWidth = 0.5;
                 cr.SetSourceRGBA(0, 0, 0, 0.5);
                 cr.MoveTo(punto.X, Logica.mapeo(punto.Y));
                 cr.LineTo(p.X, Logica.mapeo(p.Y));
                 cr.Stroke();
                 cr.Restore();
                 punto = p;
             }
         }
     }
 }
Example #15
0
        private void triangulo_contorno(Cairo.Context cr, Vector location, double rot)
        {
            reset(cr);

            cr.Save();

            r.Rotate(rot);
            t.Translate(location.X, Logica.mapeo(location.Y));

            r.TransformPoint(ref Ax, ref Ay);
            t.TransformPoint(ref Ax, ref Ay);

            r.TransformPoint(ref Bx, ref By);
            t.TransformPoint(ref Bx, ref By);

            r.TransformPoint(ref Cx, ref Cy);
            t.TransformPoint(ref Cx, ref Cy);

//			System.Diagnostics.Debug.WriteLine (Ax+", "+Ay);

            cr.MoveTo(Ax, Ay);
            cr.LineTo(Bx, By);
            cr.LineTo(Cx, Cy);

            cr.LineWidth = 2;
            cr.SetSourceRGBA(0, 0, 0, 0.5);

            cr.ClosePath();
            cr.FillPreserve();
            cr.Stroke();

            cr.Restore();

            cr.Save();
            cr.Arc(Ax, Ay, Logica.radioSep, 0, 2 * Math.PI);
            cr.SetSourceRGBA(1, 0, 0, 0.2);
            cr.Stroke();
            cr.Restore();
        }
Example #16
0
        private void dibujar_grilla_estadistica(DrawingArea area, Cairo.Context cr)
        {
            double[] color;
            double   min = Logica.grilla.min_visitas();
            double   max = Logica.grilla.max_visitas();

            for (int x = 0; x < Constantes.nro_casillas; x++)
            {
                for (int y = 0; y < Constantes.nro_casillas; y++)
                {
                    int x0 = Logica.grilla.get_casillero(x, y).inicioX;
                    int y0 = Logica.grilla.get_casillero(x, y).inicioY;
                    int xf = Logica.grilla.get_casillero(x, y).finX - Logica.grilla.get_casillero(x, y).inicioX;
                    int yf = Logica.grilla.get_casillero(x, y).finY - Logica.grilla.get_casillero(x, y).inicioY;
                    cr.Save();

//					referencia_mapa (cr);

                    cr.Save();

                    color = calcular_mapa_calor(Logica.grilla.get_casillero(x, y).visitas, min, max);
                    cr.SetSourceRGBA(color[0], color[1], color[2], 0.5);
                    cr.Rectangle(x0, Logica.mapeo(y0) - yf, xf, yf);
                    cr.Fill();


//					cr.SetSourceRGB (0,0,0);
//					cr.SelectFontFace ("Arial", FontSlant.Normal, FontWeight.Normal);
//					cr.SetFontSize (12);
//					TextExtents t = cr.TextExtents (Logica.grilla.get_casillero (x, y).visitas.ToString ());
//					cr.MoveTo (x0+10, Logica.mapeo(y0)-10);
//					cr.ShowText (Logica.grilla.get_casillero (x, y).visitas.ToString ());

                    cr.Restore();
                }
            }
        }
Example #17
0
        public void cargar_obstaculos()
        {
            limpiar_obstaculos();
            Cairo.Rectangle n;
            foreach (Obstaculo r in Logica.rectangulos)
            {
                double X0 = r.rectangle.X, Y0 = Logica.mapeo(r.rectangle.Y), X1 = r.rectangle.X + r.rectangle.Width, Y1 = Logica.mapeo(r.rectangle.Y + r.rectangle.Height);
                double Xf, Yf;
                if (X0 < X1)
                {
                    X0 -= 10;
                    Xf  = X1 + 20;
                }
                else
                {
                    Xf = X0 + 20;
                    X0 = X1 - 10;
                }
                if (Y0 < Y1)
                {
                    Y0 -= 10;
                    Yf  = Y1 + 20;
                }
                else
                {
                    Yf = Y0 + 20;
                    Y0 = Y1 - 10;
                }

                n = new Cairo.Rectangle((int)X0, (int)Y0, (int)Xf, (int)Yf);
                ubicar_rectangulo_casillero(n, r, 'r');
            }

            foreach (Obstaculo c in Logica.circulos)
            {
                double X0 = c.rectangle.X - c.rectangle.Width - 10;
                double Y0 = Logica.mapeo(c.rectangle.Y) - c.rectangle.Width - 10;
                double X1 = c.rectangle.X + c.rectangle.Width + 10;
                double Y1 = Logica.mapeo(c.rectangle.Y) + c.rectangle.Width + 10;;
                n = new Cairo.Rectangle(X0, Y0, X1, Y1);
                ubicar_rectangulo_casillero(n, c, 'c');
            }


            foreach (Obstaculo l in Logica.lineas)
            {
                int lineainiciox, lineafinx, lineainicioy, lineafiny;
                if (l.rectangle.X < l.rectangle.Width)
                {
                    lineainiciox = (int)l.rectangle.X - 10;
                    lineafinx    = (int)l.rectangle.Width + 10;
                }
                else
                {
                    lineainiciox = (int)l.rectangle.Width - 10;
                    lineafinx    = (int)l.rectangle.X + 10;
                }
                if (Logica.mapeo(l.rectangle.Y) < Logica.mapeo(l.rectangle.Height))
                {
                    lineainicioy = (int)Logica.mapeo(l.rectangle.Y) - 10;
                    lineafiny    = (int)Logica.mapeo(l.rectangle.Height) + 10;
                }
                else
                {
                    lineainicioy = (int)Logica.mapeo(l.rectangle.Height) - 10;
                    lineafiny    = (int)Logica.mapeo(l.rectangle.Y) + 10;
                }


                n = new Cairo.Rectangle(lineainiciox, lineainicioy, lineafinx, lineafiny);
                ubicar_rectangulo_casillero(n, l, 'l');
            }
        }
Example #18
0
        private void play_simulacion_finita2(DrawingArea area, Cairo.Context cr)
        {
            int      n    = 0;
            TimeSpan temp = new TimeSpan(0);

            if (Logica.play)
            {
                if (Constantes.iteraciones_total >= 2000000000)
                {
                    Constantes.iteraciones_total = 0;
                }
                Constantes.iteraciones_total++;
                a1 = DateTime.Now;
                if (Constantes.iteraciones_lapso != 0 && Constantes.tiempo % Constantes.iteraciones_lapso == 0)
                {
                    Logica.add_boids_iteracion();
                }
                else if (Constantes.iteraciones_lapso == 0)
                {
                    Logica.add_boids_iteracion();
                }

                //PARA DETENER LA SIMULACION EN UNA ITERACION DETERMINADA!!
                if (Constantes.tiempo == 10000)
                {
                    Logica.play = false;
                }
                //-----------------------------------------------------------

                Constantes.tiempo++;
                if (Constantes.tiempo > 2000000000)
                {
                    Constantes.tiempo = 0;
                    Logica.reset_trayectorias();
                }
            }

            for (int i = 0; i < Logica.objects.Count; i++)
            {
                u = Logica.grilla.ubicacion_boid(Logica.objects[i]);
                coleccion.Clear();
                rectangulos.Clear();
                lineas.Clear();
                circulos.Clear();
                for (int x = u.X; x <= u.Width; x++)
                {
                    for (int y = u.Y; y <= u.Height; y++)
                    {
                        coleccion.Add(Logica.objects [0]);
                        coleccion.AddBoids(Logica.grilla.get_casillero(x, y).boids);
                        Constantes.addObstacles(Logica.grilla.get_casillero(x, y).circulos, circulos);
                        Constantes.addObstacles(Logica.grilla.get_casillero(x, y).lineas, lineas);
                        Constantes.addObstacles(Logica.grilla.get_casillero(x, y).rectangulos, rectangulos);
                    }
                }
                //				TimeSpan total = new TimeSpan (r2.Ticks - r1.Ticks);
                //				System.Console.WriteLine (total);
                if (Logica.play)
                {
                    if (n == 0 && Logica.mouse)
                    {
                        Logica.objects[i].calculateVelocity(Logica.objects, area);
                    }
                    else if (n != 0)
                    {
                        Logica.objects[i].calculateVelocity(coleccion, circulos, rectangulos, lineas);

                        if (Logica.objects[i].llego)
                        {
                            Logica.objects.RemoveAt(i);
                            i--;
                        }
                    }
                }

                n++;
            }
            r1 = DateTime.Now;
            n  = 0;
            foreach (Boid s in Logica.objects)
            {
                if (n != 0)
                {
                    rot = s.calculateRotation();
                    if (ventana.contorno.Active)
                    {
                        triangulo_contorno(cr, s.Location, rot);
                    }
                    else
                    {
                        triangulo(cr, s, rot);
                    }
                }
                n++;
            }

            r2    = DateTime.Now;
            temp += new TimeSpan(r2.Ticks - r1.Ticks);
            Constantes.r_acum += new TimeSpan(r2.Ticks - r1.Ticks);

            Logica.actualizar_posicion_boids();

            Logica.grilla.reclasificar(Logica.objects);


            if (Logica.play)
            {
                a2 = DateTime.Now;
                Constantes.a_acum               += new TimeSpan(a2.Ticks - a1.Ticks) - temp;
                ventana.render.Text              = "Tiempo de rendering: " + Constantes.r_acum.ToString() + "    ";
                ventana.algorithm.Text           = "Tiempo de algoritmo: " + Constantes.a_acum.ToString();
                ventana.etiquetaIteraciones.Text = "   Cantidad de iteraciones: " + Constantes.iteraciones_total.ToString();
            }
        }
Example #19
0
 protected void OnResetButtonActivated(object sender, EventArgs e)
 {
     Logica.reset();
 }
Example #20
0
        private void update(BoidCollection boids, List <Obstaculo> C, List <Obstaculo> R, List <Obstaculo> L, double magnitud) //Revisa los limites y calcula los rebotes
        {
            Velocity.add(Acceleration);                                                                                        //Update velocity
            Velocity.limit(Logica.max_speed);

            double newx     = this.Location.X + this.Velocity.X;
            double newy     = this.Location.Y + this.Velocity.Y;
            double velOrigX = this.Velocity.X;
            double velOrigY = this.Velocity.Y;

            Constantes.reboto = false;
            for (int i = 0; i < C.Count() && !Constantes.reboto; i++)
            {
                if (C.ElementAt(i).enable)
                {
                    Logica.avoid_circulo(newx, newy, this.Velocity, C.ElementAt(i).rectangle, this.Location);
                }
            }
            for (int i = 0; i < R.Count() && !Constantes.reboto; i++)
            {
                if (R.ElementAt(i).enable)
                {
                    Logica.avoid_rectangulo(newx, newy, this.Velocity, R.ElementAt(i).rectangle, this.Location);
                }
            }
            for (int i = 0; i < L.Count() && !Constantes.reboto; i++)
            {
                if (L.ElementAt(i).enable)
                {
                    Logica.avoid_linea(newx, newy, this.Velocity, L.ElementAt(i).rectangle, this.Location);
                }
            }



            //rebota o atraviesa los bordes de la pantalla
            if (Logica.rebotar)
            {
                if (newx > Constantes.limites.Right - 10 || newx < Constantes.limites.Left + 10)
                {
                    this.Velocity.X = -1 * this.Velocity.X;
                }

                if (newy > Constantes.limites.Bottom - 40 || newy < Constantes.limites.Top + 20)
                {
                    this.Velocity.Y = -1 * (this.Velocity.Y);
                }
            }

            else if (Logica.atravesar)
            {
                if (newx < 0)
                {
                    LocationNueva.X = Constantes.limites.Width;
                }
                if (newy < 0)
                {
                    LocationNueva.Y = Constantes.limites.Height;
                }
                if (newx > Constantes.limites.Width)
                {
                    LocationNueva.X = 0;
                }
                if (newy > Constantes.limites.Height)
                {
                    LocationNueva.Y = 0;
                }
            }

            Velocity.X *= magnitud;
            Velocity.Y *= magnitud;
            LocationNueva.add(Velocity);

            //Reset acceleration
            Acceleration.X = 0;
            Acceleration.Y = 0;
        }