张铎龙 2019-07-29 10:36 采纳率: 100%
浏览 949
已采纳

请问下面这样的路径规划动态图应该如何制作

图片说明

  • 写回答

1条回答 默认 最新

  • threenewbee 2019-07-29 22:10
    关注

    代码下载:https://download.csdn.net/download/caozhy/11449907

    图片说明

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace Q770812
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private int[,] area;
    
            private int step = 1;
    
            private void button1_Click(object sender, EventArgs e)
            {
                //step++;
                for (int k = 0; k < step; k++)
                {
                    for (int i = 0; i < 30; i++)
                    {
                        for (int j = 0; j < 15; j++)
                        {
                            if (area[i, j] == 4) area[i, j] = 1;
                        }
                    }
                    for (int i = 0; i < 30; i++)
                    {
                        for (int j = 0; j < 15; j++)
                        {
                            if (area[i, j] == 0)
                            {
                                bool pt = false;
                                for (int ii = (i > 0 ? i - 1 : 0); ii <= (i < 29 ? i + 1 : 29); ii++)
                                    for (int jj = (j > 0 ? j - 1 : 0); jj <= (j < 14 ? j + 1 : 14); jj++)
                                    {
                                        if ((ii == i && jj != j) || (ii != i && jj == j))
                                            if (area[ii, jj] == 1) pt = true;
                                    }
                                area[i, j] = pt ? 4 : area[i, j];
                            }
                        }
                    }
                }
                pictureBox1.Refresh();
            }
    
            private void pictureBox1_Paint(object sender, PaintEventArgs e)
            {
                if (area == null) return;
                var g = e.Graphics;
                g.FillRectangle(Brushes.White, 0f, 0f, pictureBox1.Width, pictureBox1.Height);
                for (int i = 0; i < 30; i++)
                {
                    for (int j = 0; j < 15; j++)
                    {
                        Brush br = new SolidBrush(Color.FromArgb(110, 136, 199));
                        switch (area[i, j])
                        {
                            case 0:
                                br = new SolidBrush(Color.FromArgb(219, 213, 213));
                                break;
                            case 1:
                                br = new SolidBrush(Color.FromArgb(202, 190, 180));
                                break;
                            case 3:
                                br = new SolidBrush(Color.FromArgb(134, 134, 122));
                                break;
                        }
                        g.FillRectangle(br, 10.0f + i * 20.0f, 10.0f + j * 20.0f, 18.0f, 18.0f);
                    }
                }
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                area = new int[30, 15];
                for (int i = 0; i < 30; i++)
                {
                    for (int j = 0; j < 15; j++)
                        area[i, j] = 0;
                }
                for (int i = 3; i <= 11; i++)
                {
                    area[3, i] = 3;
                    area[4, i] = 3;
                }
                for (int i = 4; i <= 14; i++)
                {
                    area[13, i] = 3;
                    area[14, i] = 3;
                }
                for (int i = 0; i <= 6; i++)
                {
                    area[22, i] = 3;
                    area[23, i] = 3;
                }
                for (int i = 0; i <= 6; i++)
                {
                    area[22, i] = 3;
                    area[23, i] = 3;
                }
                for (int i = 5; i <= 6; i++)
                {
                    area[24, i] = 3;
                    area[25, i] = 3;
                    area[26, i] = 3;
                }
                area[8, 7] = 1;
                step = 1;
                pictureBox1.Refresh();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                button2.PerformClick();
            }
        }
    }
    
    
    namespace Q770812
    {
        partial class Form1
        {
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.IContainer components = null;
    
            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }
    
            #region Windows Form Designer generated code
    
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                this.pictureBox1 = new System.Windows.Forms.PictureBox();
                this.button1 = new System.Windows.Forms.Button();
                this.button2 = new System.Windows.Forms.Button();
                ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
                this.SuspendLayout();
                // 
                // pictureBox1
                // 
                this.pictureBox1.BackColor = System.Drawing.Color.White;
                this.pictureBox1.Location = new System.Drawing.Point(30, 12);
                this.pictureBox1.Name = "pictureBox1";
                this.pictureBox1.Size = new System.Drawing.Size(616, 319);
                this.pictureBox1.TabIndex = 0;
                this.pictureBox1.TabStop = false;
                this.pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
                // 
                // button1
                // 
                this.button1.Location = new System.Drawing.Point(431, 354);
                this.button1.Name = "button1";
                this.button1.Size = new System.Drawing.Size(90, 25);
                this.button1.TabIndex = 1;
                this.button1.Text = "next";
                this.button1.UseVisualStyleBackColor = true;
                this.button1.Click += new System.EventHandler(this.button1_Click);
                // 
                // button2
                // 
                this.button2.Location = new System.Drawing.Point(556, 354);
                this.button2.Name = "button2";
                this.button2.Size = new System.Drawing.Size(90, 25);
                this.button2.TabIndex = 2;
                this.button2.Text = "reset";
                this.button2.UseVisualStyleBackColor = true;
                this.button2.Click += new System.EventHandler(this.button2_Click);
                // 
                // Form1
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(673, 391);
                this.Controls.Add(this.button2);
                this.Controls.Add(this.button1);
                this.Controls.Add(this.pictureBox1);
                this.Name = "Form1";
                this.Text = "Form1";
                this.Load += new System.EventHandler(this.Form1_Load);
                ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
                this.ResumeLayout(false);
    
            }
    
            #endregion
    
            private System.Windows.Forms.PictureBox pictureBox1;
            private System.Windows.Forms.Button button1;
            private System.Windows.Forms.Button button2;
        }
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)