Example #1
0
        /// <summary>
        /// Name:evaluateCOG
        /// Description:calculates the centure of gravity for the planet
        /// </summary>
        /// <param name="inputedCOG">inputed COG</param>
        public void evaluateCOG(COG inputedCOG)
        {
            var determinedDistance = Math.Sqrt(Math.Pow(this.planetLocation.X - inputedCOG.Location.X, 2) + Math.Pow(this.planetLocation.Y - inputedCOG.Location.Y, 2));
            var distances          = Math.Abs(determinedDistance);

            if (inputedCOG.Radius + 1 > distances)
            {
                if (!(distances > this.distance))
                {
                    this.distance = distances;
                    this.center   = inputedCOG;
                }
            }
        }
Example #2
0
        /// <summary>
        /// Name:pictureBox1_Click
        /// Description: a place for all the functionalities of the picture box
        /// </summary>
        /// <param name="sender">object sender</param>
        /// <param name="e">event arugment</param>
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            MouseEventArgs clicks        = e as MouseEventArgs;
            Point          point         = new Point(clicks.X, clicks.Y);
            Planets        createdPlanet = new Planets(point);
            Bitmap         bitmap        = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            Graphics       planet        = Graphics.FromImage(bitmap);
            Graphics       circle        = Graphics.FromImage(bitmap);

            if (createButton.Checked)
            {
                COG    gravity = new COG();
                double dist    = 100000.00;
                bool   val     = false;

                foreach (COG grav in this.cog)
                {
                    var determinedDistance = Math.Sqrt(Math.Pow(point.X - grav.Location.X, 2) + Math.Pow(point.Y - grav.Location.Y, 2));
                    var distances          = Math.Abs(determinedDistance);

                    if (grav.Radius + 1 > distances)
                    {
                        val = true;
                        if (!(dist < distances))
                        {
                            dist             = distances;
                            gravity.Location = grav.Location;
                            gravity.Radius   = grav.Radius;
                        }
                    }
                }

                if (val != true)
                {
                    MessageBox.Show("Place planet in a center of gravity zone");
                }
                else
                {
                    createdPlanet.evaluateCOG(gravity);
                    this.planets.Add(createdPlanet);

                    foreach (Planets plan in this.planets)
                    {
                        planet.FillEllipse(new SolidBrush(Color.Red), plan.PlanetLocation.X - 5, plan.PlanetLocation.Y - 5, 15, 15);

                        foreach (COG center in this.cog)
                        {
                            planet.FillEllipse(new SolidBrush(Color.LightGray), center.Location.X - center.Radius, center.Location.Y - center.Radius, center.Radius * 2, center.Radius * 2);
                            planet.FillEllipse(new SolidBrush(Color.Black), center.Location.X, center.Location.Y, 5, 5);
                        }
                    }

                    pictureBox1.Image = bitmap;
                }
            }
            else if (CenterButton.Checked)
            {
                COG newGravity = new COG(point, (int)numericUpDown1.Value);
                this.cog.Add(newGravity);

                foreach (Planets pt in this.planets)
                {
                    circle.FillEllipse(new SolidBrush(Color.Red), pt.PlanetLocation.X, pt.PlanetLocation.Y, 15, 15);

                    foreach (COG center in this.cog)
                    {
                        circle.FillEllipse(new SolidBrush(Color.Black), center.Location.X - 3, center.Location.Y - 3, 5, 5);
                        circle.FillEllipse(new SolidBrush(Color.LightGray), center.Location.X - center.Radius, center.Location.Y - center.Radius, center.Radius * 2, center.Radius * 2);
                    }
                }

                pictureBox1.Image = bitmap;
            }
            else if (CenterButton.Checked == false && createButton.Checked == false)
            {
                MessageBox.Show("Select an option: create a center of gravity or create a planet.");
            }
            else
            {
                MessageBox.Show("Error!!!");
            }
        }