private void AnimationTimer_Tick(object sender, EventArgs e)
        {
            //Graphics objects for drawing lines.
            Graphics g = DrawingPanel.CreateGraphics();

            if (yValue < 155)
            {
                //Clear lines and liquid stream with rectangles.
                yValue = 374;
                g.FillRectangle(blackBrush, 91, 150, 249, 225);
                g.FillRectangle(blackBrush, 215, 118, 25, 256);

                //Reset the TrackBar and Timer.
                SpeedTrackBar.Value    = 0;
                AnimationTimer.Enabled = false;
            }
            else
            {
                //Drawing a line at each tick interval.
                Line nextLine = new Line(91, yValue, 339, yValue, liquidColor);
                nextLine.Draw(g);
                //Liquid stream must be redrawn according to the color change.
                g.FillRectangle(new SolidBrush(liquidColor), 215, 118, 25, yValue - 118);
            }
            yValue--;

            //Disposing Graphics object after drawing a line on or resetting the DrawingPanel.
            g.Dispose();
        }
Beispiel #2
0
 private void StartButton_Click(object sender, EventArgs e)
 {
     if (StartButton.Text == "Start")
     {
         AnimationTimer.Enabled = true;
         StartButton.Text       = "Stop";
         x1    = rnd.Next(0, DrawingPanel.Width);
         x2    = rnd.Next(0, DrawingPanel.Width);
         y1    = rnd.Next(0, DrawingPanel.Height);
         y2    = rnd.Next(0, DrawingPanel.Height);
         x1inc = rnd.Next(4, 15);
         x2inc = rnd.Next(4, 15);
         y1inc = rnd.Next(4, 15);
         y2inc = rnd.Next(4, 15);
         Graphics g = DrawingPanel.CreateGraphics();
         g.Clear(Color.Black);   // Clear the screen
         g.Dispose();
         lines = new List <Line>();
     }
     else
     {
         AnimationTimer.Enabled = false;
         StartButton.Text       = "Start";
     }
 }
Beispiel #3
0
        public MainForm()
        {
            InitializeComponent();

            Load();

            g = DrawingPanel.CreateGraphics();

            timer.Interval = 1000;

            InitNewGeneration();

            timer.Tick += (s, e) =>
            {
                if (best != null && best.Alive)
                {
                    DrawSnake();
                    best.Step();
                }
                else
                {
                    InitNewGeneration();
                }
            };
        }
Beispiel #4
0
        private void DrawingPanel_MouseClick(object sender, MouseEventArgs e)
        {
            if (GameTimer.Enabled)
            {
                for (int i = 0; i < NumberOfBalls; i++)
                {
                    if (ballList[i].PointInBall(e.X, e.Y))
                    {
                        ballList.RemoveAt(i);
                        NumberOfBalls--;
                    }
                }

                Graphics g = DrawingPanel.CreateGraphics(); //Create a graphics object

                g.Clear(Color.Black);

                foreach (Ball b in ballList)
                {
                    b.Draw(g);
                }

                g.Dispose();
            }
        }
Beispiel #5
0
        private void DrawingPanel_MouseClick(object sender, MouseEventArgs e)
        {
            if (GameTimer.Enabled)
            {
                // TODO – Check if we clicked on a Ball
                // do this by iterating through list of balls and check using the PointInBall method

                for (int i = 0; i < NumberOfBalls; i++)
                {
                    // if (e,X, e.Y) is inside the Ball, remove from List and then
                    // clear the objects and redraw the remaining objects on screen.
                    if (ballList[i].PointInBall(e.X, e.Y))
                    {
                        ballList.RemoveAt(i);
                        NumberOfBalls--;
                    }
                }

                Graphics g = DrawingPanel.CreateGraphics(); //Create a graphics object
                                                            // TODO – Add code to draw all of the Balls in the list to the screen
                g.Clear(Color.Black);
                foreach (Ball b in ballList)
                {
                    b.Draw(g);
                }
            }
        }
        // Called when form refreshed, redraws graph based on selection
        private void DrawingPanel_Paint(object sender, PaintEventArgs e)
        {
            Graph graph = graphs[cboxMonthDataTypes.SelectedIndex];

            // Used to set up appropriate axes
            float overallRange = graph.YearMaxValue - graph.YearMinValue;

            // Graph size remains constant
            float pixelsPerUnit = maxBarLength / overallRange;

            using (Graphics panelGraphics = DrawingPanel.CreateGraphics())
                using (SolidBrush writeBrush = new SolidBrush(fontColor))
                {
                    DrawVerticalGraphIntervals(graph, panelGraphics, writeBrush, pixelsPerUnit);

                    if (graph is BoxPlotGraph boxPlotGraph)
                    {
                        DrawBoxPlotGraph(panelGraphics, writeBrush, overallRange, pixelsPerUnit, boxPlotGraph);
                    }
                    else
                    {
                        DrawSimpleBarGraph(graph, panelGraphics, writeBrush, pixelsPerUnit);
                    }

                    DrawAxes(graph, panelGraphics, writeBrush);
                }
        }
