class ap_electric {
private:
double u_n;
double i_n;
public:
void set_u(double tens) {
if (tens < 0)
u_n=0;
else
u_n=tens;
}
int vezi_u(){
return u_n;
}
void set_i(double crnt){
if (crnt < 0)
i_n=0;
else
i_n=crnt;
}
double vezi_i() {
return i_n;
}
double vezi_p() {
return i_n*u_n;
}
};
|
#include "stdafx.h"
#include < iostream >
#include < string >
using namespace std ;
// definire clasa
class ap_electric {
private:
double u_n;
double i_n;
public:
void set_u(double tens) {
if (tens < 0)
u_n=0;
else
u_n=tens;
}
int vezi_u(){
return u_n;
}
void set_i(double crnt){
if (crnt < 0)
i_n=0;
else
i_n=crnt;
}
double vezi_i() {
return i_n;
}
double vezi_p() {
return i_n*u_n;
}
};
int main(void)
{
system("TITLE Aplicatie oop");// Titlul ferestrei consola
system("COLOR F9"); // Fundal alb caractere albastre
ap_electric a;
double u,i;
cout <<"Introduceti tensiunea: ";
cin >> u;
cout <<"\nIntroduceti curentul: ";
cin >> i;
a.set_u(u);
a.set_i(i);
cout <<"\nPuterea este: "<< a.vezi_p();
cin.ignore();
cin.get();
return 0;
}
|
int main(void)
{
ap_electric* a;
a=new ap_electric;
double u,i;
cout <<"Introduceti tensiunea: ";
cin >> u;
cout <<"\nIntroduceti curentul: ";
cin >> i;
a->set_u(u);
a->set_i(i);
cout <<"\nPuterea este: "<< a->vezi_p();
cin.ignore();
cin.get();
return 0;
}
|
namespace oop_v0
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ap_electric a = new ap_electric();
a.set_u(System.Convert.ToDouble(this.numericUpDown1.Value));
a.set_i(System.Convert.ToDouble(this.numericUpDown2.Value));
this.label1.Text=System.Convert.ToString(a.vezi_p());
}
}
public class ap_electric
{
private double u_n;
private double i_n;
public void set_u(double tens)
{
if (tens < 0)
u_n = 0;
else
u_n = tens;
}
public double vezi_u()
{
return u_n;
}
public void set_i(double crnt)
{
if (crnt < 0)
i_n = 0;
else
i_n = crnt;
}
public double vezi_i()
{
return i_n;
}
public double vezi_p()
{
return i_n * u_n;
}
}
}
|

namespace oop_00
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public System.Drawing.Graphics desen;
public System.Drawing.Pen creion_albastru;
public System.Drawing.Pen creion_rosu;
public System.Drawing.SolidBrush radiera;
public drcon drc;
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_rosu = new System.Drawing.Pen(System.Drawing.Color.Red);
radiera = new System.Drawing.SolidBrush(this.BackColor);
nr = new System.Random();
drc = new drcon();
drc.init_dr(desen, 100, 50, 100, 75);
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
drc.desenez(creion_albastru);
}
private void timer1_Tick(object sender, EventArgs e)
{
drc.sterg(radiera);
drc.setdr(creion_rosu, nr.Next(100-3), nr.Next(75-3));
}
}
public class drcon
{
int x0,y0,w0,h0;
System.Drawing.Graphics zona_des;
public void desenez(System.Drawing.Pen creion_a)
{
zona_des.DrawRectangle(creion_a, x0, y0, w0, h0);
}
public void sterg(System.Drawing.Brush rad)
{
zona_des.FillRectangle(rad, x0 + 1, y0 + 1, w0 - 1, h0 - 1);
}
public void setdr(System.Drawing.Pen creion,int w,int h)
{
int x = System.Convert.ToInt16(System.Convert.ToDouble(x0) + System.Convert.ToDouble(w0-w) / 2);
int y = System.Convert.ToInt16(System.Convert.ToDouble(y0) + System.Convert.ToDouble(h0-h) / 2);
zona_des.DrawRectangle(creion, x+1, y+1, w, h);
}
public void init_dr(System.Drawing.Graphics des,int pozx, int pozy, int lat, int inalt)
{
zona_des = des;
x0 = pozx;
y0 = pozy;
w0 = lat;
h0 = inalt;
}
}
}
|

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace oop_10
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public System.Drawing.Graphics desen;
public System.Drawing.Pen creion_albastru;
public System.Drawing.Pen creion_rosu;
public System.Drawing.SolidBrush radiera;
public drcon drc;
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_rosu = new System.Drawing.Pen(System.Drawing.Color.Red);
radiera = new System.Drawing.SolidBrush(this.BackColor);
nr = new System.Random();
drc = new drcon(desen, 100, 100, 100, 75);
}
private void timer1_Tick(object sender, EventArgs e)
{
drc.setdr(creion_rosu, creion_albastru, radiera, nr.Next(100 - 3), nr.Next(75 - 3));
}
public class drcon
{
int x0, y0, w0, h0;
System.Drawing.Graphics zona_des;
public void setdr(System.Drawing.Pen creion, System.Drawing.Pen creion_a, System.Drawing.Brush rad, int w, int h)
{
zona_des.FillRectangle(rad, x0 + 1, y0 + 1, w0 - 1, h0 - 1);
zona_des.DrawRectangle(creion_a, x0, y0, w0, h0);
int x = System.Convert.ToInt16(System.Convert.ToDouble(x0) + System.Convert.ToDouble(w0 - w) / 2);
int y = System.Convert.ToInt16(System.Convert.ToDouble(y0) + System.Convert.ToDouble(h0 - h) / 2);
zona_des.DrawRectangle(creion, x + 1, y + 1, w, h);
}
public drcon(System.Drawing.Graphics des, int pozx, int pozy, int lat, int inalt)
{
zona_des = des;
x0 = pozx;
y0 = pozy;
w0 = lat;
h0 = inalt;
}
}
}
}
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace oop_01
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public System.Drawing.Graphics desen;
public System.Drawing.Pen creion_albastru;
public System.Drawing.Pen creion_rosu;
public System.Drawing.SolidBrush radiera;
public drcon drc1;
public drcon drc2;
public drcon drc3;
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_rosu = new System.Drawing.Pen(System.Drawing.Color.Red);
radiera = new System.Drawing.SolidBrush(this.BackColor);
nr = new System.Random();
drc1 = new drcon(desen, 100, 50, 100, 75);
drc2 = new drcon(desen, 300, 50, 100, 175);
drc3 = new drcon(desen, 130, 150, 50, 55);
}
private void timer1_Tick(object sender, EventArgs e)
{
drc1.setdr(creion_rosu, creion_albastru, radiera, nr.Next(100 - 3), nr.Next(75 - 3));
drc2.setdr(creion_rosu, creion_albastru, radiera, nr.Next(100 - 3), nr.Next(175 - 3));
drc3.setdr(creion_rosu, creion_albastru, radiera, nr.Next(50 - 3), nr.Next(55 - 3));
}
}
public class drcon
{
int x0, y0, w0, h0;
System.Drawing.Graphics zona_des;
public void setdr(System.Drawing.Pen creion, System.Drawing.Pen creion_a, System.Drawing.Brush rad, int w, int h)
{
zona_des.FillRectangle(rad, x0 + 1, y0 + 1, w0 - 1, h0 - 1);
zona_des.DrawRectangle(creion_a, x0, y0, w0, h0);
int x = System.Convert.ToInt16(System.Convert.ToDouble(x0) + System.Convert.ToDouble(w0 - w) / 2);
int y = System.Convert.ToInt16(System.Convert.ToDouble(y0) + System.Convert.ToDouble(h0 - h) / 2);
zona_des.DrawRectangle(creion, x + 1, y + 1, w, h);
}
public drcon(System.Drawing.Graphics des, int pozx, int pozy, int lat, int inalt)
{
zona_des = des;
x0 = pozx;
y0 = pozy;
w0 = lat;
h0 = inalt;
}
}
}
|

