namespace Oop_instr_20 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public System.Drawing.Graphics desen; public System.Drawing.Pen creion_albastru; public System.Drawing.Pen creion_gri; public System.Drawing.SolidBrush radiera; public System.Drawing.SolidBrush pensula_rosie; public System.Drawing.Font font_nina; public termo instr; public System.Random nr; private void Form1_Load(object sender, EventArgs e) { desen = this.CreateGraphics(); creion_albastru = new System.Drawing.Pen(System.Drawing.Color.Blue); creion_gri = new System.Drawing.Pen(System.Drawing.Color.Gray); radiera = new System.Drawing.SolidBrush(this.BackColor); pensula_rosie = new System.Drawing.SolidBrush(System.Drawing.Color.Red); font_nina = new System.Drawing.Font("Nina", 8); nr = new System.Random(); instr = new termo(); instr.init_ins(100, 20, 10, 150, 1500); } private void Form1_Paint(object sender, PaintEventArgs e) { instr.desenez(desen, creion_albastru, creion_gri, pensula_rosie,font_nina); } private void timer1_Tick(object sender, EventArgs e) { instr.sterg(desen, radiera); instr.setval(nr.Next(1500), desen, pensula_rosie); } } public class termo { float x0; float y0; float w; float h; float val_max; public void desenez(System.Drawing.Graphics zona_des, System.Drawing.Pen creion_a, System.Drawing.Pen creion_gr,System.Drawing.SolidBrush pens_r,System.Drawing.Font font_ni) { zona_des.DrawRectangle(creion_a, x0, y0, w, h); for (int j = 0; j <= h; j += 5)// desenez gradatii { if (j % 25 == 0) { zona_des.DrawLine(creion_gr, x0 + w + 2, y0 + j, x0 + w + 12, y0 + j); zona_des.DrawString(System.Convert.ToString(val_max - j * val_max / h), font_ni, pens_r, x0 + w + 20, y0 + j - 7); } else { zona_des.DrawLine(creion_gr, x0 + w + 2, y0 + j, x0 + w + 7, y0 + j); } } } public void sterg(System.Drawing.Graphics zona_des, System.Drawing.SolidBrush rad) { zona_des.FillRectangle(rad, x0 + 1, y0 + 1, w - 1, h - 1); } public void setval(float val, System.Drawing.Graphics zona_des, System.Drawing.SolidBrush pens_r) { val = System.Convert.ToInt16(System.Convert.ToDouble(val) * (System.Convert.ToDouble(h) / System.Convert.ToDouble(val_max))); //scalare zona_des.FillRectangle(pens_r, x0 + 1, y0+h-val, w - 1, val); } public void init_ins(float pozx, float pozy, float lat, float inalt, float vmax) { x0 = pozx; y0 = pozy; w = lat; h = inalt; val_max = vmax; } } } |
namespace Oop_instr_21 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public System.Drawing.Graphics desen; public termo instr_1; public termo instr_2; public termo instr_3; public termo instr_4; public System.Random nr; private void Form1_Load(object sender, EventArgs e) { desen = this.CreateGraphics(); nr = new System.Random(); instr_1 = new termo(desen,100, 20, 15, 150, -1000, 1500); instr_2 = new termo(desen, 200, 40, 10, 100, -500, 500); instr_3 = new termo(desen, 300, 100, 7, 50, 0, 50); instr_4 = new termo(desen, 400, 10, 20, 200, -100, 225); } private void Form1_Paint(object sender, PaintEventArgs e) { instr_1.desenez(Color.Red, Color.Green); instr_2.desenez(Color.Green, Color.Red); instr_3.desenez(Color.Blue, Color.Magenta); instr_4.desenez(Color.Magenta, Color.Blue); } private void timer1_Tick(object sender, EventArgs e) { instr_1.setval(nr.Next(-1000, 1700), Color.Red, Color.Yellow); instr_2.setval(nr.Next(-500, 500), Color.Magenta, Color.Wheat); instr_3.setval(nr.Next(0, 50), Color.Lime, Color.WhiteSmoke); instr_4.setval(nr.Next(-100, 225), Color.Orange, Color.Azure); } } public class termo { System.Drawing.Graphics zona_des; float x0; float y0; float w; float h; float val_max; float val_min; public void desenez(System.Drawing.Color culoare_contur, System.Drawing.Color culoare_gradatii) { System.Drawing.Pen creion_a = new System.Drawing.Pen(culoare_contur); System.Drawing.Pen creion_gr = new System.Drawing.Pen(Color.Gray); System.Drawing.SolidBrush pens_gr = new System.Drawing.SolidBrush(culoare_gradatii); System.Drawing.Font font_ni = new System.Drawing.Font("Nina", 8); zona_des.DrawRectangle(creion_a, x0, y0, w, h); for (int j = 0; j <= h; j += 5)// desenez gradatii { if (j % 25 == 0) { zona_des.DrawLine(creion_gr, x0 + w + 2, y0 + j, x0 + w + 12, y0 + j); zona_des.DrawString(System.Convert.ToString(val_max - j * (val_max - val_min) / h), font_ni, pens_gr, x0 + w + 20, y0 + j - 7); } else { zona_des.DrawLine(creion_gr, x0 + w + 2, y0 + j, x0 + w + 7, y0 + j); } } } public void setval(float val, System.Drawing.Color culoare_afisare, System.Drawing.Color culoare_radiera) { System.Drawing.SolidBrush pens_r = new System.Drawing.SolidBrush(culoare_afisare); System.Drawing.SolidBrush rad = new System.Drawing.SolidBrush(culoare_radiera); zona_des.FillRectangle(rad, x0 + 1, y0 + 1, w - 1, h - 1); if (val > val_max) val = val_max; if (val < val_min) val = val_min; val = System.Convert.ToInt16(System.Convert.ToDouble(val - val_min) * (System.Convert.ToDouble(h) / System.Convert.ToDouble(val_max - val_min))); //scalare zona_des.FillRectangle(pens_r, x0 + 1, y0 + h - val, w - 1, val); } public termo( System.Drawing.Graphics desen,float pozx, float pozy, float lat, float inalt, float vmin, float vmax) { zona_des = desen; x0 = pozx; y0 = pozy; w = lat; h = inalt; val_max = vmax; val_min = vmin; } } } |
namespace Oop_instr_70 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public System.Drawing.Graphics desen; public ser ser_1; public ser ser_2; public System.Random nr; private void Form1_Shown(object sender, EventArgs e) { desen = this.CreateGraphics(); nr = new System.Random(); ser_1 = new ser(desen,100, 40, 150, 15, 10, 0, 50); ser_2 = new ser(desen,200, 140, 200, 50, 25, 0, 100); ser_1.desenez(Color.Blue, Color.LightGray, Color.Magenta); ser_2.desenez(Color.Red, Color.Blue, Color.Magenta); } private void timer1_Tick(object sender, EventArgs e) { ser_1.setval(nr.Next(0, 50), Color.Magenta, Color.Blue, Color.White); ser_2.setval(nr.Next(0, 100), Color.Azure, Color.Blue, Color.White); } } public class ser { System.Drawing.Graphics zona_des; float x0; //pozitia pe x float y0; //pozitia pe y float w; //latimea float wp; //latimea pistonului float h; //inaltimea float val_max; //valoarea maxima float val_min; //valoarea minima public void desenez(System.Drawing.Color culoare_contur, System.Drawing.Color culoare_gradatii, System.Drawing.Color culoare_valori) { System.Drawing.Pen creion_contur = new System.Drawing.Pen(culoare_contur); System.Drawing.Pen creion_gradatii = new System.Drawing.Pen(culoare_gradatii); System.Drawing.SolidBrush pens_valori = new System.Drawing.SolidBrush(culoare_valori); System.Drawing.Font font_ni = new System.Drawing.Font("Nina", 8); zona_des.DrawRectangle(creion_contur, x0, y0, w+wp, h); for (int i = 0; i <= w; i += 5)// desenez gradatii { if (i % 25 == 0) { zona_des.DrawLine(creion_gradatii, x0 + i, y0 + h+12, x0 + i, y0 + h+1); zona_des.DrawString(System.Convert.ToString(val_min + (int) (i * (val_max - val_min) / w)), font_ni, pens_valori, x0+i-5, y0 + h+15); } else { zona_des.DrawLine(creion_gradatii, x0 + i, y0 + h+1, x0 + i, y0 + h+7); } } } public void setval(float val, System.Drawing.Color culoare_ser, System.Drawing.Color culoare_piston, System.Drawing.Color culoare_radiera) { System.Drawing.SolidBrush pens_ser = new System.Drawing.SolidBrush(culoare_ser); System.Drawing.SolidBrush pens_piston = new System.Drawing.SolidBrush(culoare_piston); System.Drawing.SolidBrush rad = new System.Drawing.SolidBrush(culoare_radiera); zona_des.FillRectangle(rad, x0 + 1, y0 + 1, w+wp-1, h - 1); if (val > val_max) val = val_max; if (val < val_min) val = val_min; val = System.Convert.ToInt16(System.Convert.ToDouble(val - val_min) * (System.Convert.ToDouble(w) / System.Convert.ToDouble(val_max - val_min))); //scalare zona_des.FillRectangle(pens_ser, x0 + 1, y0 + 1, val, h-1); zona_des.FillRectangle(pens_piston, x0+1 + val, y0+1, wp-2, h-1); zona_des.FillRectangle(pens_piston, x0+1 + val, y0+1 + h / 2-1, w-val+wp, 2); } public ser(System.Drawing.Graphics desen, float pozx, float pozy, float lat, float inalt, float w_piston, float vmin, float vmax) { zona_des = desen; x0 = pozx; y0 = pozy; w = lat; wp = w_piston; h = inalt; val_max = vmax; val_min = vmin; } } } |
namespace instrum_0 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public System.Drawing.Graphics desen; public System.Drawing.Pen creion_albastru; public System.Drawing.SolidBrush radiera; System.Random nr; float x0=50; float y0=40; float w=140; float h=100; float val_max=220; float val; private void Form1_Load(object sender, EventArgs e) { desen = this.CreateGraphics(); creion_albastru = new System.Drawing.Pen(System.Drawing.Color.Blue); radiera = new System.Drawing.SolidBrush(this.BackColor); nr = new System.Random(); } private void timer1_Tick(object sender, EventArgs e) { desen.FillRectangle(radiera, x0 + 1, y0 + 1, w - 1, h - 1); desen.DrawRectangle(creion_albastru, x0, y0, w, h); val = nr.Next(System.Convert.ToInt16(val_max)); val = System.Convert.ToInt16(System.Convert.ToDouble(val) * (System.Convert.ToDouble(w) / System.Convert.ToDouble(val_max))); //scalare desen.DrawLine(creion_albastru, (x0 + w / 2), h + y0, val + x0, y0 + 10); } } } |
namespace Oop_instr_00 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public System.Drawing.Graphics desen; public System.Drawing.Pen creion_albastru; public System.Drawing.SolidBrush radiera; public voltm instr; System.Random nr; private void Form1_Load(object sender, EventArgs e) { desen = this.CreateGraphics(); creion_albastru = new System.Drawing.Pen(System.Drawing.Color.Blue); radiera = new System.Drawing.SolidBrush(this.BackColor); nr = new System.Random(); instr = new voltm(); instr.init_ins(100,100,100,75,1500); } private void Form1_Paint(object sender, PaintEventArgs e) { instr.desenez(desen, creion_albastru); } private void timer1_Tick(object sender, EventArgs e) { instr.sterg(desen, radiera); instr.setval(nr.Next(1500),desen, creion_albastru); } } public class voltm { float x0; float y0; float w; float h; float val_max; public void desenez(System.Drawing.Graphics zona_des, System.Drawing.Pen creion_a) { zona_des.DrawRectangle(creion_a, x0, y0, w, h); } public void sterg(System.Drawing.Graphics zona_des, System.Drawing.Brush rad) { zona_des.FillRectangle(rad, x0+1, y0+1, w-1, h-1); } public void setval(float val, System.Drawing.Graphics zona_des, System.Drawing.Pen creion) { val = System.Convert.ToInt16(System.Convert.ToDouble(val) * (System.Convert.ToDouble(w) / System.Convert.ToDouble(val_max))); //scalare zona_des.DrawLine(creion, (x0 + w / 2), h + y0, val + x0, y0 + 10); } public void init_ins(float pozx, float pozy, float lat,float inalt,float vmax) { x0=pozx; y0=pozy; w=lat; h=inalt; val_max = vmax; } } } |
namespace Oop_instr_000 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public System.Drawing.Graphics desen; public System.Drawing.Pen creion_albastru; public System.Drawing.SolidBrush radiera; public voltm instr; System.Random nr; private void Form1_Load(object sender, EventArgs e) { desen = this.CreateGraphics(); creion_albastru = new System.Drawing.Pen(System.Drawing.Color.Blue); radiera = new System.Drawing.SolidBrush(this.BackColor); nr = new System.Random(); instr = new voltm(100, 100, 100, 75, 1500); } private void Form1_Paint(object sender, PaintEventArgs e) { instr.desenez(desen, creion_albastru); } private void timer1_Tick(object sender, EventArgs e) { instr.sterg(desen, radiera); instr.setval(nr.Next(1500), desen, creion_albastru); } } public class voltm { float x0; float y0; float w; float h; float val_max; public void desenez(System.Drawing.Graphics zona_des, System.Drawing.Pen creion_a) { zona_des.DrawRectangle(creion_a, x0, y0, w, h); } public void sterg(System.Drawing.Graphics zona_des, System.Drawing.Brush rad) { zona_des.FillRectangle(rad, x0 + 1, y0 + 1, w - 1, h - 1); } public void setval(float val, System.Drawing.Graphics zona_des, System.Drawing.Pen creion) { val = System.Convert.ToInt16(System.Convert.ToDouble(val) * (System.Convert.ToDouble(w) / System.Convert.ToDouble(val_max))); //scalare zona_des.DrawLine(creion, (x0 + w / 2), h + y0, val + x0, y0 + 10); } public voltm(float pozx, float pozy, float lat, float inalt, float vmax) { x0 = pozx; y0 = pozy; w = lat; h = inalt; val_max = vmax; } } } |
namespace Oop_instr_01 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public System.Drawing.Graphics desen; public System.Drawing.Pen creion_albastru; public System.Drawing.SolidBrush radiera; public voltm instr_1; public voltm instr_2; public voltm instr_3; System.Random nr; private void Form1_Load(object sender, EventArgs e) { desen = this.CreateGraphics(); creion_albastru = new System.Drawing.Pen(System.Drawing.Color.Blue); radiera = new System.Drawing.SolidBrush(this.BackColor); nr = new System.Random(); instr_1 = new voltm(); instr_1.init_ins(100, 50, 100, 75, 1500); instr_2 = new voltm(); instr_2.init_ins(300, 75, 80, 100, 20); instr_3 = new voltm(); instr_3.init_ins(100, 150, 180, 100, 400); } private void Form1_Paint(object sender, PaintEventArgs e) { instr_1.desenez(desen, creion_albastru); instr_2.desenez(desen, creion_albastru); instr_3.desenez(desen, creion_albastru); } private void timer1_Tick(object sender, EventArgs e) { instr_1.sterg(desen, radiera); instr_1.setval(nr.Next(1500), desen, creion_albastru); instr_2.sterg(desen, radiera); instr_2.setval(nr.Next(20), desen, creion_albastru); instr_3.sterg(desen, radiera); instr_3.setval(nr.Next(400), desen, creion_albastru); } } public class voltm { float x0; float y0; float w; float h; float val_max; public void desenez(System.Drawing.Graphics zona_des, System.Drawing.Pen creion_a) { zona_des.DrawRectangle(creion_a, x0, y0, w, h); } public void sterg(System.Drawing.Graphics zona_des, System.Drawing.Brush rad) { zona_des.FillRectangle(rad, x0 + 1, y0 + 1, w - 1, h - 1); } public void setval(float val, System.Drawing.Graphics zona_des, System.Drawing.Pen creion) { val = System.Convert.ToInt16(System.Convert.ToDouble(val) * (System.Convert.ToDouble(w) / System.Convert.ToDouble(val_max))); //scalare zona_des.DrawLine(creion, (x0 + w / 2), h + y0, val + x0, y0 + 10); } public void init_ins(float pozx, float pozy, float lat, float inalt, float vmax) { x0 = pozx; y0 = pozy; w = lat; h = inalt; val_max = vmax; } } } |
namespace Oop_instr_02 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } System.Drawing.Graphics Desen; System.Drawing.Pen Creion_rosu; System.Drawing.SolidBrush Pens_blu; System.Drawing.SolidBrush Pens_back; public voltm voltm1; public voltm voltm2; public voltm voltm3; System.Random nr; int alfa; public class voltm { int x0; int y0; int w; int h; public void setval(System.Drawing.Graphics zona_des, System.Drawing.Pen creion, System.Drawing.SolidBrush radiera, int alfa_gr) { // alfa_gr unghiul in grade int xc = x0 + w / 2; int yc = y0 + w / 2; int raza = w / 2; zona_des.FillEllipse(radiera, x0, y0, w, w); double alfa_r = 2 * System.Math.PI * (alfa_gr) / 360;// unghiul in radiani int x = System.Convert.ToInt16(xc + raza * System.Math.Cos(alfa_r)); int y = System.Convert.ToInt16(yc - raza * System.Math.Sin(alfa_r)); zona_des.DrawRectangle(creion, xc - raza, yc - raza, 2 * raza, 5 * raza / 4); zona_des.DrawArc(creion, xc - raza, yc - raza, 2 * raza, 2 * raza, -30, -120); zona_des.DrawLine(creion, x, y, xc, yc); } public void init_voltm(int pozx, int pozy, int lat, int inalt) { x0 = pozx; y0 = pozy; w = lat; h = inalt; } } private void Form1_Load(object sender, EventArgs e) { Creion_rosu = new System.Drawing.Pen(System.Drawing.Color.Red); Pens_blu = new System.Drawing.SolidBrush(System.Drawing.Color.Blue); Pens_back = new System.Drawing.SolidBrush(this.BackColor); Desen = this.CreateGraphics(); nr = new System.Random(); voltm1 = new voltm(); voltm1.init_voltm(10, 100, 100, 75); voltm2 = new voltm(); voltm2.init_voltm(200, 50, 120, 55); voltm3 = new voltm(); voltm3.init_voltm(150, 200, 50, 175); } private void timer1_Tick(object sender, EventArgs e) { voltm1.setval(Desen, Creion_rosu, Pens_back, alfa); voltm2.setval(Desen, Creion_rosu, Pens_back, alfa); voltm3.setval(Desen, Creion_rosu, Pens_back, alfa); alfa -= 7; if (alfa < 40) alfa = 140; } } } |
namespace Oop_instr_03 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } System.Drawing.Graphics Desen; System.Drawing.Pen Creion_rosu; System.Drawing.SolidBrush Pens_blu; System.Drawing.SolidBrush Pens_back; public voltm voltm1; public voltm voltm2; public voltm voltm3; System.Random nr; int alfa; public class voltm { int x0; int y0; int w; public void desen_voltm(System.Drawing.Graphics zona_des, System.Drawing.Pen creion, System.Drawing.SolidBrush radiera) { int lg = 5; int x1, x2, y1, y2; int xc = x0 + w / 2; int yc = y0 + w / 2; int raza = w / 2; int nrd; // alfa_gr unghiul in grade double alfa_gr = 40; nrd = 0; while (alfa_gr <= 140) { double alfa_r = 2 * System.Math.PI * (alfa_gr) / 360;// unghiul in radiani if (nrd % 5 == 0) { x1 = System.Convert.ToInt16(xc + raza * System.Math.Cos(alfa_r)); y1 = System.Convert.ToInt16(yc - raza * System.Math.Sin(alfa_r)); } else { x1 = System.Convert.ToInt16(xc + (raza - lg) * System.Math.Cos(alfa_r)); y1 = System.Convert.ToInt16(yc - (raza - lg) * System.Math.Sin(alfa_r)); } x2 = System.Convert.ToInt16(xc + (raza - 2 * lg) * System.Math.Cos(alfa_r)); y2 = System.Convert.ToInt16(yc - (raza - 2 * lg) * System.Math.Sin(alfa_r)); zona_des.DrawLine(creion, x1, y1, x2, y2); alfa_gr += 2; nrd++; } zona_des.DrawRectangle(creion, xc - raza, yc - raza - 2, 2 * raza, 5 * raza / 4); } public void setval(System.Drawing.Graphics zona_des, System.Drawing.Pen creion, System.Drawing.SolidBrush radiera, int alfa_gr) { // alfa_gr unghiul in grade int lg = 5; int xc = x0 + w / 2; int yc = y0 + w / 2; int raza = w / 2; zona_des.FillPie(radiera, x0 + 2 * lg-1, y0 + 2 * lg-1, w - 4 * lg+2, w - 4 * lg+2, 10, -180); double alfa_r = 2 * System.Math.PI * (alfa_gr) / 360;// unghiul in radiani int x = System.Convert.ToInt16(xc + (raza-2*lg) * System.Math.Cos(alfa_r)); int y = System.Convert.ToInt16(yc - (raza-2*lg) * System.Math.Sin(alfa_r)); zona_des.DrawLine(creion, x, y, xc, yc); alfa_gr = 40; zona_des.DrawRectangle(creion, xc - raza, yc - raza-2, 2 * raza, 5 * raza / 4); } public void init_voltm(int pozx, int pozy, int lat) { x0 = pozx; y0 = pozy; w = lat; } } private void Form1_Load(object sender, EventArgs e) { Creion_rosu = new System.Drawing.Pen(System.Drawing.Color.Red); Pens_blu = new System.Drawing.SolidBrush(System.Drawing.Color.Blue); Pens_back = new System.Drawing.SolidBrush(this.BackColor); Desen = this.CreateGraphics(); nr = new System.Random(); voltm1 = new voltm(); voltm1.init_voltm(10, 10, 290); voltm2 = new voltm(); voltm2.init_voltm(320, 155, 220); voltm3 = new voltm(); voltm3.init_voltm(550, 30, 150); } private void Form1_Paint(object sender, PaintEventArgs e) { voltm1.desen_voltm(Desen, Creion_rosu, Pens_back); voltm2.desen_voltm(Desen, Creion_rosu, Pens_back); voltm3.desen_voltm(Desen, Creion_rosu, Pens_back); } private void timer1_Tick(object sender, EventArgs e) { voltm1.setval(Desen, Creion_rosu, Pens_back, alfa); voltm2.setval(Desen, Creion_rosu, Pens_back, alfa); voltm3.setval(Desen, Creion_rosu, Pens_back, alfa); alfa -= 7; if (alfa < 40) alfa = 140; } } } |
namespace Oop_instr_04 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } System.Drawing.Graphics Desen; System.Random nr; double u1,u2,u3; double um1 = 500; double um2 = 300; double um3 = 250; public voltm voltm1; public voltm voltm2; public voltm voltm3; private void Form1_Shown(object sender, EventArgs e) { Desen = this.CreateGraphics(); nr = new System.Random(); voltm1 = new voltm(Desen,10, 10, 290,um1,Color.Black); voltm2 = new voltm(Desen, 320, 160, 220, um2, Color.Azure); voltm3 = new voltm(Desen, 370, 20, 200, um3, this.BackColor); voltm1.desen_voltm(Color.Blue,Color.Red); voltm2.desen_voltm(Color.Orange, Color.Magenta); voltm3.desen_voltm(Color.Red, Color.Blue); } private void timer1_Tick(object sender, EventArgs e) { if (u1 > um1) u1 = 0; voltm1.setval(u1, Color.Red); u1 += 10; if (u2 > um2) u2 = 0; voltm2.setval(u2, Color.Blue); u2 += 25; if (u3 > um3) u3 = 0; voltm3.setval(u3, Color.Magenta); u3 += 25; } } public class voltm { System.Drawing.SolidBrush radiera; System.Drawing.Graphics zona_des; int x0; int y0; int w; double vm; public void desen_voltm(System.Drawing.Color culoare_gradatii, System.Drawing.Color culoare_valori) { System.Drawing.Pen creion = new System.Drawing.Pen(culoare_gradatii); System.Drawing.Font font_ni = new System.Drawing.Font("Nina", 8); System.Drawing.SolidBrush pens_blu = new System.Drawing.SolidBrush(culoare_valori); int lt = 15; int lg = 22; int x1, x2, xt, y1, y2, yt; int xc = x0 + w / 2; int yc = y0 + w / 2; int raza = w / 2; int nrd; int val_a = 0; // alfa_gr unghiul in grade double alfa_gr = 140; nrd = 0; zona_des.FillRectangle(radiera, xc - raza, yc - raza - 2, 2 * raza, 5 * raza / 4); while (alfa_gr >= 40) { double alfa_r = 2 * System.Math.PI * (alfa_gr) / 360;// unghiul in radiani if (nrd % 5 == 0) { x1 = System.Convert.ToInt16(xc + (raza - lt) * System.Math.Cos(alfa_r)); y1 = System.Convert.ToInt16(yc - (raza - lt) * System.Math.Sin(alfa_r)); xt = System.Convert.ToInt16(xc - 5 + raza * System.Math.Cos(alfa_r)); yt = System.Convert.ToInt16(yc - raza * System.Math.Sin(alfa_r)); zona_des.DrawString(System.Convert.ToString(val_a), font_ni, pens_blu, xt, yt); val_a = val_a + System.Convert.ToInt16(vm / 10); } else { x1 = System.Convert.ToInt16(xc + (raza - lg) * System.Math.Cos(alfa_r)); y1 = System.Convert.ToInt16(yc - (raza - lg) * System.Math.Sin(alfa_r)); } x2 = System.Convert.ToInt16(xc + (raza - 2 * lt) * System.Math.Cos(alfa_r)); y2 = System.Convert.ToInt16(yc - (raza - 2 * lt) * System.Math.Sin(alfa_r)); zona_des.DrawLine(creion, x1, y1, x2, y2); alfa_gr -= 2; nrd++; } zona_des.DrawRectangle(creion, xc - raza, yc - raza - 2, 2 * raza, 5 * raza / 4); } public void setval(double val, System.Drawing.Color culoare_ac) { System.Drawing.Pen creion = new System.Drawing.Pen(culoare_ac); int alfa_gr = 140 - System.Convert.ToInt16(100 * val / vm); ;//unghiul in grade int lg = 17; int xc = x0 + w / 2; int yc = y0 + w / 2; int raza = w / 2; zona_des.FillPie(radiera, x0 + 2 * lg - 1, y0 + 2 * lg - 1, w - 4 * lg + 2, w - 4 * lg + 2, 10, -180); double alfa_r = 2 * System.Math.PI * (alfa_gr) / 360;// unghiul in radiani int x = System.Convert.ToInt16(xc + (raza - 2 * lg) * System.Math.Cos(alfa_r)); int y = System.Convert.ToInt16(yc - (raza - 2 * lg) * System.Math.Sin(alfa_r)); zona_des.DrawLine(creion, x, y, xc, yc); alfa_gr = 40; zona_des.DrawRectangle(creion, xc - raza, yc - raza - 2, 2 * raza, 5 * raza / 4); } public voltm(System.Drawing.Graphics desen, int pozx, int pozy, int lat, double val_max, Color culoare_fundal) { zona_des = desen; radiera = new System.Drawing.SolidBrush(culoare_fundal); x0 = pozx; y0 = pozy; w = lat; vm = val_max; } } } |
namespace Oop_instr_06 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } System.Drawing.Graphics Desen; System.Random nr; public voltm voltm1; double u1,um=250; private void Form1_Load(object sender, EventArgs e) { Desen = this.CreateGraphics(); nr = new System.Random(); //voltm1 = new voltm(10, 10, um,"e:\\voltm.jpg"); voltm1 = new voltm(10, 10, um, "voltm.jpg"); } private void timer1_Tick(object sender, EventArgs e) { if (u1 > um) u1 = 0; voltm1.setval(Desen, u1); u1 += 10; } // Clasa voltmetru public class voltm { System.Drawing.Pen creion = new System.Drawing.Pen(System.Drawing.Color.Red); System.Drawing.Font font_ni = new System.Drawing.Font("Nina", 14); System.Drawing.SolidBrush pens_blu = new System.Drawing.SolidBrush(System.Drawing.Color.Blue); System.Drawing.Bitmap img; System.Drawing.Bitmap ims; int x0,y0,w,h; double vm; public void setval(System.Drawing.Graphics zona_des, double val) { int alfa_gr = 140 - System.Convert.ToInt16(100 * val / vm); ;//unghiul in grade int lg = 5; int xc = w / 2; int yc = h-20; int raza = 3*w / 5; img = new Bitmap(ims); Graphics g = Graphics.FromImage(img); double alfa_r = 2 * System.Math.PI * (alfa_gr) / 360;// unghiul in radiani int x = System.Convert.ToInt16(xc + (raza - 2 * lg) * System.Math.Cos(alfa_r)); int y = System.Convert.ToInt16(yc - (raza - 2 * lg) * System.Math.Sin(alfa_r)); g.DrawLine(creion, x, y, xc, yc); alfa_gr = 40; g.DrawString(val.ToString(),font_ni, pens_blu,0,0); zona_des.DrawImage(img, x0, y0); } public voltm(int pozx, int pozy, double vmax, string fisier_img) { x0 = pozx; y0 = pozy; vm = vmax; ims = new Bitmap(fisier_img); w = ims.Width; h = ims.Height; } } // gata clasa voltmetru } } |
namespace Oop_instr_07 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public System.Drawing.Graphics desen; public anemom anemom1; public System.Random n; int pozx = 50, pozy = 30, diam = 280; private void Form1_Load(object sender, EventArgs e) { desen = this.CreateGraphics(); n = new System.Random(); anemom1 = new anemom(pozx, pozy, diam); } private void timer1_Tick(object sender, EventArgs e) { anemom1.setval(desen, n.Next(diam / 2), n.Next(360)); } // --------------Clasa anemometru ------------------ public class anemom { int x0, y0, w, val; int r, rc, ds, d, xm, ym, xv, yv, xc, yc; double ar, a, ai; System.Drawing.Graphics zona_des; System.Drawing.Pen creion_a = new System.Drawing.Pen(System.Drawing.Color.Gray); System.Drawing.Pen creion_r = new System.Drawing.Pen(System.Drawing.Color.Red); public void setval(System.Drawing.Graphics desen,int i_vant, int dir_v) { zona_des = desen; r = w / 2 - 1; ds = 2 * r / 9; // distanta dintre cercuri xc = x0+r; yc = y0+r; rc = 0; val = i_vant; ai = dir_v; // sterg zona_des.Clear(Color.White); // pun grid // cercuri concentrice rc = 0; for (d = 2 * r; d >= 0; d -= ds) { zona_des.DrawEllipse(creion_a, rc+x0, rc+y0, d, d); rc += ds / 2; } //raze in cerc for (a = 0; a < 360; a += 360 / 12) { ar = a * Math.PI / 180; xm = System.Convert.ToInt16(xc + r * Math.Sin(ar)); ym = System.Convert.ToInt16(yc - r * Math.Cos(ar)); zona_des.DrawLine(creion_a, xc, yc, xm, ym); } // fascicul de raze for (a = ai; a < (ai + 30); a += 360 / 120) { ar = a * Math.PI / 180; xm = System.Convert.ToInt16(xc + r * Math.Sin(ar)); ym = System.Convert.ToInt16(yc - r * Math.Cos(ar)); zona_des.DrawLine(creion_a, xc, yc, xm, ym); xv = System.Convert.ToInt16(xc + val * Math.Sin(ar)); yv = System.Convert.ToInt16(yc - val * Math.Cos(ar)); zona_des.DrawLine(creion_r, xc, yc, xv, yv); } } public anemom(int pozx, int pozy, int diam) { x0 = pozx; y0 = pozy; w = diam; } } // --------------Sfarsit clasa anemometru ------------------ } } |
namespace Oop_instr_08 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public System.Drawing.Graphics desen; public anemom anemom1; public System.Random n; int pozx = 50, pozy = 30, diam = 300; private void Form1_Load(object sender, EventArgs e) { desen = this.CreateGraphics(); n = new System.Random(); anemom1 = new anemom(desen, pozx, pozy, diam); } private void timer1_Tick(object sender, EventArgs e) { anemom1.setval(n.Next(diam / 2), n.Next(360)); } } // --------------Clasa anemometru ------------------ public class anemom { int x0, y0, w, val; int r, rc, ds, d, xm, ym, xv, yv, xc, yc, i, j; double ar, a, ai; System.Drawing.Graphics zona_des; System.Drawing.Pen creion_a = new System.Drawing.Pen(System.Drawing.Color.Gray); System.Drawing.Pen creion_r = new System.Drawing.Pen(System.Drawing.Color.Red); System.Drawing.Bitmap img; System.Drawing.Bitmap ims; public void setval(int i_vant, int dir_v) { val = i_vant;// intensitatea vantului -- maxim diam/2 ai = dir_v; if (w > 0) { // pun grid img = new Bitmap(ims); // fascicul de raze Graphics g = Graphics.FromImage(img); for (a = ai; a < (ai + 30); a += 360 / 120) { ar = a * Math.PI / 180; xm = System.Convert.ToInt16(xc + r * Math.Sin(ar)); ym = System.Convert.ToInt16(yc - r * Math.Cos(ar)); g.DrawLine(creion_a, xc, yc, xm, ym); if (val <= w / 2) { xv = System.Convert.ToInt16(xc + val * Math.Sin(ar)); yv = System.Convert.ToInt16(yc - val * Math.Cos(ar)); g.DrawLine(creion_r, xc, yc, xv, yv); } } } // afisez zona_des.DrawImage(img, x0, y0); } public anemom(System.Drawing.Graphics desen, int pozx, int pozy, int diam) { x0 = pozx; y0 = pozy; w = diam; r = w / 2 - 1; ds = Convert.ToInt32(2 * r / 10.0); // distanta dintre cercuri xc = w / 2; yc = w / 2; rc = 0; double ar, a; zona_des = desen; img = new Bitmap(w + 4, w + 4, zona_des); if (w > 0) { ims = new Bitmap(w + 4, w + 4, zona_des); Graphics g = Graphics.FromImage(ims); // sterg imaginea for (j = 0; j <= w + 3; j++) { for (i = 0; i <= w + 3; i++) { ims.SetPixel(i, j, System.Drawing.Color.White); } } // cercuri concentrice rc = 0; int k = 0; for (d = 2 * r; d >= 0; d -= ds) { g.DrawEllipse(creion_a, rc, rc, d, d); k++; rc = Convert.ToInt32(k * (ds / 2.0)); } //raze in cerc for (a = 0; a < 360; a += 360 / 12) { ar = a * Math.PI / 180; xm = System.Convert.ToInt16(xc + r * Math.Sin(ar)); ym = System.Convert.ToInt16(yc - r * Math.Cos(ar)); g.DrawLine(creion_a, xc, yc, xm, ym); } } } } // --------------Sfarsit clasa anemometru ------------------ } |
namespace Oop_instr_60 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public System.Drawing.Graphics desen; public manom manom1,manom2,manom3,manom4; public System.Random n; private void Form1_Load(object sender, EventArgs e) { desen = this.CreateGraphics(); n = new System.Random(); manom1 = new manom(desen, 20, 30, true, 200, 500); manom2 = new manom(desen, 230, 50, false, 160, 300); manom3 = new manom(desen, 400, 80, true, 100, 100); manom4 = new manom(desen, 520, 50, true, 150, 500); } private void timer1_Tick(object sender, EventArgs e) { manom1.setval(n.Next(500)); //manom1.setval(333); manom2.setval(n.Next(300)); //manom2.setval(210); manom3.setval(n.Next(100)); //manom3.setval(75); manom4.setval(n.Next(500)); //manom4.setval(425); } } // --------------Clasa manometru ------------------ public class manom { System.Drawing.Pen creion_lg, creion_rad, creion_g, creion_r; System.Drawing.SolidBrush pens_a, pens_r, pens_rad; System.Drawing.Font font_arial; System.Drawing.Graphics zona_des; System.Drawing.Bitmap img; Graphics g; int x0, y0, xi, xe, xm, xgr, xgm, xtx, w, val_m, diam_i, diam_e, diam_m, diam_gr, diam_gm, diam_tx; int gr; //grosimea arcului de cerc bool af_grd; // se afiseaza gradatii public void setval(int val) { int vl = val; int alfa = 360 * vl / val_m; // sterg interiorul g.FillEllipse(pens_rad, xe-1, xe-1, diam_e+2, diam_e+2); // trasez arc de cerc g.DrawArc(creion_lg, xm, xm, diam_m, diam_m, 90, alfa); if ((w >= 150) && af_grd) { g.DrawEllipse(creion_g, xi, xi, diam_i, diam_i); g.DrawEllipse(creion_g, xe, xe, diam_e, diam_e); } g.DrawString(vl.ToString(), font_arial, pens_r, (w - gr) / 2 - gr / 3, (w - gr) / 2 - 3*gr / 5); g.DrawString("/" + val_m.ToString(), font_arial, pens_a, (w - gr) / 2 - gr / 3, (w - gr) / 2 + gr / 2); // afisez imaginea zona_des.DrawImage(img, x0, y0); } public manom(System.Drawing.Graphics desen, int pozx, int pozy, bool af_gradatii, int diam, int val_max) { x0 = pozx; // pozitia pe x a instrumentului y0 = pozy; // pozitia pe y a instrumentului if(diam>99) w = diam; // latimea instrumentului else w = 100; // minima latimea instrumentului gr = w/11; // grosimea arcului de cerc af_grd = af_gradatii; // afisare gradatii diam_i = diam - 7 * gr; // diametrul cercului interior diam_e = diam_i + 2 * gr; // diametrul cercului exterior diam_m = (diam_e + diam_i) / 2; // diametrul cercului mediu pentru arcul de cerc diam_gr = diam_e + 2 * gr / 3; // diametrul cercului pentru gradatii diam_gm = diam_e + 4 * gr / 3; // diametrul cercului pentru gradatii mari diam_tx = diam_e + 3 * gr; // diametrul cercului pentru texte val_m = val_max; // valoarea maxima afisata xi = (w - diam_i) / 2; // coordonata pentru cercul interior xe = (w - diam_e) / 2; // coordonata pentru cercul exterior xm = (w - diam_m) / 2; // coordonata pentru cercul mediu xgr = (w - diam_gr) / 2; // coordonata pentru cercul gradatiilor mici xgm = (w - diam_gm) / 2; // coordonata pentru cercul gradatiilor mari xtx = (w - diam_tx)/2-gr/3; // coordonata pentru cercul valorilor creion_lg = new System.Drawing.Pen(System.Drawing.Color.LightGray, gr); creion_rad = new System.Drawing.Pen(System.Drawing.Color.White, gr); creion_g = new System.Drawing.Pen(System.Drawing.Color.Gray); creion_r = new System.Drawing.Pen(System.Drawing.Color.Blue); font_arial = new System.Drawing.Font("Arial", 10); pens_a = new System.Drawing.SolidBrush(System.Drawing.Color.Gray); pens_r = new System.Drawing.SolidBrush(System.Drawing.Color.Red); pens_rad = new System.Drawing.SolidBrush(System.Drawing.Color.White); zona_des = desen; img = new Bitmap(w, w, zona_des); g = Graphics.FromImage(img); g.FillRectangle(pens_rad, 0, 0, w + 2, w + 2); int k = 0; double grd; // grade hexazecimale // trasez gradatii si valori for (grd = 630; grd > 270; grd -= 3.6) { double rad = 2 * System.Math.PI * grd / 360; int x1 = Convert.ToInt16(xe + (diam_e / 2) + (diam_e / 2) * System.Math.Cos(rad)); int y1 = Convert.ToInt16(xe + (diam_e / 2) - (diam_e / 2) * System.Math.Sin(rad)); int x2 = Convert.ToInt16(xgr + (diam_gr / 2) + (diam_gr / 2) * System.Math.Cos(rad)); int y2 = Convert.ToInt16(xgr + (diam_gr / 2) - (diam_gr / 2) * System.Math.Sin(rad)); int x3 = Convert.ToInt16(xgm + (diam_gm / 2) + (diam_gm / 2) * System.Math.Cos(rad)); int y3 = Convert.ToInt16(xgm + (diam_gm / 2) - (diam_gm / 2) * System.Math.Sin(rad)); int x4 = Convert.ToInt16(xtx + (diam_tx / 2) + (diam_tx / 2) * System.Math.Cos(rad)); int y4 = Convert.ToInt16(xtx + (diam_tx / 2) - (diam_tx / 2) * System.Math.Sin(rad)); if ((w >= 150) && af_grd) { if (k % 10 != 0) { if(w>=200) g.DrawLine(creion_g, x1, y1, x2, y2); } else { g.DrawLine(creion_r, x1, y1, x3, y3); g.DrawString((k * val_m / 100).ToString(), font_arial, pens_a, x4 - gr / 2, y4); } k++; } } } } // --------------Sfarsit clasa manometru ------------------ } |
namespace Oop_instr_80 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public System.Drawing.Graphics desen; public barom barom1, barom2, barom3; public System.Random n; private void Form1_Load(object sender, EventArgs e) { desen = this.CreateGraphics(); n = new System.Random(); barom1 = new barom(desen, 20, 10, 200, 90, 270, 10, 0, 270, "bar"); barom2 = new barom(desen, 250, 10, 300, 120, 300, 10, 300, 1200, " hPa"); barom3 = new barom(desen, 100, 220, 100, 135, 225, 10, 250, 1150, "Psi"); } private void timer1_Tick(object sender, EventArgs e) { barom1.setval(n.Next(0, 270)); //barom1.setval(97); barom2.setval(n.Next(300, 1200)); //barom2.setval(490); barom3.setval(n.Next(250, 1150)); //barom3.setval(390); } } // --------------Clasa barometru ------------------ public class barom { System.Drawing.Graphics zona_des; System.Drawing.Bitmap img; Graphics g; System.Drawing.Pen creion_g = new System.Drawing.Pen(System.Drawing.Color.Blue); System.Drawing.Pen creion_g2 = new System.Drawing.Pen(System.Drawing.Color.Blue, 2); System.Drawing.Pen creion_g10 = new System.Drawing.Pen(System.Drawing.Color.LightBlue, 12); System.Drawing.Pen creion_r = new System.Drawing.Pen(System.Drawing.Color.Red); System.Drawing.Pen creion_r2 = new System.Drawing.Pen(System.Drawing.Color.Red, 2); System.Drawing.Pen creion_r10 = new System.Drawing.Pen(System.Drawing.Color.Red, 12); System.Drawing.Font font_arial = new System.Drawing.Font("Arial", 10, FontStyle.Bold); System.Drawing.Font font_arial2 = new System.Drawing.Font("Arial", 16, FontStyle.Bold); System.Drawing.SolidBrush pens_a = new System.Drawing.SolidBrush(System.Drawing.Color.Blue); System.Drawing.SolidBrush pens_r = new System.Drawing.SolidBrush(System.Drawing.Color.Red); System.Drawing.SolidBrush pens_rad = new System.Drawing.SolidBrush(System.Drawing.Color.White); int x0; // pozitia pe x a instrumentului int y0; // pozitia pe y a instrumentului int wd; // latimea int alfa_st; // unghiul de inceput in grade int alfa_w; // marimea unghiului in grade int gd; // grade pe diviziune double vmin; // valoarea minima double vmax; // valoarea maxima string um; // unitatea de masura public barom(System.Drawing.Graphics desen, int x, int y, int wi, int gr_st, int gr_w, int gr_d, double vmn, double vmx, string u_m) { zona_des = desen; // desenul x0 = x; // pozitia pe x a instrumentului y0 = y; // pozitia pe y a instrumentului wd = wi; // latimea alfa_st = gr_st; // unghiul de inceput in grade alfa_w = gr_w; // unghiul de sfarfit in grade gd = gr_d; // grade pe diviziune vmin = vmn; // valoarea minima vmax = vmx; // valoarea maxima um = u_m; // unitatea de masura } public void setval(double val) { int x1, x2, xt, y1, y2, yt; int xc = wd / 2; int yc = wd / 2; int raza = (wd - wd / 3) / 2; int sd = 0; // semafor (diviziune cu text sau fara text) int nrd = 0; // nr diviziuni double val_c = val; // valoarea curenta double val_gr; // valoarea de afisat in grade double val_a = vmin; // valori afisate de pe cadran double alfa_r = 0; // unghi in radiani double alfa_gr = 0; // unghi in grade int lt = wd / 12; // valoare distantier img = new Bitmap(wd + 2, wd + 20, zona_des); g = Graphics.FromImage(img); // sterg continutul imaginii //g.FillEllipse(pens_rad, 0, 0, wd+2, wd+2); g.FillRectangle(pens_rad, 0, 0, wd + 2, wd + 2); // desenez arc fundal g.DrawArc(creion_g10, 2 * lt, 2 * lt, wd - 4 * lt, wd - 4 * lt, alfa_st, alfa_w); g.DrawArc(creion_r10, 2 * lt, 2 * lt, wd - 4 * lt, wd - 4 * lt, alfa_st + 4 * alfa_w / 5, alfa_w / 5); // desenez cerc origine g.FillEllipse(pens_a, (wd - lt) / 2, (wd - lt) / 2, lt, lt); g.DrawEllipse(creion_r, (wd - lt) / 2, (wd - lt) / 2, lt, lt); g.DrawArc(creion_r, (wd - lt / 2) / 2, (wd - lt / 2) / 2, lt / 2, lt / 2, 0, 360); // desenez gradatii si text alfa_r = 0; alfa_gr = alfa_st; // unghiul start in grade while (alfa_gr <= alfa_st + alfa_w) { alfa_r = Math.PI * (360 - alfa_gr) / 180;// unghiul in radiani x1 = xc + Convert.ToInt32((wd / 2 - lt * 3 / 2) * Math.Cos(alfa_r)); y1 = yc - Convert.ToInt32((wd / 2 - lt * 3 / 2) * Math.Sin(alfa_r)); x2 = xc + Convert.ToInt32((wd / 2 - 3 * lt) * Math.Cos(alfa_r)); y2 = yc - Convert.ToInt32((wd / 2 - 3 * lt) * Math.Sin(alfa_r)); xt = xc - 10 + Convert.ToInt32((wd / 2 - lt) * Math.Cos(alfa_r)); yt = yc - 10 - Convert.ToInt32((wd / 2 - lt) * Math.Sin(alfa_r)); if (sd == 0) { if (wd > 100) g.DrawString(System.Math.Round(val_a, 2).ToString(), font_arial, pens_a, xt, yt); //val_a = val_a + (vmax - vmin) / ((alfa_w / (2 * gd))); sd = 1; if (alfa_gr > (alfa_st + 4 * alfa_w / 5)) g.DrawLine(creion_g2, x1, y1, x2, y2); else g.DrawLine(creion_g2, x1, y1, x2, y2); } else { if (alfa_gr > (alfa_st + 4 * alfa_w / 5)) g.DrawLine(creion_g, x1, y1, x2, y2); else g.DrawLine(creion_g, x1, y1, x2, y2); sd = 0; } alfa_gr += gd; nrd++; val_a = vmin + nrd * (vmax - vmin) / Convert.ToDouble(alfa_w / gd); } // desenez ac indicator // scalare val_gr = alfa_st + Convert.ToInt32(alfa_w * (val_c - vmin) / (vmax - vmin)); alfa_r = Math.PI * (360 - val_gr) / 180; // unghiul in radiani int x = xc + Convert.ToInt32((wd / 2 - lt) * Math.Cos(alfa_r)); int y = yc - Convert.ToInt32((wd / 2 - lt) * Math.Sin(alfa_r)); g.DrawLine(creion_r, xc, yc, x, y); // valoare si um if (wd > 100) g.DrawString(Math.Round(val, 2).ToString(), font_arial2, pens_r, wd / 2 - lt * 3 / 4, wd / 2 + lt); else g.DrawString(Math.Round(val, 2).ToString(), font_arial, pens_r, wd / 2 - lt * 3 / 4, wd / 2 + lt * 2 / 3); if (wd > 100) g.DrawString(um, font_arial, pens_a, Convert.ToInt32(wd / 2 - lt * 2 / 3), Convert.ToInt32(4 * lt)); else g.DrawString(um, font_arial, pens_a, Convert.ToInt32(wd / 2 - lt), Convert.ToInt32(4 * lt)); // desenez cerc exterior // g.DrawArc(creion_g, 0, 0, wd , wd , alfa_st, alfa_w); g.DrawArc(creion_g, 0, 0, wd, wd, 0, 360); // plasez imaginea finala zona_des.DrawImage(img, x0, y0); } } // --------------Sfarsit clasa barometru ----------------- } |
namespace Oop_instr_90 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public System.Drawing.Graphics desen; public turom turom1, turom2; public System.Random n; private void Form1_Load(object sender, EventArgs e) { desen = this.CreateGraphics(); n = new System.Random(); turom1 = new turom(desen, 40, 10, 100, 140, 200, 10, 0, 200, "Km/h"); turom2 = new turom(desen, 180, 10, 250, 120, 300, 10, 100, 6100, "rpm"); } private void timer1_Tick(object sender, EventArgs e) { turom1.setval(n.Next(0, 200)); //turom2.setval(123); turom2.setval(n.Next(100, 6100)); //turom2.setval(2330); } } // --------------Clasa turometru ------------------ public class turom { System.Drawing.Graphics zona_des; System.Drawing.Bitmap img; Graphics g; System.Drawing.Pen creion_g = new System.Drawing.Pen(System.Drawing.Color.LightGreen); System.Drawing.Pen creion_g2 = new System.Drawing.Pen(System.Drawing.Color.LightGreen, 3); System.Drawing.Pen creion_r = new System.Drawing.Pen(System.Drawing.Color.Red); System.Drawing.Pen creion_r2 = new System.Drawing.Pen(System.Drawing.Color.Red, 2); System.Drawing.Font font_arial = new System.Drawing.Font("Arial", 10, FontStyle.Bold); System.Drawing.Font font_arial2 = new System.Drawing.Font("Arial", 16, FontStyle.Bold); System.Drawing.SolidBrush pens_a = new System.Drawing.SolidBrush(System.Drawing.Color.Yellow); System.Drawing.SolidBrush pens_r = new System.Drawing.SolidBrush(System.Drawing.Color.Red); System.Drawing.SolidBrush pens_rad = new System.Drawing.SolidBrush(System.Drawing.Color.Black); int x0; // pozitia pe x a instrumentului int y0; // pozitia pe y a instrumentului int wd; // latimea int alfa_st; // unghiul de inceput in grade int alfa_w; // marimea unghiului in grade double vmin; // valoarea minima double vmax; // valoarea maxima int gd; // grade pe diviziune string um; // unitatea de masura public turom(System.Drawing.Graphics desen, int x, int y, int wi, int gr_st, int gr_w, int gr_d, double vmn, double vmx, string u_m) { zona_des = desen; x0 = x; // pozitia pe x a instrumentului y0 = y; // pozitia pe y a instrumentului wd = wi; // latimea alfa_st = gr_st; // unghiul de inceput in grade alfa_w = gr_w; // unghiul de sfarfit in grade gd = gr_d; // grade pe diviziune vmin = vmn; // valoarea minima vmax = vmx; // valoarea maxima um = u_m; // unitatea de masura } public void setval(double val) { int x1, x2, xt, y1, y2, yt; int xc = wd / 2; int yc = wd / 2; int raza = (wd - wd / 3) / 2; int sd = 0; // semafor (diviziune cu text sau fara text) int nrd = 0; // nr diviziuni double val_c = val; // valoarea curenta de afisat int val_gr; // valoarea de afisat in grade double val_a = vmin; // valori afisate de pe cadran double alfa_r = 0; // unghi in radiani int alfa_gr = 0; // unghi in grade int lt = wd / 12; // valoare distantier img = new Bitmap(wd + 2, wd + 2, zona_des); g = Graphics.FromImage(img); // sterg continutul imaginii //g.FillEllipse(pens_rad, 0, 0, wd+2, wd+2); g.FillRectangle(pens_rad, 0, 0, wd + 2, wd + 2); // desenez gradatii si text alfa_r = 0; alfa_gr = alfa_st; // unghiul start in grade while (alfa_gr <= alfa_st + alfa_w) { alfa_r = 2 * Math.PI * (360 - alfa_gr) / 360;// unghiul in radiani x1 = Convert.ToInt32(xc + (wd / 2) * Math.Cos(alfa_r)); y1 = Convert.ToInt32(yc - (wd / 2) * Math.Sin(alfa_r)); x2 = xc + Convert.ToInt32((wd / 2 - lt) * Math.Cos(alfa_r)); y2 = yc - Convert.ToInt32((wd / 2 - lt) * Math.Sin(alfa_r)); xt = xc - lt / 2 + Convert.ToInt32((raza) * Math.Cos(alfa_r)); yt = yc - 10 - Convert.ToInt32((raza) * Math.Sin(alfa_r)); if (sd == 0) { if (wd > 100) g.DrawString(Math.Round(val_a, 2).ToString(), font_arial, pens_a, xt, yt); sd = 1; if (alfa_gr > (alfa_st + 4 * alfa_w / 5)) g.DrawLine(creion_r2, x1, y1, x2, y2); else g.DrawLine(creion_g2, x1, y1, x2, y2); } else { if (alfa_gr > (alfa_st + 4 * alfa_w / 5)) g.DrawLine(creion_r, x1, y1, x2, y2); else g.DrawLine(creion_g, x1, y1, x2, y2); sd = 0; } alfa_gr += gd; nrd++; val_a = vmin + nrd * (vmax - vmin) / Convert.ToDouble(alfa_w / gd); } // desenez ac indicator // scalare val_gr = Convert.ToInt32(alfa_st + alfa_w * (val_c - vmin) / (vmax - vmin)); alfa_r = 2 * Math.PI * (360 - val_gr) / 360;// unghiul in radiani int x = xc + Convert.ToInt32((wd / 2) * Math.Cos(alfa_r)); int y = yc - Convert.ToInt32((wd / 2) * Math.Sin(alfa_r)); g.DrawLine(creion_r, xc, yc, x, y); // valoare si um if (wd > 100) g.DrawString(Math.Round(val, 2).ToString(), font_arial2, pens_r, wd / 2 - lt * 3 / 4, wd / 2 + lt * 2 / 3); else g.DrawString(Math.Round(val, 2).ToString(), font_arial, pens_r, wd / 2 - lt * 3 / 4, wd / 2 + lt * 2 / 3); if (wd > 100) g.DrawString(um, font_arial2, pens_a, Convert.ToInt32(wd / 2 - lt), Convert.ToInt32(4 * lt)); else g.DrawString(um, font_arial, pens_a, Convert.ToInt32(wd / 2 - lt), Convert.ToInt32(4 * lt)); //desenez cerc exterior //g.DrawArc(creion_g, 0, 0, wd, wd, alfa_st, alfa_w); //g.DrawArc(creion_r, 0, 0, wd, wd, alfa_st + 4 * alfa_w / 5, alfa_w / 5); // desenez cerc origine g.DrawArc(creion_r, (wd - lt / 2) / 2, (wd - lt / 2) / 2, lt / 2, lt / 2, 0, 360); // plasez imaginea finala zona_des.DrawImage(img, x0, y0); } } // --------------Sfarsit clasa turometru ---------------- } |
namespace Oop_instr_11 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public System.Drawing.Graphics desen; public afis_xt instr; int nr_p = 400;// numarul de puncte afisate int val_max = 200; double[] valori; private void Form1_Paint(object sender, PaintEventArgs e) { desen = this.CreateGraphics(); instr = new afis_xt(desen, 10, 10, nr_p, val_max, val_max); valori = new double[nr_p]; double alfa = 0; for (int i = 0; i < nr_p; i++) { valori[i] = System.Convert.ToUInt16(val_max / 6 + ((val_max / 3) * (1 - Math.Sin(alfa)))); alfa += 0.07; } instr.sterg(Color.White); instr.setval(Color.Blue, valori, nr_p); } } public class afis_xt { public System.Drawing.Graphics zona_des; public System.Drawing.Pen c_contur = new System.Drawing.Pen(System.Drawing.Color.Tomato, 2); int x0; int y0; int w; int h; double val_max; public void sterg(Color culoare_fundal) { zona_des.FillRectangle(new SolidBrush(culoare_fundal), x0 + 2, y0 + 2, w - 2, h - 2); } public void setval(Color culoare_grafic, double[] vals, int nrv) { int val_v, val; val_v = 0; for (int i = 0; i < nrv; i++) { val = System.Convert.ToInt16(System.Convert.ToDouble(vals[i]) * (System.Convert.ToDouble(h) / System.Convert.ToDouble(val_max))); //scalare zona_des.DrawLine(new Pen(culoare_grafic), x0 + i, y0 + val_v, x0 + i+1, y0 + val); val_v = val; } zona_des.DrawRectangle(c_contur, x0 + 1, y0 + 1, w, h); } public afis_xt(System.Drawing.Graphics desen, int pozx, int pozy, int nr_valori, int inaltime, double vmax) { zona_des = desen; x0 = pozx; y0 = pozy; w = nr_valori; h = inaltime; val_max = vmax; } } } |
namespace Oop_instr_12 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public System.Drawing.Graphics desen; public osciloscop_00 os1; int pozx = 30, pozy = 40, n_maxx = 273, n_maxy = 205; double alfa = 0; double[] valori; private void Form1_Load(object sender, EventArgs e) { desen = this.CreateGraphics(); valori = new double[n_maxx]; os1 = new osciloscop_00(desen, pozx, pozy, n_maxx, n_maxy, n_maxy); } private void Form1_Paint(object sender, PaintEventArgs e) { this.trackBar1.Maximum = n_maxy / 5; this.trackBar1.Minimum = -n_maxy / 5; this.trackBar1.Value = 0; this.trackBar2.Maximum = n_maxy; this.trackBar2.Value = n_maxy / 3; this.trackBar3.Minimum = 1; this.trackBar3.Value = 14; } private void timer1_Tick(object sender, EventArgs e) { if(this.checkBox1.Checked) os1.sterg_g(Color.White); else os1.sterg(Color.White); alfa = 0; int transl = -this.trackBar1.Value; int amplif = this.trackBar2.Value; int zero = n_maxy / 2; for (int i = 0; i < n_maxx; i++) { alfa += System.Convert.ToDouble(this.trackBar3.Value) / 100; int f = System.Convert.ToInt32(transl + zero - amplif * Math.Sin(alfa)); if ((f < n_maxy) && (f >= 0)) valori[i] = f; if (f > n_maxy) valori[i] = n_maxy - 1; if (f < 0) valori[i] = 0; } os1.setval(Color.Blue, valori, n_maxx); } } // Clasa afis_xt public class osciloscop_00 { public System.Drawing.Graphics zona_des; public System.Drawing.Pen c_contur = new System.Drawing.Pen(System.Drawing.Color.Tomato, 2); int x0; int y0; int w; int h; double val_max; public void sterg(Color culoare_fundal) { zona_des.DrawRectangle(c_contur, x0 + 1, y0 + 1, w, h); zona_des.FillRectangle(new SolidBrush(culoare_fundal), x0 + 2, y0 + 2, w - 2, h - 2); } public void sterg_g(Color culoare_fundal) { int i = 0, j = 0; for (i = 1; i < w; i++) { //grid vertical zona_des.DrawLine(new Pen(culoare_fundal), x0 + i + 1, y0 + 2, x0 + i + 1, y0 + h - 1); if ((i + 1) % 10 == 0) { zona_des.DrawLine(new Pen(Color.LightGray), i + x0, y0, i + x0, y0 + h); if ((i + 1) % 50 == 0) zona_des.DrawLine(new Pen(Color.Gray), i + x0, y0, i + x0, y0 + h); } else // grid orizontal j = y0 + 10; while (j <= h) { if (j % 50 == 0) zona_des.DrawLine(new Pen(Color.Gray), i + x0, j, i + x0 + 1, j); else zona_des.DrawLine(new Pen(Color.LightGray), i + x0, j, i + x0 + 1, j); j += 10; } } } public void setval(Color culoare_grafic, double[] vals, int nrv) { int val_v, val; val_v = 0; for (int i = 0; i < nrv; i++) { val = System.Convert.ToInt16(System.Convert.ToDouble(vals[i]) * (System.Convert.ToDouble(h) / System.Convert.ToDouble(val_max))); //scalare zona_des.DrawLine(new Pen(culoare_grafic), x0 + i, y0 + val_v, x0 + i+1, y0 + val); val_v = val; } zona_des.DrawRectangle(c_contur, x0 + 1, y0 + 1, w, h); } public osciloscop_00(System.Drawing.Graphics desen, int pozx, int pozy, int nr_valori, int inaltime, double vmax) { zona_des = desen; x0 = pozx; y0 = pozy; w = nr_valori; h = inaltime; val_max = vmax; } } // Gata clasa afis_xt } |
namespace Oop_instr_13 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public System.Drawing.Graphics desen; public osciloscop_01 os1; int pozx = 20, pozy = 35, n_maxx = 320, n_maxy = 220; double alfa = 0; double[] valori; private void Form1_Load(object sender, EventArgs e) { desen = this.CreateGraphics(); valori = new double[n_maxx]; os1 = new osciloscop_01(desen, pozx, pozy, n_maxx, n_maxy, n_maxy,0,Color.Black,Color.DarkBlue,Color.DarkGreen,Color.Yellow); } private void Form1_Paint(object sender, PaintEventArgs e) { this.trackBar1.Maximum = n_maxy / 5; this.trackBar1.Minimum = -n_maxy / 5; this.trackBar1.Value = 0; this.trackBar2.Maximum = n_maxy; this.trackBar2.Value = n_maxy / 3; this.trackBar3.Minimum = 1; this.trackBar3.Value = 14; } private void timer1_Tick(object sender, EventArgs e) { os1.sterg(); alfa = 0; int transl = this.trackBar1.Value; int amplif = this.trackBar2.Value; int zero = n_maxy / 2; for (int i = 0; i < n_maxx; i++) { alfa += System.Convert.ToDouble(this.trackBar3.Value) / 100; int f = System.Convert.ToInt32(transl + zero - amplif * Math.Sin(alfa)); if ((f < n_maxy) && (f >= 0)) valori[i] = f; if (f > n_maxy) valori[i] = n_maxy - 1; if (f < 0) valori[i] = 0; } os1.setval(valori, n_maxx, Color.Lime); os1.display(); } } public class osciloscop_01 { 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 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; Graphics g = Graphics.FromImage(img); // afisare grafic cu metoda DrawLine for (i = 1; i < w - 1; i++) { val = System.Convert.ToInt16(h + transl - amplif * System.Convert.ToDouble(vals[i])); //scalare val = System.Convert.ToInt16(h + transl - amplif * System.Convert.ToDouble(vals[i])); //scalare if (val >= h) val = h - 1; if (val <= 0) val = 1; g.DrawLine(new Pen(culoare), i, val_v, i + 1, val); val_v = val; } //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_01(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; Graphics s = Graphics.FromImage(ims); s.Clear(culoare_fundal); for (i = 1; i < n_maxx; i++) { //grid vertical if ((i + 1) % 10 == 0) { s.DrawLine(new Pen(culoare_grid), i, 0, i, 0 + h); if ((i + 1) % 50 == 0) s.DrawLine(new Pen(culoare_grid_m), i + x0, y0, i + x0, y0 + h); } else // grid orizontal j = 10; while (j <= h) { if (j % 50 == 0) s.DrawLine(new Pen(culoare_grid), i, j, i + 1, j); else s.DrawLine(new Pen(culoare_grid_m), i, j, i + 1, j); j += 10; } } sterg(); } } } } |
namespace Oop_instr_14 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public System.Drawing.Graphics desen; public osciloscop_02 os1; int pozx = 20, pozy = 35, n_maxx = 320, n_maxy = 220; double alfa = 0; double[] valori; private void Form1_Load(object sender, EventArgs e) { desen = this.CreateGraphics(); valori = new double[n_maxx]; os1 = new osciloscop_02(desen, pozx, pozy, n_maxx, n_maxy, n_maxy, 0, Color.Black, Color.DarkBlue, Color.DarkGreen, Color.Yellow); } private void Form1_Paint(object sender, PaintEventArgs e) { this.trackBar1.Maximum = n_maxy / 5; this.trackBar1.Minimum = -n_maxy / 5; this.trackBar1.Value = 0; this.trackBar2.Maximum = n_maxy; this.trackBar2.Value = n_maxy / 3; this.trackBar3.Minimum = 1; this.trackBar3.Value = 14; } private void timer1_Tick(object sender, EventArgs e) { os1.sterg(); alfa = 0; int transl = this.trackBar1.Value; int amplif = this.trackBar2.Value; int zero = n_maxy / 2; for (int i = 0; i < n_maxx; i++) { alfa += System.Convert.ToDouble(this.trackBar3.Value) / 100; int f = System.Convert.ToInt32(transl + zero - amplif * Math.Sin(alfa)); if ((f < n_maxy) && (f >= 0)) valori[i] = f; if (f > n_maxy) valori[i] = n_maxy - 1; if (f < 0) valori[i] = 0; } os1.setval(valori, n_maxx, Color.Lime); os1.display(); } } public class osciloscop_02 { 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 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 puncte for (i = 0; i < w; i++) { val = System.Convert.ToInt16(h + transl - amplif * System.Convert.ToDouble(vals[i])); //scalare val = System.Convert.ToInt16(h + transl - amplif * System.Convert.ToDouble(vals[i])); //scalare if (val >= h) val = h - 1; if (val <= 0) val = 1; img.SetPixel(i, val, culoare); } 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_02(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); } sterg(); } } } |
namespace Oop_instr_15 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public System.Drawing.Graphics desen; public osciloscop_03 os1; int pozx = 20, pozy = 35, n_maxx = 320, n_maxy = 220; double alfa = 0; double[] valori; private void Form1_Load(object sender, EventArgs e) { desen = this.CreateGraphics(); valori = new double[n_maxx]; os1 = new osciloscop_03(desen, pozx, pozy, n_maxx, n_maxy, n_maxy, 0, Color.Black, Color.DarkBlue, Color.Black, Color.Yellow); } private void Form1_Paint(object sender, PaintEventArgs e) { this.trackBar1.Maximum = n_maxy / 5; this.trackBar1.Minimum = -n_maxy / 5; this.trackBar1.Value = 0; this.trackBar2.Maximum = n_maxy; this.trackBar2.Value = n_maxy / 3; this.trackBar3.Minimum = 1; this.trackBar3.Value = 14; } private void timer1_Tick(object sender, EventArgs e) { os1.sterg(); alfa = 0; int transl = this.trackBar1.Value; int amplif = this.trackBar2.Value; int zero = n_maxy / 2; for (int i = 0; i < n_maxx; i++) { alfa += System.Convert.ToDouble(this.trackBar3.Value) / 100; int f = System.Convert.ToInt32(transl + zero - amplif * Math.Sin(alfa)); if ((f < n_maxy) && (f >= 0)) valori[i] = f; if (f > n_maxy) valori[i] = n_maxy - 1; if (f < 0) valori[i] = 0; } os1.setval(valori, n_maxx, Color.LightBlue); os1.display(); } } public class osciloscop_03 { 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 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_03(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(); } } } } |
namespace Oop_instr_16 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public System.Drawing.Graphics desen; public osciloscop oscil; int pozx = 70, pozy = 10, n_maxx = 400, n_maxy = 200; double val_max = 1.5, val_min = -1.5; double[] valori; private void Form1_Load(object sender, EventArgs e) { desen = this.CreateGraphics(); valori = new double[n_maxx]; //Array.Resize(ref valori, n_maxx + 1); oscil = new osciloscop(desen, pozx, pozy, n_maxx, n_maxy, val_max, val_min, Color.Black,Color.DarkBlue,Color.DarkGreen,Color.Yellow); } private void timer1_Tick(object sender, EventArgs e) { double a = this.trackBar2.Value / 100.0; double f = this.trackBar1.Value / 100.0; double alfa = 0, min, max; double pas = 0.03; for (int i = 0; i < n_maxx; i++) { alfa += pas; valori[i] = a * Math.Sin(f * alfa); } min = valori[0]; max = valori[0]; for (int i = 0; i < n_maxx; i++) { if (valori[i] > max) max = valori[i]; if (valori[i] < min) min = valori[i]; } if (this.checkBox1.Checked) oscil.auto_sy(max, min); else oscil.auto_sy(val_max, val_min); if (this.checkBox2.Checked) oscil.auto_sx(f * pas * n_maxx, 0); else oscil.auto_sx(n_maxx, 0); oscil.sterg(); oscil.setval(valori, n_maxx, Color.Lime); oscil.display(); } } 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(); } } } } |
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; } } |
namespace Oop_instr_50 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public System.Drawing.Graphics desen; public osciloscop oscil_m; int pozx = 40, pozy = 10, n_maxx = 500, n_maxy = 200; double val_max = 2, val_min=-2; static double[] valori1 = new double[0]; static double[] valori2 = new double[0]; private void Form1_Load(object sender, EventArgs e) { desen = this.CreateGraphics(); Array.Resize(ref valori1, n_maxx + 1); Array.Resize(ref valori2, n_maxx + 1); oscil_m = new osciloscop(desen, pozx, pozy, n_maxx, n_maxy, val_max, val_min, Color.WhiteSmoke, Color.Gray, Color.LightGray, Color.Blue); } private void timer1_Tick(object sender, EventArgs e) { double a = this.trackBar1.Value / 100.0; double k = this.trackBar2.Value/100.0; double alfa = 0; double pas = 0.05; for (int i = 1; i <= n_maxx; i++) { alfa += pas; valori1[i] = a*Math.Sin(alfa); valori2[i] = Math.Sin(k*alfa); } oscil_m.sterg(); if (this.checkBox1.Checked) oscil_m.auto_sx(pas*k*n_maxx, 0); else oscil_m.auto_sx(n_maxx, 0); oscil_m.setval(valori1, n_maxx, Color.Red); oscil_m.setval(valori2, n_maxx, Color.Green); oscil_m.display(); } } // --------------Clasa osciloscop ------------------ 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(); } } } // --------------Sfarsit clasa osciloscop ------------------ } |
namespace Oop_instr_50_mat { public partial class Form1 : Form { public Form1() { InitializeComponent(); } System.Drawing.Graphics desen; osciloscop oscil_m; int pozx = 10, pozy = 10, n_maxx = 400, n_maxy = 300; double val_max = 5; //valoarea maxima double val_min = -5; //valoarea minima double x0 = -6, x1 = 6; double[] valori = new double[0]; double[] valoris = new double[0]; private void Form1_Load(object sender, EventArgs e) { Array.Resize(ref valori, n_maxx + 1); Array.Resize(ref valoris, n_maxx + 1); desen = this.CreateGraphics(); oscil_m = new osciloscop(desen, pozx, pozy, n_maxx, n_maxy, val_max, val_min, Color.WhiteSmoke, Color.Gray, Color.LightGray, Color.Blue); } private void Form1_Paint(object sender, PaintEventArgs e) { double pas = (x1 - x0) / n_maxx; double x = x0; for (int i = 0; i < n_maxx; i++) { x = x + pas; // evitarea calcularii tan(0); if ((x > -pas) && (x < pas)) x = pas; valori[i] = Math.Tan(x) * Math.Sin(x); valoris[i] = Math.Sin(x); } oscil_m.sterg(); oscil_m.auto_sx(x1, x0); oscil_m.setval(valori, n_maxx, Color.Red); oscil_m.setval(valoris, n_maxx, Color.Blue); oscil_m.display(); } } public class osciloscop... } |
namespace Oop_instr_19_ex { public partial class Form1 : Form { public Form1() { InitializeComponent(); } System.Drawing.Graphics desen; osciloscop instrum1; int pozx = 40, pozy = 80, n_maxx = 270, n_maxy = 200; double val_min = -100; double val_max = 100; double x0 = 0; double x1 = 1; double alfa = 0; double fi = 0; double[] valori = new double[0]; private void Form1_Load(object sender, EventArgs e) { Array.Resize(ref valori, n_maxx + 1); desen = this.CreateGraphics(); instrum1 = new osciloscop(desen, pozx, pozy, n_maxx, n_maxy, val_max, val_min, Color.WhiteSmoke, Color.Gray, Color.LightGray, Color.Blue); } private void Form1_Paint(object sender, PaintEventArgs e) { this.trackBar1.Maximum = System.Convert.ToInt16(val_max); this.trackBar1.Minimum = System.Convert.ToInt16(val_min); this.trackBar1.Value = 0; this.trackBar2.Maximum = n_maxy; this.trackBar2.Value = n_maxy / 3; this.trackBar3.Minimum = 1; this.trackBar3.Value = 15; instrum1.display(); } private void timer1_Tick(object sender, EventArgs e) { fi = fi + 0.1; alfa = fi; int transl = this.trackBar1.Value; int amplif = this.trackBar2.Value; double pas = (x1 - x0) / n_maxx; double x = x0; for (int i = 1; i <= n_maxx; i++) { x = x + pas; if (x > 1) x = 0; int k = System.Convert.ToInt32(this.trackBar3.Value); valori[i] = transl + amplif * (Math.Sin(k * x + fi) * (1 - Math.Pow(Math.E, x))); } instrum1.sterg(); instrum1.auto_sx(x1, x0); instrum1.setval(valori, n_maxx, Color.Magenta); instrum1.display(); } } public class osciloscop... } |
namespace Oop_instr_19_ekg { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public System.Drawing.Graphics desen; public osciloscop ekg; int pozx = 40, pozy = 10, n_maxx = 300, n_maxy = 200; double val_max = 500, val_min=0 ; static double[] valori = new double[0]; private void Form1_Load(object sender, EventArgs e) { desen = this.CreateGraphics(); Array.Resize(ref valori, n_maxx + 1); ekg = new osciloscop(desen, pozx, pozy, n_maxx, n_maxy, val_max, val_min, Color.WhiteSmoke, Color.Gray, Color.LightGray, Color.Blue); } private void timer1_Tick(object sender, EventArgs e) { double f = System.Convert.ToDouble(this.trackBar1.Value); for (int i = 0; i < n_maxx - 1; i++) { valori[i] = valori[i + 1]; } valori[n_maxx - 1] = f; ekg.setval(valori, n_maxx, Color.Red); } } public class osciloscop... } |
namespace Oop_instr_19_ekg_s { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public System.Drawing.Graphics desen; public osciloscop ekg; int pozx = 100, pozy = 10, n_maxx = 500, n_maxy = 200; double val_max = 4, val_min = 0; static double[] valori = new double[0]; double a_pwav = 0.25, d_pwav = 0.09, t_pwav = 0.16; double a_qwav = 0.025, d_qwav = 0.066, t_qwav = 0.166; double li = 0.5, a_qrswav = 1.6, d_qrswav = 0.09; double a_swav = 0.25, d_swav = 0.066, t_swav = 0.09; double a_twav = 0.35, d_twav = 0.142, t_twav = 0.2; double a_uwav = 0.035, d_uwav = 0.0476, t_uwav = 0.433; double p_wav(double x, double a_pwav, double d_pwav, double t_pwav, double li) { double l, a, b, p1, p2, harm1, pwav1, pwav; l = li; a = a_pwav; x = x + t_pwav; b = (2 * l) / d_pwav; int n = 100; p1 = 1 / l; p2 = 0; harm1 = 0.0; for (int i = 1; i < n; i++) { harm1 = (((Math.Sin((Math.PI / (2 * b)) * (b - (2 * i)))) / (b - (2 * i)) + (Math.Sin((Math.PI / (2 * b)) * (b + (2 * i)))) / (b + (2 * i))) * (2 / Math.PI)) * Math.Cos((i * Math.PI * x) / l); p2 = p2 + harm1; } pwav1 = p1 + p2; pwav = a * pwav1; return pwav; } double qrs_wav(double x, double a_qrswav, double d_qrswav, double li) { double l, a, b, harm, qrs1, qrs2, qrswav; l = li; a = a_qrswav; b = (2 * l) / d_qrswav; int n = 100; qrs1 = (a / (2 * b)) * (2 - b); qrs2 = 0; for (int i = 1; i < n; i++) { harm = (((2 * b * a) / (i * i * Math.PI * Math.PI)) * (1 - Math.Cos((i * Math.PI) / b))) * Math.Cos((i * Math.PI * x) / l); qrs2 = qrs2 + harm; } qrswav = qrs1 + qrs2; return qrswav; } double q_wav(double x, double a_qwav, double d_qwav, double t_qwav, double li) { double l, a, b, q1, q2, harm5, qwav; l = li; x = x + t_qwav; a = a_qwav; b = (2 * l) / d_qwav; int n = 100; q1 = (a / (2 * b)) * (2 - b); q2 = 0; for (int i = 1; i < n; i++) { harm5 = (((2 * b * a) / (i * i * Math.PI * Math.PI)) * (1 - Math.Cos((i * Math.PI) / b))) * Math.Cos((i * Math.PI * x) / l); q2 = q2 + harm5; } qwav = -1 * (q1 + q2); return qwav; } double s_wav(double x, double a_swav, double d_swav, double t_swav, double li) { double l, a, b, s1, s2, harm3, swav; l = li; x = x - t_swav; a = a_swav; b = (2 * l) / d_swav; int n = 100; s1 = (a / (2 * b)) * (2 - b); s2 = 0; for (int i = 1; i < n; i++) { harm3 = (((2 * b * a) / (i * i * Math.PI * Math.PI)) * (1 - Math.Cos((i * Math.PI) / b))) * Math.Cos((i * Math.PI * x) / l); s2 = s2 + harm3; } swav = -1 * (s1 + s2); return swav; } double t_wav(double x, double a_twav, double d_twav, double t_twav, double li) { double l, a, b, t1, t2, harm2, twav1, twav; l = li; a = a_twav; x = x - t_twav - 0.045; b = (2 * l) / d_twav; int n = 100; t1 = 1 / l; t2 = 0; for (int i = 1; i < n; i++) { harm2 = (((Math.Sin((Math.PI / (2 * b)) * (b - (2 * i)))) / (b - (2 * i)) + (Math.Sin((Math.PI / (2 * b)) * (b + (2 * i)))) / (b + (2 * i))) * (2 / Math.PI)) * Math.Cos((i * Math.PI * x) / l); t2 = t2 + harm2; } twav1 = t1 + t2; twav = a * twav1; return twav; } double u_wav(double x, double a_uwav, double d_uwav, double t_uwav, double li) { double l, a, b, u1, u2, harm4, uwav1, uwav; l = li; a = a_uwav; x = x - t_uwav; b = (2 * l) / d_uwav; int n = 100; u1 = 1 / l; u2 = 0; for (int i = 1; i < n; i++) { harm4 = (((Math.Sin((Math.PI / (2 * b)) * (b - (2 * i)))) / (b - (2 * i)) + (Math.Sin((Math.PI / (2 * b)) * (b + (2 * i)))) / (b + (2 * i))) * (2 / Math.PI)) * Math.Cos((i * Math.PI * x) / l); u2 = u2 + harm4; } uwav1 = u1 + u2; uwav = a * uwav1; return uwav; } private void Form1_Load(object sender, EventArgs e) { desen = this.CreateGraphics(); Array.Resize(ref valori, n_maxx + 1); ekg = new osciloscop(desen, pozx, pozy, n_maxx, n_maxy, val_max, val_min, Color.WhiteSmoke, Color.Gray, Color.LightGray, Color.Blue); } private void timer1_Tick(object sender, EventArgs e) { int p; a_qrswav = System.Convert.ToDouble(this.trackBar2.Value) / 10.0; double val_m = System.Convert.ToDouble(this.trackBar1.Value); li = 30.0 / val_m; this.label1.Text = Math.Round(val_m).ToString(); double pas = 0.004; double x = pas; double pwav, qwav, qrswav, swav, twav, uwav, ecg; for (p = 0; p < n_maxx; p++) { pwav = p_wav(x, a_pwav, d_pwav, t_pwav, li); qwav = q_wav(x, a_qwav, d_qwav, t_qwav, li); qrswav = qrs_wav(x, a_qrswav, d_qrswav, li); swav = s_wav(x, a_swav, d_swav, t_swav, li); twav = t_wav(x, a_twav, d_twav, t_twav, li); uwav = u_wav(x, a_uwav, d_uwav, t_uwav, li); ecg = pwav + qrswav + twav + swav + qwav + uwav; valori[p] = ecg; x = x + pas; } double min = valori[0]; for (p = 0; p < n_maxx; p++) { if (valori[p] < min) min = valori[p]; } for (p = 0; p < n_maxx; p++) { valori[p] = valori[p] - min + 0.5; // 0.5 translatie pe y } ekg.sterg(); if (this.checkBox1.Checked) ekg.auto_sx(pas * n_maxx, 0); else ekg.auto_sx(n_maxx, 0); ekg.setval(valori, n_maxx, Color.Red); ekg.display(); } } public class osciloscop... } |
namespace Oop_instr_50_rst { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public System.Drawing.Graphics desen; public osciloscop oscil_m; int pozx = 40, pozy = 10, n_maxx = 400, n_maxy = 200; double val_max = 1.2, val_min = -1.2; static double[] valori1 = new double[0]; static double[] valori2 = new double[0]; static double[] valori3 = new double[0]; private void Form1_Load(object sender, EventArgs e) { desen = this.CreateGraphics(); Array.Resize(ref valori1, n_maxx + 1); Array.Resize(ref valori2, n_maxx + 1); Array.Resize(ref valori3, n_maxx + 1); oscil_m = new osciloscop(desen, pozx, pozy, n_maxx, n_maxy, val_max, val_min, Color.WhiteSmoke, Color.Gray, Color.LightGray, Color.Blue); } private void timer1_Tick(object sender, EventArgs e) { double fi1 = this.trackBar1.Value / 100.0; double fi2 = this.trackBar2.Value / 100.0; double alfa = 0; double pas = 0.05; for (int i = 1; i <= n_maxx; i++) { alfa += pas; valori1[i] = Math.Sin(alfa); valori2[i] = Math.Sin(alfa - fi1); valori3[i] = Math.Sin(alfa - fi2); } oscil_m.sterg(); oscil_m.auto_sx(pas * n_maxx, 0); oscil_m.setval(valori1, n_maxx, Color.Red); oscil_m.setval(valori2, n_maxx, Color.Green); oscil_m.setval(valori3, n_maxx, Color.Magenta); oscil_m.display(); } } public class osciloscop... } |
namespace Oop_instr_50_pi { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public System.Drawing.Graphics desen; //public System.Drawing.Pen creion_rosu; public osciloscop oscil_m; int pozx = 180, pozy = 10, n_maxx = 400, n_maxy = 300; double r, er, ir, e_v, u, u_v, y, y_v, kp, ikp, Ti, iTi, Te; double val_max = 800; //valoarea maxima double val_min = -100; //valoarea minima static double[] valori_0 = new double[0]; static double[] valori_1 = new double[0]; private void Form1_Load(object sender, EventArgs e) { Array.Resize(ref valori_0, n_maxx + 1); Array.Resize(ref valori_1, n_maxx + 1); desen = this.CreateGraphics(); //creion_rosu = new System.Drawing.Pen(System.Drawing.Color.Red); oscil_m = new osciloscop(desen, pozx, pozy, n_maxx, n_maxy, val_max, val_min, Color.WhiteSmoke, Color.Gray, Color.LightGray, Color.Blue); kp = 1.1; Ti = 2.5; Te = 0.1; r = 175; u = 50; y = 0; } private void timer1_Tick(object sender, EventArgs e) { y = 0; u = 50; e_v = 0; y_v = 0; u_v = 0; ir = System.Convert.ToInt32(this.trackBar1.Value); ikp = System.Convert.ToDouble(this.trackBar2.Value); iTi = System.Convert.ToInt32(this.trackBar3.Value); r = System.Convert.ToDouble(ir); kp = System.Convert.ToDouble(ikp / 10); Ti = System.Convert.ToDouble(iTi / 10); this.label4.Text = r.ToString(); this.label5.Text = kp.ToString(); this.label6.Text = Ti.ToString(); for (int i = 1; i <= n_maxx; i++) { er = r - y; u = u_v + er * (kp + (Ti * (Te / 2))) + e_v * ((Ti * (Te / 2)) - kp); y = (u * Te + 5 * y_v) / (5 + Te); valori_0[i] = y; valori_1[i] = u; e_v = er; y_v = y; u_v = u; } oscil_m.sterg(); oscil_m.setval(valori_0, n_maxx, Color.Red); oscil_m.setval(valori_1, n_maxx, Color.Green); oscil_m.display(); } } public class osciloscop... } |
namespace Oop_instr_b_00 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public System.Drawing.Graphics desen; System.Drawing.SolidBrush culoare1, culoare2, culoare3, culoare4; public bit bit1, bit2, bit3, bit4, bit5, bit6; bool val_b = false; private void Form1_Load(object sender, EventArgs e) { desen = this.CreateGraphics(); culoare1 = new System.Drawing.SolidBrush(System.Drawing.Color.LightGreen); culoare2 = new System.Drawing.SolidBrush(System.Drawing.Color.Orange); culoare3 = new System.Drawing.SolidBrush(System.Drawing.Color.LightCyan); culoare4 = new System.Drawing.SolidBrush(System.Drawing.Color.Magenta); bit1 = new bit(desen, 120, 56, 16, 1, culoare1); bit2 = new bit(desen, 170, 56, 16, 2, culoare2); bit3 = new bit(desen, 220, 50, 26, 3, culoare3); bit4 = new bit(desen, 270, 50, 26, 4, culoare4); bit5 = new bit(desen, 320, 50, 26, 5, culoare2); bit6 = new bit(desen, 370, 50, 26, 6, culoare1); } private void timer1_Tick(object sender, EventArgs e) { val_b = !val_b; bit1.setval(val_b); bit2.setval(!val_b); bit3.setval(val_b); bit4.setval(!val_b); bit5.setval(val_b); bit6.setval(!val_b); } } // --------------Clasa bit ------------------ public class bit { System.Drawing.Graphics zona_des; System.Drawing.SolidBrush pens_bit; System.Drawing.Bitmap img; Graphics g; System.Drawing.Pen creion_contur = new System.Drawing.Pen(System.Drawing.Color.Blue); System.Drawing.SolidBrush pens_stins = new System.Drawing.SolidBrush(System.Drawing.Color.Gray); System.Drawing.SolidBrush pens_rad = new System.Drawing.SolidBrush(System.Drawing.Color.White); int x0; // pozitia pe x a bitului int y0; // pozitia pe y a bitului int wd; // latimea int tp; // tipul formei de afisat public bit(System.Drawing.Graphics desen, int x, int y, int wi, int tip, System.Drawing.SolidBrush culoare_bit) { zona_des = desen; pens_bit = culoare_bit; // culoarea cu care va fi desenta bitul x0 = x; // pozitia pe x a bitului y0 = y; // pozitia pe y a bitului wd = wi; // latimea tp = tip; // tipul formei de afisat // 1=cerc // 2=patrat // 3=sageata stanga // 4=sageata dreapta // 5=sageata jos // 6=sageata sus } public void setval(bool val) { img = new Bitmap(wd + 2, wd + 2, zona_des); g = Graphics.FromImage(img); // sterg continutul imaginii g.FillRectangle(pens_rad, 0, 0, wd + 2, wd + 2); // desenez bit // cerc if (tp == 1) { // umplere cerc if (val) g.FillEllipse(pens_bit, 0, 0, wd, wd); else g.FillEllipse(pens_stins, 0, 0, wd, wd); // trasare conturn g.DrawEllipse(creion_contur, 0, 0, wd, wd); } // patrat if (tp == 2) { // umplere patrat if (val) g.FillRectangle(pens_bit, 0, 0, wd, wd); else g.FillRectangle(pens_stins, 0, 0, wd, wd); // trasare conturn g.DrawRectangle(creion_contur, 0, 0, wd, wd); } // sageata stanga if (tp == 3) { Point p1 = new Point(wd / 2, 0); Point p2 = new Point(wd / 2, wd / 4); Point p3 = new Point(wd, wd / 4); Point p4 = new Point(wd, wd * 3 / 4); Point p5 = new Point(wd / 2, wd * 3 / 4); Point p6 = new Point(wd / 2, wd); Point p7 = new Point(0, wd / 2); Point[] puncte = { p1, p2, p3, p4, p5, p6, p7 }; // umplere poligon if (val) g.FillPolygon(pens_bit, puncte); else g.FillPolygon(pens_stins, puncte); // trasare conturn poligon g.DrawPolygon(creion_contur, puncte); } // sageata dreapta if (tp == 4) { Point p1 = new Point(0, wd / 4); Point p2 = new Point(wd / 2, wd / 4); Point p3 = new Point(wd / 2, 0); Point p4 = new Point(wd, wd / 2); Point p5 = new Point(wd / 2, wd); Point p6 = new Point(wd / 2, wd * 3 / 4); Point p7 = new Point(0, wd * 3 / 4); Point[] puncte = { p1, p2, p3, p4, p5, p6, p7 }; // umplere poligon if (val) g.FillPolygon(pens_bit, puncte); else g.FillPolygon(pens_stins, puncte); // trasare conturn poligon g.DrawPolygon(creion_contur, puncte); } // sageata jos if (tp == 5) { Point p1 = new Point(wd / 4, 0); Point p2 = new Point(wd * 3 / 4, 0); Point p3 = new Point(wd * 3 / 4, wd / 2); Point p4 = new Point(wd, wd / 2); Point p5 = new Point(wd / 2, wd); Point p6 = new Point(0, wd / 2); Point p7 = new Point(wd / 4, wd / 2); Point[] puncte = { p1, p2, p3, p4, p5, p6, p7 }; // umplere poligon if (val) g.FillPolygon(pens_bit, puncte); else g.FillPolygon(pens_stins, puncte); // trasare conturn poligon g.DrawPolygon(creion_contur, puncte); } // sageata sus if (tp == 6) { Point p1 = new Point(0, wd / 2); Point p2 = new Point(wd / 2, 0); Point p3 = new Point(wd, wd / 2); Point p4 = new Point(wd * 3 / 4, wd / 2); Point p5 = new Point(wd * 3 / 4, wd); Point p6 = new Point(wd / 4, wd); Point p7 = new Point(wd / 4, wd / 2); Point[] puncte = { p1, p2, p3, p4, p5, p6, p7 }; // umplere poligon if (val) g.FillPolygon(pens_bit, puncte); else g.FillPolygon(pens_stins, puncte); // trasare conturn poligon g.DrawPolygon(creion_contur, puncte); } // plasez imaginea finala zona_des.DrawImage(img, x0, y0); } } // --------------Sfarsit clasa bit ---------------- } |
namespace Oop_instr_b_10 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } System.Drawing.Graphics Desen; public binar binar1; public binar binar2; public binar binar3; System.Random nr; UInt64 num; string[] n_b = new string[] { "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7" }; private void Form1_Load(object sender, EventArgs e) { Desen = this.CreateGraphics(); nr = new System.Random(); binar1 = new binar(Desen,10, 10, 15, 16, 0, 0, 0); binar2 = new binar(Desen,510, 10, 15, 8, 1, 1, 0); binar3 = new binar(Desen,50, 100, 20, 8, 0, 1, 1); } private void Form1_Paint(object sender, PaintEventArgs e) { binar2.setname(n_b); binar3.setname(n_b); } private void timer1_Tick(object sender, EventArgs e) { binar1.setval(System.Convert.ToUInt64(nr.Next(65535))); binar2.setval(num); binar3.setval(System.Convert.ToUInt64(nr.Next(255))); num += 1; if (num > 256 * 256) num = 0; } } // --------------Clasa binar ------------------ public class binar { Graphics des; System.Drawing.Pen creion; System.Drawing.SolidBrush pens_verde; System.Drawing.SolidBrush pens_rosie; System.Drawing.SolidBrush pens_gri; System.Drawing.Font font_nina; int px0; // pozitia pe x int py0; // pozitia pe y int bit_w; // latimea unui bit int nrb; // numarul de biti int vh; // vertical(v_h=1)/orizontal(v_h=0) int dc; // dreptunghi(d_c=1)/cerc(d_c=0) int rv; // rosu r_v=1, verde r_v=0) int i; public void setval(UInt64 n) { if (rv == 1) pens_verde = pens_rosie; int x = 0, y = 0; x = px0 + bit_w; y = py0 + bit_w; if ((vh == 1) && (dc == 1)) y = py0 + bit_w + bit_w / 4; if (vh == 0) { for (i = nrb - 1; i >= 0; i--) { System.UInt64 bit = ((n >> (nrb - i - 1)) & 1); if (dc == 0) des.DrawEllipse(creion, x - 1, y - 1, bit_w + 2, bit_w + 2); else des.DrawRectangle(creion, x - 1, y - 1, bit_w + 2, bit_w / 2 + 2); if (bit==1) { if (dc == 0) des.FillEllipse(pens_verde, x, y, bit_w, bit_w); else des.FillRectangle(pens_verde, x, y, bit_w, bit_w / 2); } else { if (dc == 0) des.FillEllipse(pens_gri, x, y, bit_w, bit_w); else des.FillRectangle(pens_gri, x, y, bit_w, bit_w / 2); } x += 2 * bit_w; } } if (vh == 1) { for (i = 0; i < nrb; i++) { System.UInt64 bit = ((n >> (nrb - i - 1)) & 1); if (dc == 0) des.DrawEllipse(creion, x - 1, y - 1, bit_w + 2, bit_w + 2); else des.DrawRectangle(creion, x - 1, y - 1, bit_w + 2, bit_w / 2 + 2); if (bit == 1) { if (dc == 0) des.FillEllipse(pens_verde, x, y, bit_w, bit_w); else des.FillRectangle(pens_verde, x, y, bit_w, bit_w / 2); } else { if (dc == 0) des.FillEllipse(pens_gri, x, y, bit_w, bit_w); else des.FillRectangle(pens_gri, x, y, bit_w, bit_w / 2); } y += 2 * bit_w; } } } public void setname(string[] nume_biti) { int x = 0, y = 0; if (vh == 0) { x = px0 + bit_w; y = py0 + bit_w; for (i = nrb - 1; i >= 0; i--) { des.DrawString(nume_biti[i].ToString(), font_nina, pens_rosie, x, y - 2 * bit_w); x += 2 * bit_w; } } if (vh == 1) { x = px0 + 3 * bit_w; y = py0 + 3 * bit_w - bit_w / 4; ; for (i = 0; i < nrb; i++) { des.DrawString(nume_biti[i].ToString(), font_nina, pens_rosie, x, y - 2 * bit_w); y += 2 * bit_w; } } } public binar(Graphics desen, int pozx, int pozy, int w, int nr_biti, int v_h, int d_c,int r_v) { des = desen; creion = new System.Drawing.Pen(System.Drawing.Color.Gray, 2); pens_verde = new System.Drawing.SolidBrush(System.Drawing.Color.Lime); pens_rosie = new System.Drawing.SolidBrush(System.Drawing.Color.Red); pens_gri = new System.Drawing.SolidBrush(System.Drawing.Color.LightGray); font_nina = new System.Drawing.Font("Nina", 12); px0 = pozx; // pozitia pe x py0 = pozy; // pozitia pe y bit_w = w; // latimea unui bit nrb = nr_biti; // numarul de biti vh = v_h; // vertical(v_h=1)/orizontal(v_h=0) dc = d_c; // dreptunghi(d_c=1)/cerc(d_c=0) rv = r_v; // rosu r_v=1, verde r_v=0) } } // --------------Sfarsit clasa binar --------------- } |
namespace Oop_instr_b_15 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } System.Drawing.Graphics Desen; bin_bin b_b1, b_b2, b_b3, b_b4; const int nr_b = 8; string[] n_b = new string[] { "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7" }; bool[] v_bin = new bool[nr_b]; private void Form1_Load(object sender, EventArgs e) { Desen = this.CreateGraphics(); b_b1 = new bin_bin(Desen, 10, 50, 20, 8, 0, 0, 1); b_b2 = new bin_bin(Desen, 10, 150, 20, 8, 0, 1, 0); b_b3 = new bin_bin(Desen, 350, 10, 20, 8, 1, 0, 0); b_b4 = new bin_bin(Desen, 450, 10, 20, 8, 1, 1, 1); for (int i = 0; i < nr_b; i++) if (i % 2 == 0) v_bin[i] = true; else v_bin[i] = false; } private void Form1_Paint(object sender, PaintEventArgs e) { b_b1.setname(n_b); b_b2.setname(n_b); b_b3.setname(n_b); b_b4.setname(n_b); } private void timer1_Tick(object sender, EventArgs e) { b_b1.setval(v_bin); b_b2.setval(v_bin); b_b3.setval(v_bin); b_b4.setval(v_bin); } } // --------------Clasa bin_bin ------------------ public class bin_bin { Graphics des; System.Drawing.Pen creion; System.Drawing.SolidBrush pens_verde; System.Drawing.SolidBrush pens_rosie; System.Drawing.SolidBrush pens_gri; System.Drawing.Font font_nina; int px0; // pozitia pe x int py0; // pozitia pe y int bit_w; // latimea unui bit int nrb; // numarul de biti int vh; // vertical(v_h=1)/orizontal(v_h=0) int dc; // dreptunghi(d_c=1)/cerc(d_c=0) int rv; // rosu r_v=1, verde r_v=0) int i; public void setval(bool[] vector_binar) { if (rv == 1) pens_verde = pens_rosie; int x = 0, y = 0; x = px0 + bit_w; y = py0 + bit_w; if ((vh == 1) && (dc == 1)) y = py0 + bit_w + bit_w / 4; if (vh == 0) { for (i = nrb - 1; i >= 0; i--) { if (dc == 0) des.DrawEllipse(creion, x - 1, y - 1, bit_w + 2, bit_w + 2); else des.DrawRectangle(creion, x - 1, y - 1, bit_w + 2, bit_w / 2 + 2); if (vector_binar[i]) { if (dc == 0) des.FillEllipse(pens_verde, x, y, bit_w, bit_w); else des.FillRectangle(pens_verde, x, y, bit_w, bit_w / 2); } else { if (dc == 0) des.FillEllipse(pens_gri, x, y, bit_w, bit_w); else des.FillRectangle(pens_gri, x, y, bit_w, bit_w / 2); } x += 2 * bit_w; } } if (vh == 1) { for (i = 0; i < nrb; i++) { if (dc == 0) des.DrawEllipse(creion, x - 1, y - 1, bit_w + 2, bit_w + 2); else des.DrawRectangle(creion, x - 1, y - 1, bit_w + 2, bit_w / 2 + 2); if (vector_binar[i]) { if (dc == 0) des.FillEllipse(pens_verde, x, y, bit_w, bit_w); else des.FillRectangle(pens_verde, x, y, bit_w, bit_w / 2); } else { if (dc == 0) des.FillEllipse(pens_gri, x, y, bit_w, bit_w); else des.FillRectangle(pens_gri, x, y, bit_w, bit_w / 2); } y += 2 * bit_w; } } } public void setname(string[] nume_biti) { int x = 0, y = 0; if (vh == 0) { x = px0 + bit_w; y = py0 + bit_w; for (i = nrb - 1; i >= 0; i--) { des.DrawString(nume_biti[i].ToString(), font_nina, pens_rosie, x, y - 2 * bit_w); x += 2 * bit_w; } } if (vh == 1) { x = px0 + 3 * bit_w; y = py0 + 3 * bit_w; for (i = 0; i < nrb; i++) { des.DrawString(nume_biti[i].ToString(), font_nina, pens_rosie, x, y - 2 * bit_w); y += 2 * bit_w; } } } public bin_bin(Graphics desen, int pozx, int pozy, int w, int nr_biti, int v_h, int d_c, int r_v) { des = desen; creion = new System.Drawing.Pen(System.Drawing.Color.Gray, 2); pens_verde = new System.Drawing.SolidBrush(System.Drawing.Color.Lime); pens_rosie = new System.Drawing.SolidBrush(System.Drawing.Color.Red); pens_gri = new System.Drawing.SolidBrush(System.Drawing.Color.LightGray); font_nina = new System.Drawing.Font("Nina", 12); px0 = pozx; // pozitia pe x py0 = pozy; // pozitia pe y bit_w = w; // latimea unui bit nrb = nr_biti; // numarul de biti vh = v_h; // vertical(v_h=1)/orizontal(v_h=0) dc = d_c; // dreptunghi(d_c=1)/cerc(d_c=0) rv = r_v; // rosu r_v=1, verde r_v=0) } } // --------------Sfarsit clasa bin_bin --------------- } |
namespace Oop_instr_b_20 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } System.Drawing.Graphics Desen; System.Random nr; public matrix matrix1,matrix2; static Int64[] num = new Int64[0]; int biti = 8, rnd = 10; private void Form1_Load(object sender, EventArgs e) { Desen = this.CreateGraphics(); nr = new System.Random(); Array.Resize(ref num, rnd + 1); matrix1 = new matrix(Desen,20, 10, 25, 25,rnd,biti,0,0); matrix2 = new matrix(Desen, 300, 10, 25, 25, rnd, biti, 1, 1); } private void timer1_Tick(object sender, EventArgs e) { this.timer1.Interval = 333; /* for(int j=0; j < rnd; j++){ num[j]++; if (num[j] > 256) num[j] = 0; } */ for (int j = 0; j < rnd; j++) { num[j] = System.Convert.ToInt64(nr.Next(255)); } matrix1.setval(num); matrix2.setval(num); } } // ------------- Clasa matrix --------------------- public class matrix { System.Drawing.Graphics des; System.Drawing.Pen creion_gr= new System.Drawing.Pen(System.Drawing.Color.Gray); System.Drawing.SolidBrush pens_r= new System.Drawing.SolidBrush(System.Drawing.Color.Red); System.Drawing.SolidBrush pens_v = new System.Drawing.SolidBrush(System.Drawing.Color.Lime); System.Drawing.SolidBrush pens_gri = new System.Drawing.SolidBrush(System.Drawing.Color.LightGray); int x0; // pozitia pe x int y0; // pozitia pe y int wb; // latimea unui bit int hb; // inaltimea unui bit int nrr; // numarul de randuri int nrb; // numarul de biti (coloane) int dc; // dreptunghi d_c=1, cerc d_c=0) int rv; // rosu r_v=1, verde r_v=0) public void setval(Int64[] n) { int x = x0 + nrb*(wb+4)-wb; int y = y0 + hb; int i, j; if(rv==1) pens_v = pens_r; //des.DrawRectangle(creion_gr, x0, y0, (wb+4)*nrb+wb, (hb+4) *nrr+hb); for (j = 0; j < nrr; j++) { for (i = nrb - 1; i >= 0; i--) { System.Int64 bit = ((n[j] >> (nrb - i - 1)) & 1); if (dc == 1) { des.DrawRectangle(creion_gr, x - 1, y - 1, wb + 1, hb + 1); if (bit == 1) des.FillRectangle(pens_v, x, y, wb, hb); else des.FillRectangle(pens_gri, x, y, wb, hb); } if (dc == 0) { des.DrawEllipse(creion_gr, x - 1, y - 1, wb + 2, hb + 2); if (bit == 1) des.FillEllipse(pens_v, x, y, wb, hb); else des.FillEllipse(pens_gri, x, y, wb, hb); } x -= wb+4; } x = x0 + nrb * (wb+4)-wb; y += hb+4; } } public matrix(System.Drawing.Graphics desen, int pozx, int pozy, int bit_w, int bit_h, int nr_randuri, int nr_biti, int d_c, int r_v) { des = desen; x0 = pozx; // pozitia pe x y0 = pozy; // pozitia pe y wb = bit_w; // latimea unui bit hb = bit_h; // inaltimea unui bit nrr = nr_randuri; // numarul de randuri nrb = nr_biti; // numarul de biti (coloane) dc = d_c; // dreptunghi d_c=1, cerc d_c=0) rv = r_v; // rosu r_v=1, verde r_v=0) } } // ----------- sfarsit clasa matrix --------------- } |
namespace Oop_instr_b_30 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } System.Drawing.Graphics Desen; System.Drawing.Pen Creion_rosu; System.Drawing.SolidBrush Pens_blu; System.Drawing.SolidBrush Pens_back; System.Random nr; bool[,] matr; public matrix_b matrix_b1, matrix_b2; int rnd = 10, col = 10, i, j, k; private void Form1_Load(object sender, EventArgs e) { Creion_rosu = new System.Drawing.Pen(System.Drawing.Color.Red); Pens_blu = new System.Drawing.SolidBrush(System.Drawing.Color.Blue); Pens_back = new System.Drawing.SolidBrush(this.BackColor); Desen = this.CreateGraphics(); nr = new System.Random(); matr = new bool[rnd, col]; matrix_b1 = new matrix_b(Desen, 20, 20, 20, 20, rnd, col, 0, 0); matrix_b2 = new matrix_b(Desen, 300, 20, 20, 20, rnd, col, 1, 1); } private void timer1_Tick(object sender, EventArgs e) { for (j = 0; j < rnd; j++) { for (i = 0; i < col; i++) { if ((i == j + k) || (i + k == j)) matr[j, i] = true; else matr[j, i] = false; } } k++; if (k > col) k = 0; matrix_b1.setval(matr); matrix_b2.setval(matr); } } // ------------- Clasa matrix_b --------------------- public class matrix_b { System.Drawing.Graphics des; System.Drawing.Pen creion_gr = new System.Drawing.Pen(System.Drawing.Color.Gray); System.Drawing.SolidBrush pens_r = new System.Drawing.SolidBrush(System.Drawing.Color.Red); System.Drawing.SolidBrush pens_v = new System.Drawing.SolidBrush(System.Drawing.Color.Lime); System.Drawing.SolidBrush pens_gri = new System.Drawing.SolidBrush(System.Drawing.Color.LightGray); int x0; // pozitia pe x int y0; // pozitia pe y int wb; // latimea unui bit int hb; // inaltimea unui bit int nrr; // numarul de randuri int nrc; // numarul de coloane int dc; // dreptunghi d_c=1, cerc d_c=0) int rv; // rosu r_v=1, verde r_v=0) public void setval(bool[,] mat) { int x = x0 + nrc * (wb + 4) - wb; int y = y0 + hb; int i, j; if (rv == 1) pens_v = pens_r; for (j = 0; j < nrr; j++) { for (i = nrc - 1; i >= 0; i--) { if (dc == 1) { des.DrawRectangle(creion_gr, x - 1, y - 1, wb + 1, hb + 1); if (mat[j,i]) des.FillRectangle(pens_v, x, y, wb, hb); else des.FillRectangle(pens_gri, x, y, wb, hb); } if (dc == 0) { des.DrawEllipse(creion_gr, x - 1, y - 1, wb + 2, hb + 2); if (mat[j,i]) des.FillEllipse(pens_v, x, y, wb, hb); else des.FillEllipse(pens_gri, x, y, wb, hb); } x -= wb + 4; } x = x0 + nrc * (wb + 4) - wb; y += hb + 4; } } public matrix_b(System.Drawing.Graphics desen, int pozx, int pozy, int bit_w, int bit_h, int nr_randuri, int nr_coloane, int d_c, int r_v) { des = desen; x0 = pozx; // pozitia pe x y0 = pozy; // pozitia pe y wb = bit_w; // latimea unui bit hb = bit_h; // inaltimea unui bit nrr = nr_randuri; // numarul de randuri nrc = nr_coloane; // numarul de coloane dc = d_c; // dreptunghi d_c=1, cerc d_c=0) rv = r_v; // rosu r_v=1, verde r_v=0) } } // ----------- sfarsit clasa matrix_b --------------- } |
|