본문 바로가기
C#.Net

C#, 그래프(graph) 그리는 소스입니다.[퍼옴]

by 호야호잇 2024. 3. 6.

참고: https://blog.naver.com/smserial/221713969182

 

PIC18F, 용량 & PWM & PID-2 계산 테스트... 성미시리얼

  ● PIC18F 를 사용하여, 비레제어-2 테스트를 수행합니다.   300%, 200%, 100% 를 적...

blog.naver.com

 ● C#용, 그래프(graph) 그리는 소스입니다.

 

 

private void draw_graph()

{
  int b, x, y1, y2, w = 2;
  Graphics g1, g2, g3;

  Bitmap bmp1, bmp2, bmp3;

  Pen pen;

 

  bmp1 = new Bitmap(241, 311); // 메모리 크기
  bmp2 = new Bitmap(241, 311);
  bmp3 = new Bitmap(241, 311);

 

  g1 = Graphics.FromImage(bmp1);
  g2 = Graphics.FromImage(bmp2);
  g3 = Graphics.FromImage(bmp3);

 

  g1.Clear(Color.Black); // 검은색으로 바탕을 지웁니다
  g2.Clear(Color.Black);
  g3.Clear(Color.Black);

 

  x = ccubf.old_t1 * 2;
  pen = new Pen(Color.FromArgb(150, 150, 150), 1); // white, 세로이동선
  g1.DrawLine(pen, x, 5, x, 304);
  g2.DrawLine(pen, x, 5, x, 304);
  g3.DrawLine(pen, x, 5, x, 304);

 

  pen = new Pen(Color.FromArgb(150, 150, 150), 1); // white, 가로기준선
  g1.DrawLine(pen, 0, 5, 242, 5); // 
  g1.DrawLine(pen, 0, 305, 240, 305); // 아래
  g2.DrawLine(pen, 0, 5, 240, 5);
  g2.DrawLine(pen, 0, 305, 240, 305);
  g3.DrawLine(pen, 0, 5, 240, 5);
  g3.DrawLine(pen, 0, 305, 240, 305);

 

  pen = new Pen(Color.FromArgb(255, 0, 255), 1); // 설정선
  b = combf.rb[203]; b <<= 8; b += combf.rb[204]; // G
  g1.DrawLine(pen, 8, 305 - b, 232, 305 - b);
  b = combf.rb[205]; b <<= 8; b += combf.rb[206]; // O
  g2.DrawLine(pen, 8, 305 - b, 232, 305 - b);
  b = combf.rb[207]; b <<= 8; b += combf.rb[208]; // N
  g3.DrawLine(pen, 8, 305 - b, 232, 305 - b);

  x = 0;

  pen = new Pen(Color.FromArgb(0, 255, 0), 1);​
  for (int i = 0; i < 119; i++) {
    if (ccubf.f[i] == true && ccubf.f[i + 1] == true) { // G
      y1 = 305 - ccubf.g[i];
      y2 = 305 - ccubf.g[i + 1];
      g1.DrawLine(pen, x, y1, x + w, y2); // x1, y2, x2, y2
    }
    x += w; 
  }
  pictureBox1.Image = bmp1.Clone(new System.Drawing.Rectangle(0, 0, bmp1.Width, bmp1.Height),
     System.Drawing.Imaging.PixelFormat.Format24bppRgb); // 가상메모리에서 화면메모리로 복사합니다

  x = 0;

  pen = new Pen(Color.FromArgb(0, 255, 0), 1);​
  for (int i = 0; i < 119; i++) {
    if (ccubf.f[i] == true && ccubf.f[i + 1] == true) { // O
      y1 = 305 - ccubf.o[i];
      y2 = 305 - ccubf.o[i + 1];
      g2.DrawLine(pen, x, y1, x + w, y2); // x1, y2, x2, y2
    }
    x += w;
  }
  pictureBox2.Image = bmp2.Clone(new System.Drawing.Rectangle(0, 0, bmp2.Width, bmp2.Height),
     System.Drawing.Imaging.PixelFormat.Format24bppRgb);

  x = 0;

  pen = new Pen(Color.FromArgb(0, 255, 0), 1);​
  for (int i = 0; i < 119; i++) {
    if (ccubf.f[i] == true && ccubf.f[i + 1] == true) { // N
      y1 = 305 - ccubf.n[i];
      y2 = 305 - ccubf.n[i + 1];
      g3.DrawLine(pen, x, y1, x + w, y2); // x1, y2, x2, y2
    }
    x += w;
  }
  pictureBox3.Image = bmp3.Clone(new System.Drawing.Rectangle(0, 0, bmp3.Width, bmp3.Height),
     System.Drawing.Imaging.PixelFormat.Format24bppRgb);
}