namespace oop_02
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public System.Drawing.Graphics desen;
public System.Drawing.Pen creion_albastru;
public System.Drawing.Pen creion_rosu;
public System.Drawing.SolidBrush radiera;
public ccon cc;
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_rosu = new System.Drawing.Pen(System.Drawing.Color.Red);
radiera = new System.Drawing.SolidBrush(this.BackColor);
nr = new System.Random();
cc = new ccon();
cc.init_c(desen, 100, 100, 100);
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
cc.desenez(creion_albastru);
}
private void timer1_Tick(object sender, EventArgs e)
{
cc.sterg(radiera);
cc.setc(creion_rosu, nr.Next(100 - 3));
cc.setc(creion_albastru, nr.Next(100 - 3));
cc.setc(creion_rosu, nr.Next(100 - 3));
}
}
public class ccon
{
int x0, y0, r0;
System.Drawing.Graphics zona_des;
public void desenez(System.Drawing.Pen creion_a)
{
zona_des.DrawEllipse(creion_a, x0, y0, r0+2, r0+2);
}
public void sterg(System.Drawing.Brush rad)
{
zona_des.FillEllipse(rad, x0 + 1, y0 + 1, r0 - 1, r0 - 1);
}
public void setc(System.Drawing.Pen creion, int r)
{
int x = System.Convert.ToInt16(System.Convert.ToDouble(x0) + System.Convert.ToDouble(r0 - r) / 2);
int y = System.Convert.ToInt16(System.Convert.ToDouble(y0) + System.Convert.ToDouble(r0 - r) / 2);
zona_des.DrawEllipse(creion, x + 1, y + 1, r, r);
}
public void init_c(System.Drawing.Graphics des, int pozx, int pozy, int raza)
{
zona_des = des;
x0 = pozx;
y0 = pozy;
r0 = raza;
}
}
}
|

