Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.63 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace oop12
  11. {
  12. public partial class Form1 : Form
  13. {
  14. public Form1()
  15. {
  16. InitializeComponent();
  17. }
  18. public System.Drawing.Graphics desen;
  19. public System.Drawing.Pen creion_rosu;
  20. public osciloscop osciloscop1;
  21. int pozx = 40, pozy = 30, n_maxx = 250, n_maxy = 270;
  22. int val_max = 270;
  23. double d_max = 5, amplif, x, transl, pas;
  24. static int[] valori = new int[0];
  25. public class osciloscop
  26. {
  27. int x0;
  28. int y0;
  29. int w;
  30. int h;
  31. int val_max, val_max_af, val, val_v;
  32. int nr_max;
  33. System.Drawing.Graphics zona_des;
  34. System.Drawing.Pen creion_r = new System.Drawing.Pen(System.Drawing.Color.Red);
  35. System.Drawing.Font font_ni = new System.Drawing.Font("Nina", 8);
  36. System.Drawing.SolidBrush pens_blu = new System.Drawing.SolidBrush(System.Drawing.Color.Blue);
  37. System.Drawing.SolidBrush radiera = new System.Drawing.SolidBrush(System.Drawing.Color.White);
  38.  
  39. System.Drawing.Bitmap img;
  40. System.Drawing.Bitmap ims;
  41.  
  42. public void setval(int[] vals, int nrv)
  43. {
  44. img = new Bitmap(nr_max, val_max, zona_des);
  45. int i, j;
  46.  
  47. // afisare grafic sub forma de puncte
  48.  
  49. val_v = val_max - 1 - System.Convert.ToInt16(System.Convert.ToDouble(vals[0]) * (System.Convert.ToDouble(h) / System.Convert.ToDouble(val_max))); //scalare
  50. if (val_v >= val_max)
  51. val_v = val_max - 1;
  52. if (val_v <= 0)
  53. val_v = 1;
  54. for (i = 0; i < w; i++)
  55. {
  56. val = val_max - 1 - System.Convert.ToInt16(System.Convert.ToDouble(vals[i]) * (System.Convert.ToDouble(h) / System.Convert.ToDouble(val_max))); //scalare
  57. if (val >= val_max)
  58. val = val_max - 1;
  59. if (val <= 0)
  60. val = 1;
  61. if (val_v < val)
  62. {
  63. for (j = val_v; j <= val; j++)
  64. img.SetPixel(i, j, System.Drawing.Color.Red);
  65. }
  66. else
  67. {
  68. for (j = val; j <= val_v; j++)
  69. img.SetPixel(i, j, System.Drawing.Color.Red);
  70.  
  71. }
  72. val_v = val;
  73. }
  74. zona_des.DrawImage(ims, x0, y0);
  75. zona_des.DrawImage(img, x0, y0);
  76.  
  77. //valori axa x
  78. //zona_des.FillRectangle(radiera, x0, y0 + h, w + 20, 20); // pentru afisare dinamica valori axa x
  79.  
  80. for (i = 0; i <= w; i += 50)
  81. {
  82. val = System.Convert.ToInt16(System.Convert.ToDouble(i) * (System.Convert.ToDouble(nr_max) / System.Convert.ToDouble(w))); //scalare
  83. zona_des.DrawString(val.ToString(), font_ni, pens_blu, x0 + i, y0 + h);
  84. }
  85.  
  86. //valori axa y
  87. //zona_des.FillRectangle(radiera, x0 - 20, y0 - 10, 20, h + 20);// pentru afisare dinamica valori axa y
  88.  
  89. for (i = 0; i <= h; i += 50)
  90. {
  91. val = System.Convert.ToInt16(System.Convert.ToDouble(i) * (System.Convert.ToDouble(val_max_af) / System.Convert.ToDouble(h))); //scalare
  92. zona_des.DrawString(val.ToString(), font_ni, pens_blu, x0 - 20, y0 + h - i - 10);
  93. }
  94.  
  95. }
  96. public osciloscop(System.Drawing.Graphics desen, int pozx, int pozy, int n_maxx, int n_maxy, int vmaxa)
  97. {
  98. x0 = pozx;
  99. y0 = pozy;
  100. w = n_maxx;
  101. h = n_maxy;
  102. nr_max = n_maxx;
  103. val_max = n_maxy;
  104. val_max_af = vmaxa;
  105. zona_des = desen;
  106. int i, j;
  107. img = new Bitmap(nr_max, n_maxy, zona_des);
  108. ims = new Bitmap(nr_max, n_maxy, zona_des);
  109. // sterg imaginea
  110.  
  111. for (j = 0; j < val_max; j++)
  112. {
  113. for (i = 0; i < nr_max; i++)
  114. {
  115. ims.SetPixel(i, j, System.Drawing.Color.WhiteSmoke);
  116. }
  117. }
  118. // grid
  119. for (j = 0; j < val_max; j++)
  120. {
  121.  
  122. // grid orizontal
  123.  
  124.  
  125. if ((n_maxy - j - 1) % 10 == 0)
  126. {
  127. for (i = 0; i < nr_max; i++)
  128. {
  129. if ((n_maxy - j - 1) % 50 == 0)
  130. ims.SetPixel(i, j, System.Drawing.Color.Gray);
  131. else
  132. ims.SetPixel(i, j, System.Drawing.Color.LightGray);
  133. }
  134. }
  135. else
  136. {
  137.  
  138. // grid orizontal vertical
  139.  
  140. for (i = 0; i < nr_max; i++)
  141. {
  142. if (i % 10 == 0)
  143. {
  144. if (i % 50 == 0)
  145. ims.SetPixel(i, j, System.Drawing.Color.Gray);
  146. else
  147. ims.SetPixel(i, j, System.Drawing.Color.LightGray);
  148. }
  149. }
  150. }
  151. }
  152.  
  153. //chenar
  154.  
  155. for (i = 0; i < n_maxx; i++)
  156. {
  157. ims.SetPixel(i, 0, System.Drawing.Color.Blue);
  158. ims.SetPixel(i, val_max - 1, System.Drawing.Color.Blue);
  159. }
  160. for (j = 0; j < val_max; j++)
  161. {
  162. ims.SetPixel(0, j, System.Drawing.Color.Blue);
  163. ims.SetPixel(nr_max - 1, j, System.Drawing.Color.Blue);
  164. }
  165.  
  166. }
  167.  
  168. }
  169.  
  170. private void Form1_Load(object sender, EventArgs e)
  171. {
  172. Array.Resize(ref valori, n_maxx + 1);
  173. desen = this.CreateGraphics();
  174. osciloscop1 = new osciloscop(desen, pozx, pozy, n_maxx, n_maxy,val_max);
  175. }
  176.  
  177. private void trackBar1_Scroll(object sender, EventArgs e)
  178. {
  179. int amplif = this.trackBar1.Value;
  180. int transl = 0;
  181. double x =0;
  182. double pas = d_max / n_maxx;
  183. for (int i = 1; i <= n_maxx; i++)
  184. {
  185. // 1-e la x
  186. int f = System.Convert.ToInt32(transl + amplif * (Math.Pow(Math.E, x)));
  187. x += pas;
  188. valori[i] = f;
  189. }
  190. osciloscop1.setval(valori, n_maxx);
  191. }
  192.  
  193. private void Form1_Paint(object sender, PaintEventArgs e)
  194. {
  195. int amplif = this.trackBar1.Value;
  196. int transl = 0;
  197. double x = 0;
  198. double pas = d_max / n_maxx;
  199. for (int i = 1; i <= n_maxx; i++)
  200. {
  201. // 1-e la x
  202. int f = System.Convert.ToInt32(transl + amplif * (Math.Pow(Math.E, x)));
  203. x += pas;
  204. valori[i] = f;
  205. }
  206. osciloscop1.setval(valori, n_maxx);
  207. }
  208. }
  209. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement