public class osciloscop { int x0, y0, w, h, val, val_v; double v_max, v_min, x_max, x_min; System.Drawing.Graphics zona_des; System.Drawing.Font font_ni = new System.Drawing.Font("Nina", 8); Color cul_val; System.Drawing.Bitmap img; System.Drawing.Bitmap ims; public void sterg() { img = new Bitmap(ims); } public void display() { zona_des.DrawImage(img, x0, y0); } public void auto_sy(double val_max, double val_min) { if (val_max - val_min != 0) { v_max = val_max; v_min = val_min; } } public void auto_sx(double x_maxim, double x_minim) { if (x_max - x_min != 0) { x_max = x_maxim; x_min = x_minim; } else { x_max = w; x_min = 0; } } public void setval(double[] vals, int nrv, System.Drawing.Color culoare) { int i, j; if (w > 0 && h > 0) { double amplif; if ((v_max - v_min) != 0) amplif = (System.Convert.ToDouble(h) / System.Convert.ToDouble(v_max - v_min)); else amplif = 1; double transl = v_min * amplif; val_v = System.Convert.ToInt16(h + transl - amplif * System.Convert.ToDouble(vals[0])); //scalare if (val_v >= h) val_v = h - 1; if (val_v <= 0) val_v = 1; // afisare grafic sub forma de linii cu puncte for (i = 0; i < w; i++) { val = System.Convert.ToInt16(h + transl - amplif * System.Convert.ToDouble(vals[i])); //scalare if (val >= h) val = h - 1; if (val <= 0) val = 1; if (val_v < val) { // unesc doua puncte cu o linie crescatoare for (j = val_v; j <= val; j++) { img.SetPixel(i, j, culoare); } } else { // unesc doua puncte cu o linie descrescatoare for (j = val; j <= val_v; j++) { img.SetPixel(i, j, culoare); } } val_v = val; } Graphics g = Graphics.FromImage(img); //valori axa x double vx = x_min; double pasx = System.Convert.ToDouble(x_max - x_min) / System.Convert.ToDouble(w) * 50; for (i = 50; i < w; i += 50) { vx = vx + pasx; g.DrawString(Math.Round(vx, 2).ToString(), font_ni, new SolidBrush(cul_val), i, h - 15); } //valori axa y double vy = v_min; double pasy = System.Convert.ToDouble(v_max - v_min) / System.Convert.ToDouble(h) * 50; for (i = 50; i < h; i += 50) { vy = vy + pasy; g.DrawString(Math.Round(vy, 2).ToString(), font_ni, new SolidBrush(cul_val), 2, h - i - 10); } } } public osciloscop(System.Drawing.Graphics desen, int pozx, int pozy, int n_maxx, int n_maxy, double val_max, double val_min, Color culoare_fundal, Color culoare_grid_m, Color culoare_grid, Color culoare_valori) { x0 = pozx; y0 = pozy; w = n_maxx; h = n_maxy; v_max = val_max; v_min = val_min; x_max = n_maxx; x_min = 0; zona_des = desen; cul_val = culoare_valori; if (w > 0 && h > 0) { img = new Bitmap(w, h, zona_des); ims = new Bitmap(w, h, zona_des); int i = 0, j = 0; // sterg imaginea for (j = 0; j < h; j++) { for (i = 0; i < w; i++) { ims.SetPixel(i, j, culoare_fundal); } } // grid for (j = 0; j < h; j++) { // grid orizontal if (j % 10 == 0) { for (i = 0; i < w; i++) { if (j % 50 == 0) ims.SetPixel(i, j, culoare_grid_m); else ims.SetPixel(i, j, culoare_grid); } } else { // grid orizontal vertical for (i = 0; i < w; i++) { if (i % 10 == 0) { if (i % 50 == 0) ims.SetPixel(i, j, culoare_grid_m); else ims.SetPixel(i, j, culoare_grid); } } } } //chenar for (i = 0; i < w; i++) { ims.SetPixel(i, 0, culoare_grid_m); ims.SetPixel(i, h - 1, culoare_grid_m); } for (j = 0; j < h; j++) { ims.SetPixel(0, j, culoare_grid_m); ims.SetPixel(w - 1, j, culoare_grid_m); } Graphics s = Graphics.FromImage(ims); sterg(); } } }