namespace oop_03
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public System.Drawing.Graphics desen;
public System.Drawing.Pen creion_albastru;
public System.Drawing.Pen creion_rosu;
public System.Drawing.SolidBrush radiera;
public ccon cc1;
public ccon cc2;
public ccon cc3;
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_rosu = new System.Drawing.Pen(System.Drawing.Color.Red);
radiera = new System.Drawing.SolidBrush(this.BackColor);
nr = new System.Random();
cc1 = new ccon();
cc1.init_c(desen, 10, 10, 100);
cc2 = new ccon();
cc2.init_c(desen, 250, 20, 200);
cc3 = new ccon();
cc3.init_c(desen, 10, 200, 50);
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
cc1.desenez(creion_albastru);
cc2.desenez(creion_albastru);
cc3.desenez(creion_albastru);
}
private void timer1_Tick(object sender, EventArgs e)
{
cc1.sterg(radiera);
cc1.setc(creion_rosu, nr.Next(100 - 3));
cc1.setc(creion_albastru, nr.Next(100 - 3));
cc1.setc(creion_rosu, nr.Next(100 - 3));
cc2.sterg(radiera);
cc2.setc(creion_rosu, nr.Next(200 - 3));
cc2.setc(creion_albastru, nr.Next(200 - 3));
cc2.setc(creion_rosu, nr.Next(200 - 3));
cc3.sterg(radiera);
cc3.setc(creion_rosu, nr.Next(50 - 3));
cc3.setc(creion_albastru, nr.Next(50 - 3));
cc3.setc(creion_rosu, nr.Next(50 - 3));
}
}
public class ccon
{
int x0, y0, r0;
System.Drawing.Graphics zona_des;
public void desenez(System.Drawing.Pen creion_a)
{
zona_des.DrawEllipse(creion_a, x0, y0, r0 + 2, r0 + 2);
}
public void sterg(System.Drawing.Brush rad)
{
zona_des.FillEllipse(rad, x0 + 1, y0 + 1, r0 - 1, r0 - 1);
}
public void setc(System.Drawing.Pen creion, int r)
{
int x = System.Convert.ToInt16(System.Convert.ToDouble(x0) + System.Convert.ToDouble(r0 - r) / 2);
int y = System.Convert.ToInt16(System.Convert.ToDouble(y0) + System.Convert.ToDouble(r0 - r) / 2);
zona_des.DrawEllipse(creion, x + 1, y + 1, r, r);
}
public void init_c(System.Drawing.Graphics des, int pozx, int pozy, int raza)
{
zona_des = des;
x0 = pozx;
y0 = pozy;
r0 = raza;
}
}
}
|

namespace oop_09
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
System.Drawing.Graphics desen;
System.Drawing.SolidBrush pens_back;
public ceas ceas1;
public ceas ceas2;
public ceas ceas3;
private void Form1_Load(object sender, EventArgs e)
{
pens_back = new System.Drawing.SolidBrush(this.BackColor);
desen = this.CreateGraphics();
ceas1 = new ceas(desen, 50, 10, 150);
ceas2 = new ceas(desen, 10, 125, 300);
ceas3 = new ceas(desen, 200, 50, 200);
}
private void timer1_Tick(object sender, EventArgs e)
{
ceas1.setval(pens_back);
ceas2.setval(pens_back);
ceas3.setval(pens_back);
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
ceas1.des_ceas(pens_back);
ceas2.des_ceas(pens_back);
ceas3.des_ceas(pens_back);
}
}
public class ceas
{
System.Drawing.Graphics zona_des;
int x0;
int y0;
int w;
public void des_ceas(System.Drawing.SolidBrush radiera)
{
int x = x0 + w / 5;
int y = y0 + w / 5;
int d = w / 2;
int x1 = x + d / 2;
int y1 = y + d / 2;
double g;
System.Drawing.Pen c_min = new System.Drawing.Pen(System.Drawing.Color.Blue);
System.Drawing.Pen c_5min = new System.Drawing.Pen(System.Drawing.Color.Red);
zona_des.DrawEllipse(c_5min, x, y, d, d);
for (g = 0; g < 360; g += 6)
{
double r = 2 * System.Math.PI * g / 360;
int x2 = Convert.ToInt16(x1 + (d / 2) * System.Math.Cos(r));
int y2 = Convert.ToInt16(y1 - (d / 2) * System.Math.Sin(r));
zona_des.DrawLine(c_min, x1, y1, x2, y2);
if (g % 30 == 0)
zona_des.DrawLine(c_5min, x1, y1, x2, y2);
else
zona_des.DrawLine(c_min, x1, y1, x2, y2);
}
zona_des.FillEllipse(radiera, x + 5, y + 5, d - 10, d - 10);
}
public void setval(System.Drawing.SolidBrush radiera)
{
System.Drawing.Pen c_sec = new System.Drawing.Pen(System.Drawing.Color.Purple);
System.Drawing.Pen c_min = new System.Drawing.Pen(System.Drawing.Color.Blue);
System.Drawing.Pen c_ore = new System.Drawing.Pen(System.Drawing.Color.Red);
int x = x0 + w / 5;
int y = y0 + w / 5;
int d = w / 2;
int x1 = x + d / 2;
int y1 = y + d / 2;
int i, x3, y3;
double r;
//secundar
i = 90 - 6 * System.DateTime.Now.Second;
r = (2 * System.Math.PI * i) / 360;
x3 = Convert.ToInt16(x1 + (d / 2 - 6) * System.Math.Cos(r));
y3 = Convert.ToInt16(y1 - (d / 2 - 6) * System.Math.Sin(r));
zona_des.FillEllipse(radiera, x + 5, y + 5, d - 10, d - 10);
zona_des.DrawLine(c_sec, x1, y1, x3, y3);
//minutar
i = 90 - 6 * System.DateTime.Now.Minute;
r = (2 * System.Math.PI * i) / 360;
x3 = Convert.ToInt16(x1 + (d / 2 - 10) * System.Math.Cos(r));
y3 = Convert.ToInt16(y1 - (d / 2 - 10) * System.Math.Sin(r));
zona_des.DrawLine(c_min, x1, y1, x3, y3);
//ora
i = 90 - (30 * System.Convert.ToInt16(System.DateTime.Now.Hour) + System.Convert.ToInt16(System.DateTime.Now.Minute) / 2);
r = (2 * System.Math.PI * i) / 360;
x3 = Convert.ToInt16(x1 + (d / 2 - 15) * System.Math.Cos(r));
y3 = Convert.ToInt16(y1 - (d / 2 - 15) * System.Math.Sin(r));
zona_des.DrawLine(c_ore, x1, y1, x3, y3);
zona_des.DrawEllipse(c_ore, x1 - 2, y1 - 2, 4, 4);
}
public ceas(System.Drawing.Graphics des, int pozx, int pozy, int lat)
{
zona_des = des;
x0 = pozx;
y0 = pozy;
w = lat;
}
}
}
|

