Exemple #1
0
        } //trajectory update

        public static void Vertical_Trajectory(int nr)
        {
            g = Graphics.FromImage(map);
            //speed = (float.Parse(tb2.Text) / 100) * 1.5f;
            if (toinit)
            {
                ps.Clear();
                speed        = float.Parse(tb2.Text);
                grav         = (float.Parse(tb4.Text) / 100) * 1.5f;
                tempx        = new float[nr];
                tempy        = new float[nr];
                acceleration = new float[nr];
                for (int i = 0; i < nr; i++)
                {
                    ps.Add(new ColorPoint(rand.Next(10, drawspace.Width - 9), drawspace.Height - 200, Color.FromArgb(rand.Next(256), rand.Next(256), rand.Next(256))));
                    tempy[i]        = (rand.Next((int)speed / 2, (int)speed + 1) / 100) * 1.5f;
                    acceleration[i] = grav;
                    toinit          = false;
                }
            }
            else
            {
                for (int i = 0; i < nr; i++)
                {
                    ps[i]           = new ColorPoint(ps[i].x, drawspace.Height - 200, ps[i].color);
                    tempy[i]        = (rand.Next((int)speed / 3, (int)speed + 1) / 100) * 1.5f;
                    acceleration[i] = grav;
                }
            }
            time.Interval = 30;
            Update_func[Search_tag("vtrajectory")].torun = true;
        } //throwing ball in the air and falling simulation
Exemple #2
0
        } //throwing ball in the air and falling simulation

        public static void Vertical_Trajectory_Update()
        {
            g.Clear(Color.White);
            bool ok = true;

            for (int i = 0; i < ps.Count; i++)
            {
                float py = ps[i].y + (-tempy[i] + acceleration[i]);
                if (py < drawspace.Height - 200)
                {
                    g.DrawLine(Pens.Black, 0, drawspace.Height - 200, drawspace.Width, drawspace.Height - 200);
                    acceleration[i] += grav;
                    g.FillEllipse(new SolidBrush(ps[i].color), ps[i].x - 4, py - 4, 8, 8);
                    ps[i] = new ColorPoint(ps[i].x, (int)py, ps[i].color);
                    ok    = false;
                }
                else
                {
                    g.DrawLine(Pens.Black, 0, drawspace.Height - 200, drawspace.Width, drawspace.Height - 200);
                    PointF p1  = new PointF(ps[i].x - 4, py - (-tempy[i] + acceleration[i]) - 4);
                    PointF p2  = new PointF(ps[i].x - 4, py - 4);
                    PointF p3  = new PointF(0, drawspace.Height - 200);
                    PointF p4  = new PointF(drawspace.Width, drawspace.Height - 200);
                    PointF itr = Intersectionof2lines(p1, p2, p3, p4);
                    g.FillEllipse(new SolidBrush(ps[i].color), itr.X, itr.Y - 8, 8, 8);
                }
                //tempx[i] = tempx[i] - acceleration[i];
                //tempy[i] = tempy[i] + tempx[i];
            }

            /*  bool ok = true;
             * for (int i = 0; i < ps.Count; i++)
             *    if (!isok[i])
             *        ok = false;*/
            if (ok)
            {
                Update_func[Search_tag("vtrajectory")].torun = false;
            }
            Updatebackground(drawspace, map);
        } //update for vertical trajectory