Beispiel #7
0
        private void DrawingPanel_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = DrawingPanel.CreateGraphics();

            g.Clear(Color.White);
            level.setGraphics(g, DrawingPanel.Size.Width);
            this.g = g;
        }
Beispiel #8
0
        public MainWindow()
        {
            InitializeComponent();

            WindowSize       = DrawingPanel.Width;
            SingleSquareSize = WindowSize / (float)Settings.BoardSize - (float)(1.7 / (float)Settings.BoardSize);
            drawArea         = DrawingPanel.CreateGraphics();
        }
Beispiel #9
0
        private void InfoUpdate()
        {
            // Get the current raw sensor KG values.

            var rwWeight = wiiDevice.WiimoteState.BalanceBoardState.WeightKg;

            var rwTopLeft     = wiiDevice.WiimoteState.BalanceBoardState.SensorValuesKg.TopLeft;
            var rwTopRight    = wiiDevice.WiimoteState.BalanceBoardState.SensorValuesKg.TopRight;
            var rwBottomLeft  = wiiDevice.WiimoteState.BalanceBoardState.SensorValuesKg.BottomLeft;
            var rwBottomRight = wiiDevice.WiimoteState.BalanceBoardState.SensorValuesKg.BottomRight;

            float pointX = wiiDevice.WiimoteState.BalanceBoardState.CenterOfGravity.X;
            float pointY = wiiDevice.WiimoteState.BalanceBoardState.CenterOfGravity.Y;

            // label_rwWT.Text = rwWeight.ToString("0.0");
            LeftTopVal.Text     = rwTopLeft.ToString("0.0");
            RightTopDat.Text    = rwTopRight.ToString("0.0");
            LeftBottomDat.Text  = rwBottomLeft.ToString("0.0");
            RightBottomDat.Text = rwBottomRight.ToString("0.0");
            WeightDat.Text      = rwWeight.ToString("0.0");

            CenterGravityX.Text = pointX.ToString("0.0");
            CenterGravityY.Text = pointY.ToString("0.0");

            Bitmap bufl = new Bitmap(DrawingPanel.Width, DrawingPanel.Height);

            using (Graphics g = Graphics.FromImage(bufl))
                using (System.Drawing.Pen blackPen = new System.Drawing.Pen(System.Drawing.Color.Black))
                    using (System.Drawing.Pen redPen = new System.Drawing.Pen(System.Drawing.Color.Red))

                    {
                        g.FillRectangle(Brushes.White, new Rectangle(0, 0, DrawingPanel.Width, DrawingPanel.Height));

                        g.DrawLine(blackPen, 0, DrawingPanel.Height / 2, DrawingPanel.Width, DrawingPanel.Height / 2);
                        g.DrawLine(blackPen, DrawingPanel.Width / 2, 0, DrawingPanel.Width / 2, DrawingPanel.Height);



                        int Xpos = DrawingPanel.Width / 2 + (int)(pointX * 10);
                        if (InvertX.Checked)
                        {
                            Xpos = DrawingPanel.Width - Xpos;
                        }
                        int Ypos = DrawingPanel.Height / 2 + (int)(pointY * 10);
                        if (InvertY.Checked)
                        {
                            Ypos = DrawingPanel.Height - Ypos;
                        }
                        System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(Xpos - 1, Ypos - 1, 2, 2);
                        g.DrawRectangle(System.Drawing.Pens.Red, rectangle);

                        g.DrawLine(redPen, Xpos - 5, Ypos, Xpos + 5, Ypos);
                        g.DrawLine(redPen, Xpos, Ypos - 5, Xpos, Ypos + 5);


                        DrawingPanel.CreateGraphics().DrawImageUnscaled(bufl, 0, 0);
                    }
        }
