zoukankan      html  css  js  c++  java
  • 标准十字座标系

    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 CoordinateSystem
    {
        public partial class Form1 : Form
        {
            int orgX = 20;
            int orgY = 20;//原点距离边框左,下距离
            int move = 20;//格子间隔
            int timerI = 0;
           
            public Form1()
            {
                InitializeComponent();
                timer1.Interval = 1000;
                timer1.Enabled = true;
            }
           
            private void panel1_Paint(object sender, PaintEventArgs e)
            {
               
              
                Draw draw = new Draw();
                draw.DrawX(move,panel1,orgX,orgY);
                draw.DrawY(move, panel1, orgX, orgY);
               
            }
            private void timer1_Tick(object sender, EventArgs e)
            {
                Graphics g = panel1.CreateGraphics();
              
                //double a = Math.Sin(timerI);
                //double c = a * 100;
                //int b = (int)c;
                //g.DrawLine(new Pen(Color.Red), new Point(orgX, panel1.Height - orgY),
                //           new Point(orgX + timerI, panel1.Width - orgY - b));
                g.DrawLine(new Pen(Color.Red), new Point(orgX+timerI*10, panel1.Height - orgY- timerI * 10),
                                           new Point(orgX + timerI * 10+10, panel1.Height - orgY- timerI * 10-10));
                timerI += 1;
            }
        }
        public class Draw
        {
            //X轴方法
            public void DrawX(int move,Panel panel,int orgX,int orgY)//画X轴上分格
            {
               
              
                int a = (panel.Width/2) / move;//X轴有多少格
                Graphics g = panel.CreateGraphics();
               
                g.DrawLine(new Pen(Color.Black, 3), new Point(panel.Width/2, panel.Height),//画X轴长线
                                                    new Point(panel.Width/2, 0));

                for (int i = 0; i < a; i++)
                {
                    g.DrawLine(new Pen(Color.Black, 3), new Point(panel.Width/2+ move * i, panel.Height/2),
                               new Point(panel.Width / 2 + move * i, panel.Height / 2 - 4));//划分+格子
                    g.DrawLine(new Pen(Color.Black, 3),new Point(panel.Width / 2 - move * i, panel.Height / 2),
                                new Point(panel.Width / 2 - move * i, panel.Height / 2 - 4));//划分-格子
                    g.DrawString(i.ToString(), new Font("宋体", 8f), Brushes.Black, panel.Width / 2 + move * i,
                                                                          panel.Height / 2 + 4 );//写X轴+的数字
                    if (i!=0)
                    {
                        g.DrawString("-" + i.ToString(), new Font("宋体", 8f), Brushes.Black, panel.Width / 2 - move * i,
                                                                                              panel.Height / 2 + 4);//写X轴-的数字
                    }
                   
                }
                g.DrawString("X轴", new Font("宋体", 10f), Brushes.Black, panel.Width-30, panel.Height/2+20);
            }
            public void DrawY(int move,Panel pan,int orgX,int orgY)
            {
                Graphics g = pan.CreateGraphics();
                g.DrawLine(new Pen(Color.Black, 3), new Point(0, pan.Height/2),
                                                    new Point(pan.Width, pan.Height / 2));//画Y轴长线
                int a = (pan.Height/2) / move;
                for (int i = 0; i < a; i++)
                {
                    g.DrawLine(new Pen(Color.Black, 3), new Point(pan.Width/2, pan.Height/2 - move * i),
                               new Point(pan.Width / 2 + 4, pan.Height / 2 - move * i));
                    g.DrawLine(new Pen(Color.Black, 3), new Point(pan.Width / 2, pan.Height / 2 + move * i),
                               new Point(pan.Width / 2 + 4, pan.Height / 2 + move * i));
                    if (i!=0)
                    {
                        g.DrawString(i.ToString(), new Font("宋体", 8f), Brushes.Black, pan.Width / 2 - 10,
                        pan.Height / 2 - move * i);
                        g.DrawString("-"+i.ToString(), new Font("宋体", 8f), Brushes.Black, pan.Width / 2 - 15,
                        pan.Height / 2 + move * i);
                    }
                   
                }
                g.DrawString("Y轴", new Font("宋体", 10f),Brushes.Black, orgX, orgY - 20);
               
            }
        }
    }
    自动驱动未来
  • 相关阅读:
    并行和并发
    怎样用第三方开源免费软件portecle从https站点上导出SSL的CA证书?
    我持续推动Rust语言支持Windows XP系统
    Android——4.2.2 文件系统文件夹分析
    hadoop(八)
    自己定义html中a标签的title提示tooltip
    多个返回 顶部的代码
    同学们,OpenCV出3.0了,速去围观!
    hdu1002
    好记性不如烂笔头(一)
  • 原文地址:https://www.cnblogs.com/rb-huang/p/hrb_190417_2.html
Copyright © 2011-2022 走看看