namespace Oop_instr_10
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public System.Drawing.Graphics desen;
public afisor_xt instr;
System.Random nr;
int np = 35;
int v_max = 300;
static double[] valori = new double[0];
private void Form1_Load(object sender, EventArgs e)
{
desen = this.CreateGraphics();
nr = new System.Random();
instr = new afisor_xt(desen,10, 10, np, 200, v_max);
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
instr.desenez(Color.Blue);
}
private void timer1_Tick(object sender, EventArgs e)
{
int nr_max, val_max;
nr_max = np;
val_max = v_max;
instr.sterg(Color.White);
Array.Resize(ref valori, nr_max + 1);
for(int i=1;i<=nr_max;i++){
valori[i]=nr.Next(val_max);
}
instr.setval(Color.Red, valori);
}
}
public class afisor_xt
{
System.Drawing.Graphics zona_des;
int x0;
int y0;
int w;
int h;
double val_max;
int nrv;
public void desenez(Color culoare_contur)
{
zona_des.DrawRectangle(new Pen(culoare_contur), x0 - 1, y0 - 1, w + 2, h + 2);
}
public void sterg(Color culoare_fundal)
{
zona_des.FillRectangle(new SolidBrush(culoare_fundal), x0 + 1, y0 + 1, w - 2, h - 2);
}
public void setval(Color cul, double[] vals)
{
float val_v, val;
val_v = 0;
for (int i = 1; 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(cul), x0 + (i - 1) * 10, y0 + h - val_v, x0 + i * 10, y0 + h - val);
val_v = val;
}
}
public afisor_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 * 10;
h = inaltime;
nrv = nr_valori;
val_max = vmax;
desenez(Color.Blue);
}
}
}
|

namespace Oop_instr_10_h
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public System.Drawing.Graphics desen;
System.Random nr;
int np = 35;
int v_max = 300;
double[] valori;
public histo h1;
private void Form1_Load(object sender, EventArgs e)
{
desen = this.CreateGraphics();
nr = new System.Random();
valori = new double[np];
h1 = new histo(desen, 10, 10, np, 250, 0, v_max);
}
private void timer1_Tick(object sender, EventArgs e)
{
for (int i = 0; i < np; i++)
{
valori[i] = nr.Next(v_max);
}
h1.setval(valori, Color.Lime, Color.Black);
}
}
public class histo
{
System.Drawing.Graphics zona_des;
System.Drawing.SolidBrush rad = new System.Drawing.SolidBrush(Color.Black);
int x0;
int y0;
int w;
int h;
double val_max, val_min;
int nrv;
public void setval(double[] vals, Color culoare_afisare, Color culoare_fundal)
{
System.Drawing.Pen creion = new System.Drawing.Pen(culoare_afisare, 4);
System.Drawing.SolidBrush rad = new System.Drawing.SolidBrush(culoare_fundal);
int val;
// sterg
zona_des.FillRectangle(rad, x0 + 1, y0 + 1, w + 10, h + 2);
//desenez
double factor_s = System.Convert.ToDouble(h) / (val_max - val_min); // factor de scala
for (int i = 0; i < nrv; i++)
{
val = System.Convert.ToInt16((vals[i] - val_min) * factor_s); //scalare
zona_des.DrawLine(creion, x0 + (i + 1) * 10, y0 + h + Convert.ToInt16(val_min * factor_s), x0 + (i + 1) * 10, y0 + h - val);
}
}
public histo(System.Drawing.Graphics desen, int pozx, int pozy, int nr_valori, int inaltime, double vmin, double vmax)
{
nrv = nr_valori;
zona_des = desen;
x0 = pozx;
y0 = pozy;
w = nr_valori * 10;
h = inaltime;
val_max = vmax;
val_min = vmin;
}
}
}
|

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.Black);
instr.setval(Color.Lime, 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 - 1), y0 + val_v, x0 + i, 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_30
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public System.Drawing.Graphics desen;
int x0,y0,val_maxx, val_maxy,w,h,nr_max;
System.Random nr;
static double[] valorix = new double[0];
static double[] valoriy = new double[0];
public afisor_xy instr;
private void Form1_Load(object sender, EventArgs e)
{
desen = this.CreateGraphics();
nr = new System.Random();
nr_max = 10;
val_maxx = 300;
val_maxy = 500;
x0 = 200;
y0 = 20;
w = 200;
h = 175;
instr = new afisor_xy(desen,x0, y0, w, h, val_maxx,val_maxy);
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
instr.desenez(Color.Blue);
}
private void timer1_Tick(object sender, EventArgs e)
{
instr.sterg(Color.White);
Array.Resize(ref valorix, nr_max + 1);
Array.Resize(ref valoriy, nr_max + 1);
for (int i = 1; i <= nr_max; i++)
{
valorix[i] = nr.Next(System.Convert.ToInt32(val_maxx));
valoriy[i] = nr.Next(System.Convert.ToInt32(val_maxy));
}
instr.setval(Color.Red, valorix, valoriy, nr_max);
}
}
public class afisor_xy
{
System.Drawing.Graphics zona_des;
int x0, y0, w, h, val_maxx, val_maxy;
public void desenez(Color culoare_contur)
{
zona_des.DrawRectangle(new Pen(culoare_contur), x0 - 1, y0 - 1, w + 2, h + 2);
}
public void sterg(Color culoare_fundal)
{
zona_des.FillRectangle(new SolidBrush(culoare_fundal), x0, y0, w + 1, h + 1);
}
public void setval(Color culoare_grafic, double[] valsx, double[] valsy, int nrv)
{
int val_vx, valx, val_vy, valy;
val_vx = System.Convert.ToInt16(System.Convert.ToDouble(valsx[0]) * (System.Convert.ToDouble(w) / System.Convert.ToDouble(val_maxx)));
val_vy = System.Convert.ToInt16(System.Convert.ToDouble(valsy[0]) * (System.Convert.ToDouble(h) / System.Convert.ToDouble(val_maxy)));
for (int i = 0; i < nrv; i++)
{
valx = System.Convert.ToInt16(System.Convert.ToDouble(valsx[i]) * (System.Convert.ToDouble(w) / System.Convert.ToDouble(val_maxx))); //scalare
valy = System.Convert.ToInt16(System.Convert.ToDouble(valsy[i]) * (System.Convert.ToDouble(h) / System.Convert.ToDouble(val_maxy))); //scalare
zona_des.DrawLine(new Pen(culoare_grafic), x0 + val_vx, y0 + val_vy, x0 + valx, y0 + valy);
val_vx = valx;
val_vy = valy;
}
}
public afisor_xy(System.Drawing.Graphics desen, int pozx, int pozy, int lat, int inalt, int vmaxx, int vmaxy)
{
zona_des = desen;
x0 = pozx;
y0 = pozy;
w = lat;
h = inalt;
val_maxx = vmaxx;
val_maxy = vmaxy;
}
}
}
|