Beispiel #10
0
 public FormNotes()
 {
     InitializeComponent();
     g = DrawingPanel.CreateGraphics();
     g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
     p          = new Pen(Color.Black);
     p.StartCap = p.EndCap = System.Drawing.Drawing2D.LineCap.Round;
     clearSketch();
 }
Beispiel #11
0
 private void ClearButton_Click(object sender, EventArgs e)
 {
     DrawingPanel.CreateGraphics().Clear(Color.White);
     Edges = new EList();
     Vert  = new EList();
     //string a = "1\n2\n3\n4\n5";
     //if (SFD.ShowDialog() == DialogResult.OK)
     //    File.WriteAllText(SFD.FileName, a);
 }
Beispiel #12
0
 /* Creates art when user drags the mouse around */
 private void DrawingPanel_MouseMove(object sender, MouseEventArgs e)
 {
     if (shouldPaint)
     {
         /* User is only able to draw within the panel */
         using (Graphics graphics = DrawingPanel.CreateGraphics())
         {
             graphics.FillEllipse(
                 new SolidBrush(brushColor), e.X, e.Y, brushSize, brushSize);
         }
     }
 }
Beispiel #13
0
        private void GenerateButton_Click(object sender, EventArgs e)
        {
            Vert.indicator = new int[MaxDEPTH];
            for (int i = 0; i < MaxDEPTH; i++)
            {
                Vert.indicator[i] = 0;
            }

            TNode.GenerateBranches(bakaut.root, MaxDEPTH, MaxBRANCHES, DrawingPanel.Width, DrawingPanel.Height, ref Edges, ref Vert, 0);
            bakaut.depth = MaxDEPTH;
            DrawingPanel.CreateGraphics().DrawImage(DrawTree(DrawingPanel.Width, DrawingPanel.Height), new Point(0, 0));
        }
Beispiel #14
0
        private void AnimationTimer_Tick(object sender, EventArgs e)
        {
            Color lc   = Color.LightGreen;
            Line  line = new Line(x1, y1, x2, y2, lc);

            lines.Add(line);

            // Draw the line on screen
            Graphics g = DrawingPanel.CreateGraphics();

            if (lines.Count == LINE_DEPTH)
            {
                lines[0].LineColor = Color.Black;
                lines[0].Draw(g);
                lines.RemoveAt(0);
            }


            foreach (Line l in lines)
            {
                l.Draw(g);
                l.Fade();
            }

            g.Dispose();

            // Move the line
            x1 += x1inc;
            y1 += y1inc;
            x2 += x2inc;
            y2 += y2inc;

            // Check and reverse increments if required
            if (x1 < 0 || x1 > DrawingPanel.Width)
            {
                x1inc = (x1inc > 0) ? -rnd.Next(4, 15) : rnd.Next(4, 15);
            }
            if (x2 < 0 || x2 > DrawingPanel.Width)
            {
                x2inc = (x2inc > 0) ? -rnd.Next(4, 15) : rnd.Next(4, 15);
            }
            if (y1 < 0 || y1 > DrawingPanel.Height)
            {
                y1inc = (y1inc > 0) ? -rnd.Next(4, 15) : rnd.Next(4, 15);
            }
            if (y2 < 0 || y2 > DrawingPanel.Height)
            {
                y2inc = (y2inc > 0) ? -rnd.Next(4, 15) : rnd.Next(4, 15);
            }
        }
