Esempio n. 1
0
        private void PbSorting_Paint_1(object sender, PaintEventArgs e)
        {
            float  maxX = this.pbSorting.Width - 75;
            Random r    = new Random();

            for (int i = 0; i < 3; i++)
            {
                int times = r.Next(1, 4);
                e.Graphics.DrawLine(new Pen(Color.SlateGray, 6), maxX * i / 3 + 80, entries[0], maxX * i / 3 + 80 + 50 * times, entries[1]);
                Checkpoint c = new Checkpoint(maxX * i / 4 + 80, entries[0], i);
                c.AddCheckpoint(new Checkpoint(maxX * i / 4 + 80 + 50 * times, entries[1]));
                checkpoints.Add(c);
                if (i == 2)
                {
                    e.Graphics.DrawLine(new Pen(Color.SlateGray, 6), 70, entries[0], maxX * i / 3 + 80, entries[0]);
                }
                times = r.Next(1, 4);
                e.Graphics.DrawLine(new Pen(Color.SlateGray, 6), maxX * i / 3 + 100, entries[2], maxX * i / 3 + 100 + 50 * times, entries[1]);
                c = new Checkpoint(maxX * i / 4 + 100, entries[2], i);
                c.AddCheckpoint(new Checkpoint(maxX * i / 4 + 100 + 50 * times, entries[1]));
                checkpoints.Add(c);
                if (i == 2)
                {
                    e.Graphics.DrawLine(new Pen(Color.SlateGray, 6), 70, entries[2], maxX * i / 3 + 100, entries[2]);
                }
            }
            e.Graphics.DrawLine(new Pen(Color.SlateGray, 6), 70, entries[1], this.pbSorting.Width, entries[1]);
            //Draw shortest
            for (int i = 0; i < this.activeEntry.Count; i++)
            {
                if (this.activeEntry[i] == 1 || this.activeEntry[i] == 2)
                {
                    Checkpoint ch = this.findShortestLine(entries[0], entries[1]);
                    if (this.activeEntry[i] == 1)
                    {
                        lblsortingA1.Visible = true;
                        pbxRed.Visible       = true;
                        textBox1.Visible     = true;
                        Color color = Color.Red;
                        e.Graphics.DrawLine(new Pen(color, 3), 70, entries[0] + 3, Convert.ToUInt32(ch.x + 50 * ch.id * 1.5), entries[0] + 3);
                        e.Graphics.DrawLine(new Pen(color, 3), Convert.ToUInt32(ch.x + 50 * ch.id * 1.5), entries[0] + 3, Convert.ToUInt32(ch.neighbour.x + 50 * ch.id * 1.5), entries[1] + 3);
                        e.Graphics.DrawLine(new Pen(color, 3), Convert.ToUInt32(ch.neighbour.x + 50 * ch.id * 1.5), entries[1] + 3, this.pbSorting.Width, entries[1] + 3);
                        e.Graphics.DrawLine(new Pen(color, 3), 0, (this.pbSorting.Height / 7 - 3) * (this.activeEntry[i]), 20, (this.pbSorting.Height / 7 - 3) * (this.activeEntry[i]));
                        e.Graphics.DrawLine(new Pen(color, 3), 15, (this.pbSorting.Height / 7 - 3) * (this.activeEntry[i]), 70, (this.pbSorting.Height / 7 - 3) * (this.activeEntry[i]) + (this.pbSorting.Height / 7 - 3) / 2);
                    }
                    else
                    {
                        lblsortingA2.Visible = true;
                        pbxBlue.Visible      = true;
                        textBox2.Visible     = true;
                        Color color = Color.Blue;
                        e.Graphics.DrawLine(new Pen(color, 3), 70, entries[0] - 3, Convert.ToUInt32(ch.x + 50 * ch.id * 1.5), entries[0] - 3);
                        e.Graphics.DrawLine(new Pen(color, 3), Convert.ToUInt32(ch.x + 50 * ch.id * 1.5), entries[0] - 3, Convert.ToUInt32(ch.neighbour.x + 50 * ch.id * 1.5), entries[1] - 3);
                        e.Graphics.DrawLine(new Pen(color, 3), Convert.ToUInt32(ch.neighbour.x + 50 * ch.id * 1.5), entries[1] - 3, this.pbSorting.Width, entries[1] - 3);
                        e.Graphics.DrawLine(new Pen(color, 3), 0, (this.pbSorting.Height / 7 - 3) * (this.activeEntry[i]), 20, (this.pbSorting.Height / 7 - 3) * (this.activeEntry[i]));
                        e.Graphics.DrawLine(new Pen(color, 3), 15, (this.pbSorting.Height / 7 - 3) * (this.activeEntry[i]), 70, (this.pbSorting.Height / 7 - 3) * (this.activeEntry[i] - 1) + (this.pbSorting.Height / 7 - 3) / 2);
                    }
                }
                else if (this.activeEntry[i] == 4 || this.activeEntry[i] == 3)
                {
                    if (this.activeEntry[i] == 4)
                    {
                        lblsortingA4.Visible = true;
                        pbxTurquoise.Visible = true;
                        textBox4.Visible     = true;
                        Color color = Color.Turquoise;
                        e.Graphics.DrawLine(new Pen(color, 6), 70, entries[1] + 3, this.pbSorting.Width, entries[1] + 3);
                        e.Graphics.DrawLine(new Pen(color, 3), 0, (this.pbSorting.Height / 7 - 3) * (this.activeEntry[i]), 20, (this.pbSorting.Height / 7 - 3) * (this.activeEntry[i]));
                        e.Graphics.DrawLine(new Pen(color, 3), 15, (this.pbSorting.Height / 7 - 3) * (this.activeEntry[i]), 70, (this.pbSorting.Height / 7 - 3) * (this.activeEntry[i] - 1) + (this.pbSorting.Height / 7 - 3) / 2);
                    }
                    else
                    {
                        lblsortingA3.Visible = true;
                        pbxGreen.Visible     = true;
                        textBox3.Visible     = true;
                        Color color = Color.Green;
                        e.Graphics.DrawLine(new Pen(color, 6), 70, entries[1] - 3, this.pbSorting.Width, entries[1] - 3);
                        e.Graphics.DrawLine(new Pen(color, 3), 0, (this.pbSorting.Height / 7 - 3) * (this.activeEntry[i]), 20, (this.pbSorting.Height / 7 - 3) * (this.activeEntry[i]));
                        e.Graphics.DrawLine(new Pen(color, 3), 15, (this.pbSorting.Height / 7 - 3) * (this.activeEntry[i]), 70, (this.pbSorting.Height / 7 - 3) * (this.activeEntry[i]) + (this.pbSorting.Height / 7 - 3) / 2);
                    }
                }
                else if (this.activeEntry[i] == 5 || this.activeEntry[i] == 6)
                {
                    Checkpoint ch = this.findShortestLine(entries[2], entries[1]);
                    if (this.activeEntry[i] == 5)
                    {
                        lblsortingA5.Visible = true;
                        pbxHotPink.Visible   = true;
                        textBox5.Visible     = true;
                        Color color = Color.HotPink;
                        e.Graphics.DrawLine(new Pen(color, 3), 70, entries[2] + 3, Convert.ToUInt32(ch.x + 50 * ch.id * 1.5), entries[2] + 3);
                        e.Graphics.DrawLine(new Pen(color, 3), Convert.ToUInt32(ch.x + 50 * ch.id * 1.5), entries[2] + 3, Convert.ToUInt32(ch.neighbour.x + 50 * ch.id * 1.5), entries[1] + 3);
                        e.Graphics.DrawLine(new Pen(color, 3), Convert.ToUInt32(ch.neighbour.x + 50 * ch.id * 1.5), entries[1] + 3, this.pbSorting.Width, entries[1] + 3);
                        e.Graphics.DrawLine(new Pen(color, 3), 0, (this.pbSorting.Height / 7 - 3) * (this.activeEntry[i]), 20, (this.pbSorting.Height / 7 - 3) * (this.activeEntry[i]));
                        e.Graphics.DrawLine(new Pen(color, 3), 15, (this.pbSorting.Height / 7 - 3) * (this.activeEntry[i]), 70, (this.pbSorting.Height / 7 - 3) * (this.activeEntry[i]) + (this.pbSorting.Height / 7 - 3) / 2);
                    }
                    else
                    {
                        lblsortingA6.Visible = true;
                        pbxPurple.Visible    = true;
                        textBox6.Visible     = true;
                        Color color = Color.Purple;
                        e.Graphics.DrawLine(new Pen(color, 3), 70, entries[2] - 3, Convert.ToUInt32(ch.x + 50 * ch.id * 1.5), entries[2] - 3);
                        e.Graphics.DrawLine(new Pen(color, 3), Convert.ToUInt32(ch.x + 50 * ch.id * 1.5), entries[2] - 3, Convert.ToUInt32(ch.neighbour.x + 50 * ch.id * 1.5), entries[1] - 3);
                        e.Graphics.DrawLine(new Pen(color, 3), Convert.ToUInt32(ch.neighbour.x + 50 * ch.id * 1.5), entries[1] - 3, this.pbSorting.Width, entries[1] - 3);
                        e.Graphics.DrawLine(new Pen(color, 3), 0, (this.pbSorting.Height / 7 - 3) * (this.activeEntry[i]), 20, (this.pbSorting.Height / 7 - 3) * (this.activeEntry[i]));
                        e.Graphics.DrawLine(new Pen(color, 3), 15, (this.pbSorting.Height / 7 - 3) * (this.activeEntry[i]), 70, (this.pbSorting.Height / 7 - 3) * (this.activeEntry[i] - 1) + (this.pbSorting.Height / 7 - 3) / 2);
                    }
                }
            }
        }
Esempio n. 2
0
 public void AddCheckpoint(Checkpoint c)
 {
     this.neighbour = c;
     this.length    = Math.Sqrt(Math.Pow(this.x - c.x, 2) + Math.Pow(this.y - c.y, 2));
 }