namespace Oop_instr_31
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public System.Drawing.Graphics desen;
int x0, y0, val_maxx, val_maxy, w, h,nr_max;
System.Random nr;
static double[] valorix = new double[0];
static double[] valoriy = new double[0];
public afisor_xy instr;
private void Form1_Load(object sender, EventArgs e)
{
desen = this.CreateGraphics();
nr = new System.Random();
nr_max = 500;
val_maxx = 100;
val_maxy = 100;
x0 = 10;
y0 = 10;
w = 200;
h = 200;
instr = new afisor_xy(desen, x0, y0, w, h, val_maxx, val_maxy);
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
instr.desenez(Color.Blue);
}
private void timer1_Tick(object sender, EventArgs e)
{
instr.sterg(Color.White);
Array.Resize(ref valorix, nr_max + 1);
Array.Resize(ref valoriy, nr_max + 1);
int k = System.Convert.ToInt32(nr.Next(15));
double f = 10;
//double f = nr.Next(100);
// Lisajou
//int k = 7;
//double f = 0.01*nr.Next(10);
for (int i = 1; i <= nr_max; i++)
{
//valorix[i] = System.Convert.ToInt32(val_maxx));
valorix[i] = System.Convert.ToInt32(50*(1-Math.Sin(f*i)));
valoriy[i] = System.Convert.ToInt32(50*(1-Math.Cos(f*k * i)));
}
instr.setval(Color.Red, valorix, valoriy, nr_max);
}
}
public class afisor_xy
{
System.Drawing.Graphics zona_des;
int x0, y0, w, h, val_maxx, val_maxy;
public void desenez(Color culoare_contur)
{
zona_des.DrawRectangle(new Pen(culoare_contur), x0 - 1, y0 - 1, w + 2, h + 2);
}
public void sterg(Color culoare_fundal)
{
zona_des.FillRectangle(new SolidBrush(culoare_fundal), x0, y0, w + 1, h + 1);
}
public void setval(Color culoare_grafic, double[] valsx, double[] valsy, int nrv)
{
int val_vx, valx, val_vy, valy;
val_vx = System.Convert.ToInt16(System.Convert.ToDouble(valsx[0]) * (System.Convert.ToDouble(w) / System.Convert.ToDouble(val_maxx)));
val_vy = System.Convert.ToInt16(System.Convert.ToDouble(valsy[0]) * (System.Convert.ToDouble(h) / System.Convert.ToDouble(val_maxy)));
for (int i = 0; i < nrv; i++)
{
valx = System.Convert.ToInt16(System.Convert.ToDouble(valsx[i]) * (System.Convert.ToDouble(w) / System.Convert.ToDouble(val_maxx))); //scalare
valy = System.Convert.ToInt16(System.Convert.ToDouble(valsy[i]) * (System.Convert.ToDouble(h) / System.Convert.ToDouble(val_maxy))); //scalare
zona_des.DrawLine(new Pen(culoare_grafic), x0 + val_vx, y0 + val_vy, x0 + valx, y0 + valy);
val_vx = valx;
val_vy = valy;
}
}
public afisor_xy(System.Drawing.Graphics desen, int pozx, int pozy, int lat, int inalt, int vmaxx, int vmaxy)
{
zona_des = desen;
x0 = pozx;
y0 = pozy;
w = lat;
h = inalt;
val_maxx = vmaxx;
val_maxy = vmaxy;
}
}
}
|