Beispiel #15
0
        private void DisplayDrawing()
        {
            if (_imageBuffer == null)
            {
                _imageBuffer         = new Bitmap(DrawingPanel.Width, DrawingPanel.Height);
                _imageBufferGraphics = Graphics.FromImage(_imageBuffer);
                _panelGraphics       = DrawingPanel.CreateGraphics();
            }

            if (TargetDrawing.Draw(_imageBufferGraphics))
            {
                _panelGraphics.DrawImageUnscaled(_imageBuffer, 0, 0);
            }
        }
Beispiel #16
0
        private void StartBtn_Click(object sender, EventArgs e)
        {
            if (StartButton.Enabled)
            {
                GameTimer.Enabled   = true;
                StartButton.Enabled = false;
                NumberOfBalls       = 0;
                ticks = 0;

                Graphics g = DrawingPanel.CreateGraphics(); //Create a graphics object
                g.Clear(Color.Black);
                ballList.Clear();
                GameTimer_Tick(null, null); // May need to comment this out for now
            }
        }
        } // end Paint()

        private void DrawLines()
        {
            int   distanceBetweenLines = 20;
            Point lineStartPoint       = new Point(0, 0);
            Point lineEndPoint         = new Point(0, 0);

            if (verRadioBut.Checked)
            {
                lineStartPoint = new Point(10, 20);

                lineEndPoint = new Point(10, 100);
            }

            using (Graphics panelGraphics = DrawingPanel.CreateGraphics())
                using (Pen linePen = new Pen(Color.Red))
                {
                    for (int i = 0; i < numberToDraw; i++)
                    {
                        panelGraphics.DrawLine(linePen, lineStartPoint, lineEndPoint);

                        lineStartPoint.X = lineStartPoint.X + distanceBetweenLines;
                        lineEndPoint.X   = lineEndPoint.X + distanceBetweenLines;
                    }
                }// end using

            if (horRadioBut.Checked)
            {
                lineStartPoint = new Point(10, 20);

                lineEndPoint = new Point(100, 20);
            }
            using (Graphics panelGraphics = DrawingPanel.CreateGraphics())
                using (Pen linePen = new Pen(Color.Red))
                {
                    for (int i = 0; i < numberToDraw; i++)
                    {
                        panelGraphics.DrawLine(linePen, lineStartPoint, lineEndPoint);

                        lineStartPoint.Y = lineStartPoint.Y + distanceBetweenLines;
                        lineEndPoint.Y   = lineEndPoint.Y + distanceBetweenLines;
                    }
                }// end using
        }
Beispiel #18
0
        private void GenerateButton_Click(object sender, EventArgs e)
        {
            //очистка панели рисования
            DrawingPanel.CreateGraphics().Clear(Color.White);

            //очистка списков (узлы/рёбра), если до этого момента кнопка "сгенерировать" уже была нажата
            Edges = new EList();
            Vert  = new EList();

            //генерация дерева
            TNode.GenerateBranches(bakaut.root, MaxDEPTH, BRANCHES);

            //инициализация точки корня для правильной работы алгоритма по нахождению остальных точек
            bakaut.root.tPoint = new Point(DrawingPanel.Width / 2, 15);

            //получение списков точек узлов/рёбер
            bakaut.GetPoints(bakaut.root, DrawingPanel.Width, DrawingPanel.Height, Edges, Vert);

            //рисование элементов
            DrawingPanel.CreateGraphics().DrawImage(DrawTree(DrawingPanel.Width, DrawingPanel.Height), new Point(0, 0));
        }