namespace Oop_instr_32
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public System.Drawing.Graphics desen;
int x0, y0, val_maxx, val_maxy, w, h,nr_max;
System.Random nr;
static double[] valorix = new double[0];
static double[] valoriy = new double[0];
public afisor_xy instr1,instr2,instr3;
private void Form1_Load(object sender, EventArgs e)
{
desen = this.CreateGraphics();
nr = new System.Random();
nr_max = 500;
val_maxx = 100;
val_maxy = 100;
x0 = 10;
y0 = 10;
w = 200;
h = 200;
instr1 = new afisor_xy(desen,x0, y0, w, h, val_maxx, val_maxy);
instr2 = new afisor_xy(desen, 400, 100, 150, 170, val_maxx, val_maxy);
instr3 = new afisor_xy(desen,250, 120, 120, 120, val_maxx, val_maxy);
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
instr1.desenez(Color.Blue);
instr2.desenez(Color.Blue);
instr3.desenez(Color.Blue);
}
private void timer1_Tick(object sender, EventArgs e)
{
int i, k;
Array.Resize(ref valorix, nr_max + 1);
Array.Resize(ref valoriy, nr_max + 1);
double f = 10;
k = System.Convert.ToInt32(1 + nr.Next(15));
for (i = 1; i <= nr_max; i++)
{
valorix[i] = System.Convert.ToInt32(50 * (1 - Math.Sin(f * i)));
valoriy[i] = System.Convert.ToInt32(50 * (1 - Math.Cos(f * k * i)));
}
instr1.sterg(Color.White);
instr1.setval(Color.Red, valorix, valoriy,nr_max);
k = System.Convert.ToInt32(1 + nr.Next(15));
for (i = 1; i <= nr_max; i++)
{
valorix[i] = System.Convert.ToInt32(50 * (1 - Math.Sin(f * i)));
valoriy[i] = System.Convert.ToInt32(50 * (1 - Math.Cos(f * k * i)));
}
instr2.sterg(Color.White);
instr2.setval(Color.Red, valorix, valoriy, nr_max);
k = System.Convert.ToInt32(1 + nr.Next(15));
for (i = 1; i <= nr_max; i++)
{
valorix[i] = System.Convert.ToInt32(50 * (1 - Math.Sin(f * i)));
valoriy[i] = System.Convert.ToInt32(50 * (1 - Math.Cos(f * k * i)));
}
instr3.sterg(Color.White);
instr3.setval(Color.Red, valorix, valoriy, nr_max);
}
}
public class afisor_xy
{
System.Drawing.Graphics zona_des;
int x0, y0, w, h, val_maxx, val_maxy;
public void desenez(Color culoare_contur)
{
zona_des.DrawRectangle(new Pen(culoare_contur), x0 - 1, y0 - 1, w + 2, h + 2);
}
public void sterg(Color culoare_fundal)
{
zona_des.FillRectangle(new SolidBrush(culoare_fundal), x0, y0, w + 1, h + 1);
}
public void setval(Color culoare_grafic, double[] valsx, double[] valsy, int nrv)
{
int val_vx, valx, val_vy, valy;
val_vx = System.Convert.ToInt16(System.Convert.ToDouble(valsx[0]) * (System.Convert.ToDouble(w) / System.Convert.ToDouble(val_maxx)));
val_vy = System.Convert.ToInt16(System.Convert.ToDouble(valsy[0]) * (System.Convert.ToDouble(h) / System.Convert.ToDouble(val_maxy)));
for (int i = 0; i < nrv; i++)
{
valx = System.Convert.ToInt16(System.Convert.ToDouble(valsx[i]) * (System.Convert.ToDouble(w) / System.Convert.ToDouble(val_maxx))); //scalare
valy = System.Convert.ToInt16(System.Convert.ToDouble(valsy[i]) * (System.Convert.ToDouble(h) / System.Convert.ToDouble(val_maxy))); //scalare
zona_des.DrawLine(new Pen(culoare_grafic), x0 + val_vx, y0 + val_vy, x0 + valx, y0 + valy);
val_vx = valx;
val_vy = valy;
}
}
public afisor_xy(System.Drawing.Graphics desen, int pozx, int pozy, int lat, int inalt, int vmaxx, int vmaxy)
{
zona_des = desen;
x0 = pozx;
y0 = pozy;
w = lat;
h = inalt;
val_maxx = vmaxx;
val_maxy = vmaxy;
}
}
}
|