Beispiel #19
0
        private void GameTimer_Tick(object sender, EventArgs e)
        {
            // Check for end condition
            if (ballList.Count > 0 && NumberOfBalls > 0)
            {
                // TODO – End of Game
                // Turn timer off and re-enable the Start button
                GameTimer.Enabled   = false;
                StartButton.Enabled = true;
                // Put up a message that Game is Over and tell them how
                // many rounds they have completed
                MessageBox.Show($"Game over! You completed {ticks} rounds.");
                return;
            }
            NumberOfBalls++;
            ticks++;
            // This will generate a Random set of Balls and put them into a List
            for (int i = 0; i < NumberOfBalls; i++)
            {
                int radius = rnd.Next(20, 50);
                int x      = rnd.Next(radius * 2, DrawingPanel.Width - radius * 4);
                int y      = rnd.Next(radius * 2, DrawingPanel.Height - radius * 4);
                int red    = rnd.Next(100, 255);
                int green  = rnd.Next(100, 255);
                int blue   = rnd.Next(100, 255);
                ballList.Add(new Ball(x, y, radius, Color.FromArgb(red, green, blue)));
            }
            Graphics g = DrawingPanel.CreateGraphics(); //Create a graphics object

            // TODO – Add code to draw all of the Balls in the list to the screen
            g.Clear(Color.Black);
            foreach (Ball b in ballList)
            {
                b.Draw(g);
            }

            g.Dispose();
        }
 PaintEventArgs GetNewPaintEventArgs()
 {
     return(new PaintEventArgs(DrawingPanel.CreateGraphics(), new Rectangle()));
 }
        public void drawTree(int levels)
        {
            int panelW = DrawingPanel.Size.Width;
            int panelH = DrawingPanel.Size.Height;

            SolidBrush sb    = new SolidBrush(Color.Green);
            Pen        myPen = new Pen(Color.Red);
            Graphics   g     = DrawingPanel.CreateGraphics();

            int xPos          = panelW / 2;
            int yPos          = 60;
            int width         = 20;
            int height        = 20;
            int number_nodes  = 1;
            int space         = xPos;
            int startPosition = xPos;


            for (int i = 1; i <= levels; i++)
            {
                number_nodes = number_nodes * 2;
            }
            number_nodes = number_nodes - 1;
            Console.WriteLine("******* number nodes" + number_nodes);
            int counter = 1;
            int number_nodes_by_level = 2;


            int[,] values = new int [number_nodes, 2];

            while (number_nodes != 0)
            {
                if (counter > 1)
                {
                    if (number_nodes_by_level == counter)
                    {
                        yPos  = yPos + 100;
                        space = panelW / (number_nodes_by_level + 1);
                        xPos  = space;
                        number_nodes_by_level = number_nodes_by_level * 2;
                    }
                    else
                    {
                        xPos = xPos + space;
                    }
                }
                Label node = new Label();
                node.Location = new Point(xPos, yPos);
                node.Text     = "(x:" + xPos + ") (y:" + yPos + ")";

                //DrawingPanel.Controls.Add(node);
                Rectangle rectangle = new Rectangle(xPos, yPos, width, height);
                g.DrawEllipse(myPen, rectangle);
                values[counter - 1, 0] = xPos;
                values[counter - 1, 1] = yPos;

                counter++;
                number_nodes--;
            }

            /*
             * int maxLines = (values.Length / 2) -1;
             * int yPoxS = 0,xPosS = 0;
             * for (int i = 0; i<= maxLines; i++)
             * {
             *  if (yPoxS == 0)
             *  {
             *      xPosS = values[i, 0];
             *      yPoxS = values[i, 1];
             *  }
             *  else
             *  {
             *
             *      System.Drawing.Graphics graphicsObj;
             *
             *      graphicsObj = this.CreateGraphics();
             *
             *      g.DrawLine(myPen, xPosS, yPoxS, values[i, 0], values[i, 1]);
             *      if (yPoxS != values[i, 1] && i>2)
             *      {
             *          xPosS = values[i, 0];
             *          yPoxS = values[i, 1];
             *      }
             *      else
             *      {
             *          xPosS = values[i, 0];
             *      }
             *  }
             *  Console.WriteLine("x:" + values[i, 0]);
             *  Console.WriteLine("y:" + values[i, 1]);
             *
             *
             *
             * }
             */
            /*for (int i = 1; i<=levels; i++)
             * {
             *  int tempNumberNodes = number_nodes;
             *
             *  while (tempNumberNodes != 0)
             *  {
             *      Rectangle rectangle = new Rectangle(xPos, yPos, width, height);
             *      g.DrawEllipse(myPen, rectangle);
             *      xPos = xPos + (startPosition * number_nodes);
             *      tempNumberNodes--;
             *  }
             *  yPos = yPos + 100;
             *  xPos = startPosition / 2;
             *  startPosition = xPos;
             *  number_nodes = number_nodes * 2;
             *
             * }
             */
        }
 public VillageWindow()
 {
     InitializeComponent();
     g = DrawingPanel.CreateGraphics();
 }