namespace oop_v30
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public System.Drawing.Graphics desen;
public dr d;
private void button1_Click(object sender, EventArgs e)
{
d.deplasez();
d.desenez(desen);
}
private void Form1_Load(object sender, EventArgs e)
{
desen = this.CreateGraphics();
d = new dr();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
d.desenez(desen);
}
}
public class dr
{
float pozX;
float pozY;
float vX;
float w;
System.Drawing.Pen creion_a;
System.Random nr;
public void desenez(System.Drawing.Graphics zona_des)
{
zona_des.Clear(System.Drawing.Color.White);
zona_des.DrawRectangle(creion_a, pozX, pozY, w, w);
}
public void deplasez()
{
pozX += vX;
if (pozX > 440 - w)
{
vX = -vX;
w = nr.Next(40) + 2;
pozX = 440 - w;
}
if (pozX < 0)
{
vX = -vX;
w = nr.Next(40) + 2;
pozX = 0;
}
}
public dr()
{
nr = new System.Random();
//pozX = nr.Next(400);
//pozY = nr.Next(300);
//vX = nr.Next(10) + 1;
pozX = 10;
pozY = 100;
vX = 27;
w = nr.Next(30)+10;
creion_a = new System.Drawing.Pen(System.Drawing.Color.Blue);
}
}
}
|

public dr()
{
nr = new System.Random();
pozX = 10;
pozY = 100;
vX = 27;
w = nr.Next(30)+10;
creion_a = new System.Drawing.Pen(System.Drawing.Color.Blue);
}
|
public void desenez(System.Drawing.Graphics zona_des)
{
zona_des.Clear(System.Drawing.Color.White);
zona_des.DrawRectangle(creion_a, pozX, pozY, w, w);
}
|
public void deplasez()
{
pozX += vX;
if (pozX > 440 - w)
{
vX = -vX;
w = nr.Next(40) + 2;
pozX = 440 - w;
}
if (pozX < 0)
{
vX = -vX;
w = nr.Next(40) + 2;
pozX = 0;
}
}
|
namespace oop_v31
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public System.Drawing.Graphics desen;
public System.Drawing.Pen creion_a;
public dr d;
private void Form1_Load(object sender, EventArgs e)
{
desen = this.CreateGraphics();
creion_a = new System.Drawing.Pen(System.Drawing.Color.Blue);
d = new dr();
}
private void timer1_Tick(object sender, EventArgs e)
{
desen.Clear(System.Drawing.Color.White);
d.deplasez();
d.desenez(desen, creion_a);
}
}
public class dr
{
int pozX,pozY,vX,w;
System.Random nr;
public void desenez(System.Drawing.Graphics zona_des, System.Drawing.Pen creion)
{
zona_des.DrawRectangle(creion, pozX, pozY, w, w);
}
public void deplasez()
{
pozX += vX;
if (pozX > 440 - w)
{
vX = -vX;
w = nr.Next(40) + 2;
pozX = 440 - w;
}
if (pozX < 0)
{
vX = -vX;
w = nr.Next(40) + 2;
pozX = 0;
}
}
public dr()
{
nr = new System.Random();
pozX = nr.Next(400);
pozY = nr.Next(200);
vX = nr.Next(50) + 1;
w = nr.Next(40);
}
}
}
|
namespace oop_v4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
System.Drawing.Graphics desen;
dr[] drr;
int nr_c, i;
void sterg_desen()
{
desen.Clear(this.BackColor);
}
void creare_drr()
{
nr_c = 20;
drr = new dr[nr_c];
for (i = 0; i < nr_c; i++)
{
drr[i] = new dr(i, this.Width - 50, this.Height - 80);
}
}
void trasez_drr()
{
for (i = 0; i < nr_c; i++)
drr[i].desenez(desen, this.Width - 20, this.Height - 45);
}
void depl_drr()
{
for (i = 0; i < nr_c; i++)
drr[i].deplasez(this.Width - 20, this.Height - 45);
}
private void Form1_Activated(object sender, EventArgs e)
{
desen = this.CreateGraphics();
creare_drr();
}
private void timer1_Tick(object sender, EventArgs e)
{
sterg_desen();
trasez_drr();
depl_drr();
}
private void button1_Click(object sender, EventArgs e)
{
creare_drr();
}
private void trackBar1_Scroll(object sender, EventArgs e)
{
this.timer1.Interval = this.trackBar1.Value;
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
desen = this.CreateGraphics();
creare_drr();
}
}
public class dr
{
public Int32 pozX, pozY, vX, vY, accX, accY, raza;
public System.Drawing.Pen creion_a;
public int desenez(System.Drawing.Graphics zona_des, int lung, int lat)
{
zona_des.DrawRectangle(creion_a, pozX, pozY, raza, raza);
return 1;
}
public void deplasez(int lung, int lat)
{
System.Random nr = new System.Random();
pozX += vX;
if ((pozX > lung - raza - 40) || (pozX < 0))
{
raza = 10 + nr.Next(40);
vX = -vX;
}
}
public dr(int r, int lung, int lat)
{
System.Random nr = new System.Random(r);
pozX = 5 + nr.Next(lung - 50);
pozY = 50 + nr.Next(lat - 70);
vX = 10 + nr.Next(20);
raza = 10 + nr.Next(40);
creion_a = new System.Drawing.Pen(System.Drawing.Color.Blue);
}
}
}
|
desen = this.CreateGraphics();
creare_drr();
|
sterg_desen();
trasez_drr();
depl_drr();
|