Beispiel #23
0
        private void doComputation()
        {
            initGraphicsImage();

            // Determine Drawing Area
            maxLeft   = 15.0f;
            maxRight  = this.DrawingPanel.Size.Width - 20.0f;
            maxTop    = 15.0f;
            maxBottom = this.DrawingPanel.Size.Height - 20.0f;

            // Determine Boundries From Data
            leftMost = convertToDecimal(cities[0].derajatBujur, cities[0].menitBujur);
            if (cities[0].bujurBaratTimur.Equals("B"))
            {
                leftMost *= -1.0f;
            }
            rightMost = leftMost;

            topMost = convertToDecimal(cities[0].derajatLintang, cities[0].menitLintang);
            if (cities[0].lintangUtaraSelatan.Equals("S"))
            {
                topMost *= -1.0f;
            }
            bottomMost = topMost;

            foreach (City c in cities)
            {
                float bujur = convertToDecimal(c.derajatBujur, c.menitBujur);
                if (c.bujurBaratTimur.Equals("B"))
                {
                    bujur *= -1.0f;
                }

                float lintang = convertToDecimal(c.derajatLintang, c.menitLintang);
                if (c.lintangUtaraSelatan.Equals("S"))
                {
                    lintang *= -1.0f;
                }

                if (bujur < leftMost)
                {
                    leftMost = bujur;
                }
                if (bujur > rightMost)
                {
                    rightMost = bujur;
                }

                if (lintang > topMost)
                {
                    topMost = lintang;
                }
                if (lintang < bottomMost)
                {
                    bottomMost = lintang;
                }
            }

            // Initialize Centroids with random value
            if (centroids == null)
            {
                centroids = new Centroid[numOfTerminus];

                for (Int32 i = 0; i < centroids.Length; i++)
                {
                    centroids[i] = new Centroid();

                    PointF location = new PointF(0.0f, 0.0f);
                    location.X            = (float)random.NextDouble() * (rightMost - leftMost) + leftMost;
                    location.Y            = (float)random.NextDouble() * (topMost - bottomMost) + bottomMost;
                    centroids[i].location = location;

                    centroids[i].color = ColorHelper.getNextKnownColor();
                }
            }

            // Determine Closest Distance
            foreach (Centroid c in centroids)
            {
                c.closestCities.Clear();
            }
            foreach (City c in cities)
            {
                Int32 i = 0, closestCentroid = Int32.MinValue;
                float minDistance = float.MaxValue;

                do
                {
                    PointF cityLocationOnMap = new PointF(0.0f, 0.0f);
                    cityLocationOnMap.X = convertToDecimal(c.derajatBujur, c.menitBujur) * (c.bujurBaratTimur.Equals("T") ? 1.0f : -1.0f);
                    cityLocationOnMap.Y = convertToDecimal(c.derajatLintang, c.menitLintang) * (c.lintangUtaraSelatan.Equals("U") ? 1.0f : -1.0f);

                    if (minDistance > calculateEuclideanDistance(cityLocationOnMap, centroids[i].location))
                    {
                        closestCentroid = i;
                        minDistance     = calculateEuclideanDistance(cityLocationOnMap, centroids[i].location);
                    }
                } while (++i < centroids.Length);

                centroids[closestCentroid].closestCities.Add(c);
            }

            // Draw The Cities And Centroids
            Graphics DrawingGraphics = Graphics.FromImage(GraphicsImage);

            DrawingGraphics.SmoothingMode = SmoothingMode.HighQuality;

            foreach (Centroid p in centroids)
            {
                foreach (City c in p.closestCities)
                {
                    Point cityLocationOnDrawingPanel = convertToLocationOnDrawingPanel(c);
                    DrawingGraphics.FillEllipse(new SolidBrush(p.color), cityLocationOnDrawingPanel.X, cityLocationOnDrawingPanel.Y, 10, 10);
                }

                maxRight  -= 5.0f;
                maxBottom -= 5.0f;

                Point centroidLocationOnDrawingPanel = convertToLocationOnDrawingPanel(p);
                DrawingGraphics.FillRectangle(new SolidBrush(p.color), centroidLocationOnDrawingPanel.X, centroidLocationOnDrawingPanel.Y, 15, 15);

                maxRight  += 5.0f;
                maxBottom += 5.0f;
            }

            DrawingPanel.CreateGraphics().DrawImageUnscaled(GraphicsImage, new Point(0, 0));

            // Calculate Next Centroid
            String serializedOldCentroid = JsonConvert.SerializeObject(centroids);

            Centroid[] oldCentroid = JsonConvert.DeserializeObject <Centroid[]>(serializedOldCentroid);
            foreach (Centroid centroid in centroids)
            {
                PointF rata2 = new PointF(0.0f, 0.0f);

                foreach (City city in centroid.closestCities)
                {
                    PointF location = new PointF(0.0f, 0.0f);
                    location.X = convertToDecimal(city.derajatBujur, city.menitBujur) * (city.bujurBaratTimur.Equals("T") ? 1.0f : -1.0f);
                    location.Y = convertToDecimal(city.derajatLintang, city.menitLintang) * (city.lintangUtaraSelatan.Equals("U") ? 1.0f : -1.0f);

                    rata2.X += location.X;
                    rata2.Y += location.Y;
                }

                if (centroid.closestCities.Count != 0 || true)
                {
                    rata2.X = rata2.X / (float)centroid.closestCities.Count;
                    rata2.Y = rata2.Y / (float)centroid.closestCities.Count;
                }
                else
                {
                    // Push ke centroid lain yg terdekat
                }

                centroid.location = rata2;
            }

            // Check Program Ends
            Boolean centroidLocationChange = false;

            for (Int32 i = 0; i < centroids.Length; i++)
            {
                Point a = convertToLocationOnDrawingPanel(centroids[i].location);
                Point b = convertToLocationOnDrawingPanel(oldCentroid[i].location);

                if (a.X != b.X && a.Y != b.Y)
                {
                    centroidLocationChange = true;
                    break;
                }
            }

            if (!centroidLocationChange)
            {
                timer.Stop();
                // Enable UI Elements
                this.browseButton.Enabled          = true;
                this.numOfTerminusComboBox.Enabled = true;
                this.calcButton.Enabled            = true;
                this.saveResultButton.Enabled      = true;
                this.saveImageButton.Enabled       = true;

                // Print Output
                Array.Sort(centroids);
                for (Int32 i = 0; i < centroids.Length; i++)
                {
                    PointF p = centroids[i].location;

                    String utaraSelatan = p.Y >= 0.0f ? "U" : "S";
                    String baratTimur   = p.X >= 0.0f ? "T" : "B";

                    p.X = Math.Abs(p.X);
                    p.Y = Math.Abs(p.Y);

                    String printedContent = "Station " + (i + 1) + ": ";

                    printedContent += Math.Truncate(p.Y);
                    printedContent += (Char)176;
                    p.Y            -= (float)Math.Truncate(p.Y);
                    p.Y            *= 60.0f;
                    printedContent += Math.Truncate(p.Y) + "\'";
                    printedContent += utaraSelatan + " ";

                    printedContent += Math.Truncate(p.X);
                    printedContent += (Char)176;
                    p.X            -= (float)Math.Truncate(p.X);
                    p.X            *= 60.0f;
                    printedContent += Math.Truncate(p.X) + "\'";
                    printedContent += baratTimur + Environment.NewLine;

                    this.resultRichTextBox.AppendText(printedContent);
                }
            }
        }
Beispiel #24
0
 private void ExecuteBu_Click(object sender, EventArgs e)
 {
     _interpreter.Execute(CommandsText.Text, DrawingPanel.CreateGraphics());
 }
Beispiel #25
0
 private void initGraphicsImage()
 {
     Graphics.FromImage(GraphicsImage).Clear(Color.White);
     DrawingPanel.CreateGraphics().DrawImageUnscaled(GraphicsImage, new Point(0, 0));
 }
Beispiel #26
0
 //очистка
 private void ClearButton_Click(object sender, EventArgs e)
 {
     DrawingPanel.CreateGraphics().Clear(Color.White);
     Edges = new EList();
     Vert  = new EList();
 }