namespace oop_v1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Graphics desen;
cerc c;
private void Form1_Activated(object sender, EventArgs e)
{
desen = this.CreateGraphics();
c = new cerc(this.Width-50,this.Height-80);
}
private void timer1_Tick(object sender, EventArgs e)
{
desen.Clear(this.BackColor);
c.desenez(desen);
c.deplasez(this.Width - 20, this.Height - 45);
}
private void button1_Click(object sender, EventArgs e)
{
c.arunc();
}
}
public class cerc {
public double vX, vY, accX, accY;
int pozX, pozY, raza;
public System.Drawing.Pen creion_a;
public void arunc()
{
pozY = raza;
}
public void desenez (System.Drawing.Graphics zona_des)
{
zona_des.DrawEllipse(creion_a,pozX,pozY,raza,raza);
}
public void deplasez (int lung,int lat)
{
pozX += Convert.ToInt16(vX);
pozY += Convert.ToInt16(vY);
vX = vX + accX;
vY = vY + accY;
if((pozX>lung-raza)||(pozX<0))
{
vX = -vX;
}
if((pozY>=lat-raza)||(pozY<=0)||(vY==0))
{
if(pozY>lat-raza)
vY = vY-vY/10; //forta elastica
//la ciocnirea cu solul se pierde 10% din viteza
vY = -vY;
}
}
public cerc (int lung,int lat)
{
Random nr = new Random();
pozX = nr.Next(lung);
pozY = nr.Next(lat);
vX = 2;
vY = 2;
accX = 0;
accY = 0.12;
raza = 35;
creion_a =new Pen(Color.Blue);
}
}
}
|

public cerc(int r, int lung, int lat)
{
System.Random nr = new System.Random(r);
pozX = nr.Next(lung);
pozY = nr.Next(lat);
vX = 3;
vY = 1;
accX = 1 / 2;
accY = 1;
raza = 10 + nr.Next(40);
creion_a = new System.Drawing.Pen(System.Drawing.Color.Blue);
}
|
public int desenez(System.Drawing.Graphics zona_des, int lung, int lat)
{
zona_des.DrawEllipse(creion_a, pozX, pozY, raza, raza);
return 1;
}
|
public void deplasez(int lung, int lat)
{
pozX += vX;
pozY += vY;
vX = vX + accX;
vY = vY + accY;
vY -= vY / 100;
if ((pozX > lung - raza) || (pozX < 0))
{
vX = -vX;
}
if ((pozY > lat - raza) || (pozY < 0))
{
vY = -vY;
}
}
|
desen.Clear(this.BackColor);
c.desenez(desen);
c.deplasez();
|
c.init_cerc(1);
|
namespace oop_v2
{
public partial class Form1 : Form
{ public Form1()
{
InitializeComponent();
}
System.Drawing.Graphics desen;
cerc[] cercuri;
int nr_c, i;
void sterg_desen()
{
desen.Clear(this.BackColor);
}
void creare_cercuri()
{
nr_c = 20;
cercuri = new cerc[nr_c];
for (i = 0; i < nr_c; i++)
{
cercuri[i] = new cerc(i,this.Width-50,this.Height-80);
}
}
void trasez_cercuri()
{
for (i = 0; i < nr_c; i++)
cercuri[i].desenez(desen,this.Width-20,this.Height-45);
}
void depl_cercuri()
{
for (i = 0; i < nr_c; i++)
cercuri[i].deplasez(this.Width-20, this.Height-45);
}
private void Form1_Activated(object sender, EventArgs e)
{
desen = this.CreateGraphics();
creare_cercuri();
}
private void button1_Click(object sender, EventArgs e)
{
creare_cercuri();
}
private void timer1_Tick(object sender, EventArgs e)
{
sterg_desen();
trasez_cercuri();
depl_cercuri();
}
private void trackBar1_Scroll(object sender, EventArgs e)
{
this.timer1.Interval = this.trackBar1.Value;
}
}
public class cerc
{
public int pozX, pozY, raza;
public double vX, vY, accX, accY ;
public void desenez(Graphics zona_des,int lung,int lat)
{
zona_des.DrawEllipse(new Pen(Color.Blue), pozX, pozY, raza, raza);
}
public void deplasez(int lung,int lat)
{
pozX += Convert.ToInt16(vX);
pozY += Convert.ToInt16(vY);
if(vX>0)
vX = vX - accX;
else
vX = vX + accX;
vY = vY + accY;
if ((pozX > lung - raza) || (pozX < 0))
{
//vX = vX - vX / 10; //forta elastica
//la ciocnirea cu peretii se pierde 10% din viteza
vX = -vX;
}
if ((pozY > lat - raza) || (pozY < 0) || (vY == 0))
{
if (pozY > lat - raza)
vY = vY - vY / 10; //forta elastica
//la ciocnirea cu solul se pierde 10% din viteza
vY = -vY;
}
}
public cerc(int r,int lung,int lat)
{
Random nr = new Random(r);
pozX = nr.Next(lung);
pozY = nr.Next(lat);
vX = 3;
vY = 1;
//accX = 0.002;
accX = 0;
accY = 0.12;
raza = 10+nr.Next(40);
}
}
}
|
desen = this.CreateGraphics(); creare_cercuri(); |
sterg_desen(); trasez_cercuri(); depl_cercuri(); |
creare_cercuri(); |

|
|