|
Instructiuni:
while (expresie); |
// Program scris in C++ Visual Studio 2005 de tipul:CLR console application // Programul afiseaza primele 10 numere naturale #include "stdafx.h" #include < iostream > using namespace std; int main(void) { int i=1; cout <<" \n\tNumerele sunt: "; while (i<=10) { cout << i << " "; i+=1; } cin.ignore(); cin.get(); return 0; } |
#include "stdafx.h" #include < iostream > using namespace std; int main(void) { int i=0; while(i < 500) { cout << rand()%10 <<" "; i++; } cin.ignore(); cin.get(); return 0; } |
// Programul calculeaza n factorial. #include "stdafx.h" #include < iostream > using namespace std; int main(void) { int i=1,n; double fact=1; cout <<" \n\tProgramul calculeaza n Factorial "; cout <<" \n\n\tIntroduceti numarul n: "; cin >> n; while (i<=n) { fact*=i; i+=1; } cout <<" \n\n\tRezultat: "<< n << "! =" << fact; cin.ignore(); cin.get(); return 0; } |
// Programul calculeaza integrala functiei x^2 pe intervalul 0-10 #include "stdafx.h" #include < iostream > using namespace std; int main(void) { double s=0; double x0=0; double x1=10; double nr_pasi=1000000; const double pas=(x1-x0)/nr_pasi; double x=x0; while (x<=x1) { s=s+x*x*pas; x=x+pas; } cout <<" \n\tIntegrala este: " << s; cin.ignore(); cin.get(); return 0; } |
int i,j,h,w,d,n=10; // i contor dreptunghiuri concentrice // n nr dreptunghiuri concentrice System.Drawing.Graphics Desen; Desen = this.CreateGraphics(); System.Drawing.Pen Creion_albastru; Creion_albastru =new System.Drawing.Pen(System.Drawing.Color.Blue); Desen.Clear(this.BackColor); h=this.Height-30; //inaltimea maxima a dreptunghiurilor w=this.Width; //latimea maxima a dreptunghiului d=h/2/n; //distanta intre doua dreptunghiuri concentrice i=0; while (i<=d*n){ Desen.DrawRectangle(Creion_albastru, i+10, i+10, (w-30-2*i), (h-30-2*i)); i+=d; } |
int i, x1, y1, w, h; System.Drawing.Graphics Desen; System.Drawing.SolidBrush Pens_g, Pens_w; System.Drawing.Pen Creion_g; Desen = this.CreateGraphics(); Pens_g = new System.Drawing.SolidBrush(System.Drawing.Color.LightGray); Pens_w = new System.Drawing.SolidBrush(System.Drawing.Color.WhiteSmoke); Creion_g = new System.Drawing.Pen(System.Drawing.Color.Gray, 3); System.Random n = new System.Random(); Desen.Clear(this.BackColor); i = 0; while (i <= 50) { x1 = n.Next(this.Width); y1 = n.Next(this.Height); w = n.Next(75); h = this.Height - y1; if (i % 2 == 0) { Desen.DrawRectangle(Creion_g, x1, y1, w, h); Desen.FillRectangle(Pens_g, x1 + 1, y1 + 1, w - 1, h - 1); } else { Desen.DrawRectangle(Creion_g, x1, y1, w, h); Desen.FillRectangle(Pens_w, x1 + 1, y1 + 1, w - 1, h - 1); } i++; } |
int i=0; System.Drawing.Graphics Desen; Desen = this.CreateGraphics(); System.Drawing.Pen Creion_gri; Creion_gri=new System.Drawing.Pen(System.Drawing.Color.LightGray); Desen.Clear(this.BackColor); // linii verticale while (i<=this.Width){ Desen.DrawLine(Creion_gri, i, 0, i,this.Height); i+=10; } // linii orizontale i=0; while (i<=this.Height){ Desen.DrawLine(Creion_gri, 0, i,this.Width,i); i+=10; } |
int i=0; System.Drawing.Graphics Desen; Desen = this.CreateGraphics(); System.Drawing.Pen Creion_gri_d; Creion_gri_d=new System.Drawing.Pen(System.Drawing.Color.LightGray); System.Drawing.Pen Creion_gri; Creion_gri=new System.Drawing.Pen(System.Drawing.Color.Gray); Desen.Clear(this.BackColor); // linii verticale while (i<=this.Width){ if (i%50==0) Desen.DrawLine(Creion_gri, i, 0, i,this.Height); else Desen.DrawLine(Creion_gri_d, i, 0, i,this.Height); i+=10; } // linii orizontale i=0; while (i<=this.Height){ if (i%50==0) Desen.DrawLine(Creion_gri, 0, i,this.Width,i); else Desen.DrawLine(Creion_gri_d, 0, i,this.Width,i); i+=10; } |
int i,j,h,w,d,m=3,n=10; // j contor dreptunghiuri // i contor dreptunghiuri concentrice // m nr dreptunghiuri // n nr dreptunghiuri concentrice System.Drawing.Graphics Desen; Desen = this.CreateGraphics(); System.Drawing.Pen Creion_albastru; Creion_albastru =new System.Drawing.Pen(System.Drawing.Color.Blue); Desen.Clear(this.BackColor); h=this.Height-30; //inaltimea maxima a dreptunghiurilor w=this.Width/m; //latimea maxima a dreptunghiului d=w/2/n; // distanta intre doua dreptunghiuri concentrice j=0; while (j<=m*w){ i=0; while (i<=d*n){ Desen.DrawRectangle(Creion_albastru, j+i+10, i+10, (w-20-2*i), (h-20-2*i)); i+=d; } j+=w; } |
// Program scris in C++ Visual Studio 2005 de tipul:CLR console application // Program pentru calculul sectiunii unui conductor electric // Se citeste diametrul conductorului electric se afiseaza aria sectiunii lui // Se reia programul pana se raspunde cu N la intrebarea : "Continuati ?" #include "stdafx.h" #include < iostream > using namespace std; int main(void) { double d,s; char c='D'; cout <<" \nProgram pentru calculul sectiunii unui conductor electric"; do { cout <<" \n\n\tIntroduceti diametrul conductorului:"; cin >> d; s=3.14*(d/2)*(d/2); cout <<" \n\n\tSectiunea conductorului de diametru : "<< d << " este : " << s; cin.ignore(); cout <<" \n\n\tContinuati (D/N) ?:"; cin >> c; } while (c=='D' || c=='d' ); return 0; } |
// Program scris in C++ Visual Studio 2005 de tipul:CLR console application // Program pentru calculul sectiunii unui conductor electric // Se citeste diametrul conductorului electric se afiseaza aria sectiunii lui // Programul se reia pana se introduce valoarea 0 la diametru #include "stdafx.h" #include < iostream > using namespace std; int main(void) { double d,s; cout <<" \nProgram pentru calculul sectiunii unui conductor electric"; do { cout <<" \n\n\tIntroduceti diametrul conductorului (0=terminare program):"; cin >> d; s=System::Math::PI*(d/2)*(d/2); cout <<" \n\n\tSectiunea conductorului de diametru : "<< d << " este : " << s; cin.ignore(); } while (d!=0 ); return 0; } |
int i=0; System.Drawing.Graphics Desen; Desen = this.CreateGraphics(); System.Drawing.Pen Creion_albastru; Creion_albastru =new System.Drawing.Pen(System.Drawing.Color.Blue); do { Desen.DrawLine(Creion_albastru, this.Width/2, 0, i, this.Height-30); i+=10; } while (i<=this.Width); |
int x1, y1, w, h; int nr_s = 20; System.Drawing.Graphics Desen; Desen = this.CreateGraphics(); System.Drawing.Pen Creion_g; Creion_g = new System.Drawing.Pen(System.Drawing.Color.LightGray, 2); System.Random n = new System.Random(); Desen.Clear(this.BackColor); x1 = 0; do { y1 = 0; w = 3 + n.Next(12); h = n.Next(this.Height); Desen.DrawLine(Creion_g, x1, y1, x1 + w / 2, h); Desen.DrawLine(Creion_g, x1 + w, y1, x1 + w / 2, h); x1 = x1 + this.Width / nr_s; } while (x1 <= this.Width); |
int i, x0, y0, w; System.Drawing.Graphics Desen; System.Random n; System.Drawing.Pen Creion_albastru; Desen = this.CreateGraphics(); Creion_albastru = new System.Drawing.Pen(System.Drawing.Color.Blue); n = new System.Random(); w = 30; i = 0; do { x0 = n.Next(this.Width-w); y0 = n.Next(this.Height-w); Desen.DrawEllipse(Creion_albastru, x0, y0, w, w); i ++; } while (i < 20); |
int i=0,j=0; System.Drawing.Graphics Desen; Desen = this.CreateGraphics(); System.Drawing.Pen Creion_rosu; Creion_rosu=new System.Drawing.Pen(System.Drawing.Color.Red); Desen.Clear(this.BackColor); do{ i=0; do{ Desen.DrawEllipse( Creion_rosu, i, j, 25,25); i+=30; }while (i<=this.Width-30); j+=30; }while (j<=this.Height-50); |
int i,j, x0, y0, w; System.Drawing.Graphics Desen; System.Random n; System.Drawing.Pen Creion_albastru; Desen = this.CreateGraphics(); Creion_albastru = new System.Drawing.Pen(System.Drawing.Color.Blue); n = new System.Random(); j = 0; do { w = n.Next(this.Width); x0 = n.Next(this.Width); y0 = n.Next(this.Height); i = x0-w/2; do { Desen.DrawLine(Creion_albastru, x0, y0, i, this.Height - 30); i += 10; } while (i < x0 + w); j++; } while (j < 10); |
#include "stdafx.h" #include < iostream > using namespace std; int main(void) { cout << " Numerele afisate pe 5 coloane sunt:\n"; for(int i=0; i<=100; i++) { if(i%5==0) cout<<"\n"; cout << i << " \t"; } cin.ignore(); cin.get(); return 0; } |
#include "stdafx.h" #include < iostream > using namespace std; int main(void) { cout << " Primele 100 de patrate sunt:\n"; int p=1; for(int i=0; i<100; i++) { if(i%5==0) cout<<"\n"; cout << p*p <<" \t"; p++; } cin.ignore(); cin.get(); return 0; } |
#include "stdafx.h" #include < iostream > using namespace std; int main(void) { cout << " 100 de numere aleatoare intre 0 si " << RAND_MAX << "\n"; for(int i=0; i < 100; i++) { if(i%5==0) cout<<"\n"; cout << rand() <<" \t"; } cin.ignore(); cin.get(); return 0; } |
#include "stdafx.h" #include < iostream > using namespace std; int main(void) { cout << " 100 de numere aleatoare intre 0 si 700 \n"; for(int i=0; i < 100; i++) { if(i%5==0) cout<<"\n"; cout << rand()%700 <<" \t"; } cin.ignore(); cin.get(); return 0; } |
#include "stdafx.h" #include < iostream > using namespace std; int main(void) { srand(1000); cout << " 100 de numere aleatoare intre 0 si " << RAND_MAX << "\n"; for(int i=0; i < 100; i++) { if(i%5==0) cout<<"\n"; cout << rand() <<" \t"; } cin.ignore(); cin.get(); return 0; } |
#include "stdafx.h" #include < iostream > #include < ctime > // pentru functia time() using namespace std; int main(void) { int nr; int seed=time(0); srand(seed); nr=rand(); cout << " 100 de numere aleatoare intre 0 si " << RAND_MAX << "\n"; for(int i=0; i < 100; i++) { if(i%5==0) cout<<"\n"; cout << rand() <<" \t"; } cin.ignore(); cin.get(); return 0; } |
// Program scris in C++ Visual Studio 2005 de tipul:CLR console application // Se utilizeaza spatiul de nume System:: // programul afiseaza 500 de cifre aleatoare intre 0-9 despartite prin spatiu #include "stdafx.h" using namespace System; int main(void) { System::Random^ n = gcnew System::Random(8); for ( int i=1; i<=500; i++) Console::Write(n->Next(10)+" "); Console::ReadLine(); return 0; } |
int i=0; System.Drawing.Graphics Desen; Desen = this.CreateGraphics(); System.Drawing.Pen Creion_rosu; Creion_rosu=new System.Drawing.Pen(System.Drawing.Color.Red); System.Drawing.Pen Creion_albastru; Creion_albastru=new System.Drawing.Pen(System.Drawing.Color.Blue); System.Random n = new System.Random(8); Desen.Clear(this.BackColor); i=0; for (i=1; i<=100; i++){ Desen.DrawRectangle(Creion_albastru,n.Next(this.Width),n.Next(this.Height),n.Next(75),n.Next(50)); Desen.DrawEllipse(Creion_rosu,n.Next(this.Width),n.Next(this.Height),n.Next(50),n.Next(75)); } |
System.Drawing.Graphics Desen; Desen = this.CreateGraphics(); System.Drawing.SolidBrush Pensula; Pensula=new System.Drawing.SolidBrush(System.Drawing.Color.Red); System.Drawing.Font font_arial; font_arial=new System.Drawing.Font("Arial",12); System.String text_t="Text Arial de marime 12 \n -de culoare rosie \n- scris incepand cu pozitia 20,75"; Desen.DrawString(text_t,font_arial,Pensula,20,75); |
System.Drawing.Graphics Desen; Desen = this.CreateGraphics(); System.Drawing.SolidBrush Pensula; Pensula=new System.Drawing.SolidBrush(System.Drawing.Color.DarkOrchid ); System.Drawing.Font font_nina; font_nina=new System.Drawing.Font("Nina",8); for ( int i=1; i<=20; i++) Desen.DrawString(System.Convert.ToString(i),font_nina,Pensula,10+i*15,50); |
// Se utilizeaza spatiul de nume std // programul afiseaza numerele de la 100 la 150 pe 15 linii a cate 10 caractere. #include "stdafx.h" #include < iostream > using namespace std; int main(void) { int k=100; for (int j=1; j<=15 ; j++){ for ( int i=1; i<=10; i++) cout << k++ << " "; cout <<":\n"; } cin.ignore(); cin.get(); return 0; } |
// Se utilizeaza spatiul de nume System:: // programul afiseaza numerele de la 100 la 150 pe 15 linii a cate 10 caractere. #include "stdafx.h" using namespace System; int main(void) { int k=100; for (int j=1; j<=15 ; j++){ for ( int i=1; i<=10; i++) Console::Write(k++ + " "); Console::WriteLine(":"); } Console::ReadLine(); return 0; } |
System.Drawing.Graphics Desen; Desen = this.CreateGraphics(); System.Drawing.SolidBrush Pensula; Pensula=new System.Drawing.SolidBrush(System.Drawing.Color.Red); System.Drawing.Font font_arial; font_arial=new System.Drawing.Font("Arial",8); for (int j=1; j<=10 ; j++ ){ for ( int i=1; i<=10; i++){ Desen.DrawString(System.Convert.ToString(i+10*(j-1)),font_arial,Pensula,10+i*30,25+j*15); } } |
int i=0; bool repeta=true; System.Drawing.Graphics Desen; Desen = this.CreateGraphics(); System.Drawing.Pen Creion_rosu; Creion_rosu=new System.Drawing.Pen(System.Drawing.Color.Red); System.Drawing.Pen Creion_albastru; Creion_albastru=new System.Drawing.Pen(System.Drawing.Color.Blue); System.Random n = new System::Random(); while (repeta=true){ Desen.Clear(this.BackColor); i=0; for ( int i=1; i<=100; i++){ Desen.DrawRectangle(Creion_albastru,n.Next(this.Width),n.Next(this.Height),n.Next(75),n.Next(50)); Desen.DrawEllipse(Creion_rosu,n.Next(this.Width),n.Next(this.Height),n.Next(50),n.Next(75)); } } |
int i=0; System.Drawing.Graphics Desen; Desen = this.CreateGraphics(); System.Drawing.Pen Creion_rosu; Creion_rosu=new System.Drawing.Pen(System.Drawing.Color.Red); System.Drawing.Pen Creion_albastru; Creion_albastru=new System.Drawing.Pen(System.Drawing.Color.Blue); System.Random n = new System.Random(); Desen.Clear(this.BackColor); for (i=1; i<=100; i++){ Desen.DrawRectangle( Creion_albastru,n.Next(this.Width),n.Next(this.Height),n.Next(75),n.Next(50)); Desen.DrawEllipse( Creion_rosu,n.Next(this.Width),n.Next(this.Height),n.Next(50),n.Next(75)); } |
int i=0; System.Drawing.Graphics Desen; Desen = this.CreateGraphics(); System.Drawing.Pen Creion_blue; Creion_blue=new System.Drawing.Pen(System.Drawing.Color.DeepSkyBlue); Desen.Clear(this.BackColor); do { int factor_s=this.Height/2-22; int y = System.Convert.ToInt16(5 + factor_s * (1 - System.Math.Sin(0.0314 * i))); Desen.DrawLine(Creion_blue, i, this.Height, i, y); i+=2; } while (i<=this.Width); |
int i = 0; System.Drawing.Graphics Desen; Desen = this.CreateGraphics(); System.Drawing.Pen Creion_blue; Creion_blue = new System.Drawing.Pen(System.Drawing.Color.DeepSkyBlue); Desen.Clear(this.BackColor); do { int factor_s = this.Height / 2-22 ; int y = System.Convert.ToInt16(factor_s * (1 - System.Math.Sin(0.0314 * i))); Desen.DrawLine(Creion_blue, i, this.Height/2-22, i, y); i += 5; } while (i <= this.Width); |
int i = 0, y = 0, y_v = 0, w = 0, h = 0, k = 0; double x, rad = 7; System.Drawing.Graphics Desen; Desen = this.CreateGraphics(); System.Drawing.Pen Creion_blu; Creion_blu = new System.Drawing.Pen(System.Drawing.Color.DeepSkyBlue); Desen.Clear(this.BackColor); w = this.Width; // latimea h = this.Height - 50; // inaltimea (50=inaltimea title bar-ului) k = h / 2; // factor de scala do { x = i * rad * System.Math.PI / w; y = System.Convert.ToInt16(k * (1 - System.Math.Sin(x))); Desen.DrawLine(Creion_blu, i - 1, y_v, i, y); y_v = y; i += 1; } while (i <= w); |
int i=0,y=0,y_v=0,lat,factor_s; double x,rad; System.Drawing.Graphics Desen; Desen = this.CreateGraphics(); System.Drawing.Pen Creion_blu; Creion_blu=new System.Drawing.Pen(System.Drawing.Color.DeepSkyBlue); Desen.Clear(this.BackColor); factor_s=this.Height/2-37; rad=System.Convert.ToDouble(this.numericUpDown1.Value); lat=this.Width; do { x=i*rad*System.Math.PI/(lat-10); y=System.Convert.ToInt16(35+factor_s*(1-System.Math.Sin(x))); Desen.DrawLine(Creion_blu, i-1,y_v, i, y); y_v=y; i+=1; } while (i<=lat); |
int i=0,y=0,y_v=0,lat,factor_s; double x,rad; System.Drawing.Graphics Desen; Desen = this.CreateGraphics(); System.Drawing.Pen Creion_r; Creion_r=new System.Drawing.Pen(System.Drawing.Color.Red); System.Drawing.Pen Creion_g; Creion_g=new System.Drawing.Pen(System.Drawing.Color.Yellow); System.Drawing.Pen Creion_a; Creion_a=new System.Drawing.Pen(System.Drawing.Color.Blue); Desen.Clear(this.BackColor); factor_s=this.Height/2-37; rad=System.Convert.ToDouble(this.numericUpDown1.Value); lat=this.Width; i=0; do { x=i*rad*System.Math.PI/(lat-10); y=System.Convert.ToInt16(35+factor_s*(1-System.Math.Sin(x))); Desen.DrawLine(Creion_r, i-1,y_v, i, y); y_v=y; i+=1; } while (i<=lat); i=0; do { x=(i+2*lat/rad/3)*rad*System.Math.PI/(lat-10); y=System.Convert.ToInt16(35+factor_s*(1-System.Math.Sin(x))); Desen.DrawLine(Creion_g, i-1,y_v, i, y); y_v=y; i+=1; } while (i<=lat); i=0; do { x=(i+4*lat/rad/3)*rad*System.Math.PI/(lat-10); y=System.Convert.ToInt16(35+factor_s*(1-System.Math.Sin(x))); Desen.DrawLine(Creion_a, i-1,y_v, i, y); y_v=y; i+=1; } while (i<=lat); |
int i=0,lat,h; float x,ymax,y=0,y_v=0,k; System.Drawing.Graphics Desen; Desen = this.CreateGraphics(); System.Drawing.Pen Creion_gri_d; Creion_gri_d=new System.Drawing.Pen(System.Drawing.Color.LightGray); System.Drawing.Pen Creion_gri; Creion_gri=new System.Drawing.Pen(System.Drawing.Color.Gray); Desen.Clear(this.BackColor); System.Drawing.Pen Creion_rosu; Creion_rosu=new System.Drawing.Pen(System.Drawing.Color.Red); //Grid // linii verticale for (i=0; i <=this.Width; i+=10){ if (i%50==0) Desen.DrawLine(Creion_gri, i, 0, i,this.Height); else Desen.DrawLine(Creion_gri_d, i, 0, i,this.Height); } // linii orizontale for (i=0; i <=this.Height; i+=10){ if (i%50==0) Desen.DrawLine(Creion_gri, 0, i,this.Width,i); else Desen.DrawLine(Creion_gri_d, 0, i,this.Width,i); } // Trasare grafic x*x h=this.Height-50; i=0; lat=this.Width-20; ymax=(lat/2)*(lat/2); // ymax pe intervalul -lat/2... lat/2 este (lat/2)^2 k=h/ymax; // factorul de scala for(x=-lat/2; x <=lat/2; x++) { y=h-k*x*x; // y=k*x^2 Desen.DrawLine(Creion_rosu, i-1,y_v, i, y); y_v=y; i+=1; } |
float w_r=2,w_a=5; System.Drawing.Graphics Desen; Desen = this.CreateGraphics(); System.Drawing.Pen Creion_rosu; Creion_rosu=new System.Drawing.Pen(System.Drawing.Color.Red,w_r); System.Drawing.Pen Creion_albastru; Creion_albastru=new System.Drawing.Pen(System.Drawing.Color.Blue,w_a); System.Random n = new System.Random(); Desen.Clear(this.BackColor); Desen.DrawLine( Creion_rosu,7,0,7,this.Height-40); Desen.DrawLine( Creion_rosu,6,this.Height-40,this.Width-20,this.Height-40); for ( int i=14; i<=this.Width-20; i+=10){ Desen.DrawLine( Creion_albastru,i,this.Height-40,i,n.Next(this.Height-50)); } |
double t=0; int x_v,y_v,x,y,x0,y0; System.Drawing.Graphics Desen; Desen = this.CreateGraphics(); System.Drawing.Pen Creion_albastru = new System.Drawing.Pen(System.Drawing.Color.Blue); Desen.Clear(this.BackColor); x0=(this.Width-50)/2; y0=(this.Height-50)/2; x_v=System.Convert.ToInt16(x0+x0*System.Math.Cos(3*t)*System.Math.Cos(t)); y_v=System.Convert.ToInt16(y0+y0*System.Math.Cos(3*t)*System.Math.Sin(t)); do { x=System.Convert.ToInt16(x0+x0*System.Math.Cos(3*t)*System.Math.Cos(t)); y=System.Convert.ToInt16(y0+y0*System.Math.Cos(3*t)*System.Math.Sin(t)); Desen.DrawLine(Creion_albastru, x_v, y_v, x, y); x_v=x; y_v=y; t+=0.001; } while (t<=6.3); |
double t=0,n; int x_v,y_v,x,y,x0,y0; System.Drawing.Graphics Desen; Desen = this.CreateGraphics(); System.Drawing.Pen Creion_albastru =new System.Drawing.Pen(System.Drawing.Color.Blue); Desen.Clear(this.BackColor); x0=(this.Width-50)/2; y0=(this.Height-50)/2; n=System.Convert.ToDouble(this.numericUpDown1.Value); x_v=System.Convert.ToInt16(x0+x0*System.Math.Cos(n*t)*System.Math.Cos(t)); y_v=System.Convert.ToInt16(y0+y0*System.Math.Cos(n*t)*System.Math.Sin(t)); do { x=System.Convert.ToInt16(x0+x0*System.Math.Cos(n*t)*System.Math.Cos(t)); y=System.Convert.ToInt16(y0+y0*System.Math.Cos(n*t)*System.Math.Sin(t)); Desen.DrawLine(Creion_albastru, x_v, y_v, x, y); x_v=x; y_v=y; t+=0.001; } while (t<=6.3); |
double t=0; int x_v,y_v,x,y,x0,y0; System.Drawing.Graphics Desen; Desen = this.CreateGraphics(); System.Drawing.Pen Creion_albastru =new System.Drawing.Pen(System.Drawing.Color.Blue); Desen.Clear(this.BackColor); x0=(this.Width-10)/2; y0=(this.Height-50)/2; x_v=System.Convert.ToInt16(x0+x0*t/30*System.Math.Cos(t)); y_v=System.Convert.ToInt16(y0+10+y0*t/30*System.Math.Sin(t)); for (t=0; t<=8*System.Math.PI; t+=0.001){ x=System.Convert.ToInt16(x0+x0*t/30*System.Math.Cos(t)); y=System.Convert.ToInt16(y0+10+y0*t/30*System.Math.Sin(t)); Desen.DrawLine(Creion_albastru, x_v, y_v, x, y); x_v=x; y_v=y; } |
double t=0,n; int x_v,y_v,x,y,x0,y0; System.Drawing.Graphics Desen; Desen = this.CreateGraphics(); System.Drawing::Pen Creion_rosu =new System.Drawing.Pen(System.Drawing.Color.Red); Desen.Clear(this.BackColor); x0=(this.Width-10)/2; y0=(this.Height-50)/2; n=System.Convert.ToDouble(this.numericUpDown1.Value); x_v=System.Convert.ToInt16(x0+x0*t/30*System.Math.Cos(t)); y_v=System.Convert.ToInt16(y0+10+y0*t/30*System.Math.Sin(t)); for (t=0; t<=n*System.Math.PI; t+=0.001){ x=System.Convert.ToInt16(x0+x0*t/30*System.Math.Cos(t)); y=System.Convert.ToInt16(y0+10+y0*t/30*System.Math.Sin(t)); Desen.DrawLine(Creion_rosu, x_v, y_v, x, y); x_v=x; y_v=y; } |
namespace miscare_01 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } System.Drawing.Graphics Desen; System.Drawing.Pen Creion_a, Creion_r, Creion_gr; int i,x0, y0, w, h, nc,lp,nl; private void Form1_Paint(object sender, PaintEventArgs e) { x0 = 70; y0 = 20; w = 200; h = 200; i = 0; nc = 20; // numarul de coloane lp = w / nc;// latimea unui patratel nl = h / lp;// numarul de linii Desen = this.CreateGraphics(); Creion_a = new System.Drawing.Pen(System.Drawing.Color.Blue); Creion_r = new System.Drawing.Pen(System.Drawing.Color.Red); Creion_gr = new System.Drawing.Pen(System.Drawing.Color.LightGray); this.trackBar1.Maximum = w-lp; this.trackBar2.Maximum = h-lp; } private void timer1_Tick(object sender, EventArgs e) { Desen.Clear(BackColor); // Contur Desen.DrawRectangle(Creion_a, x0 - 1, y0 - 1, w, h); //Grid for (i = 0; i <= nc; i++) { Desen.DrawLine(Creion_gr, x0 + i * lp, y0, x0 + i * lp, y0 + h); } for (i = 0; i <= nl; i++) { Desen.DrawLine(Creion_gr, x0, y0 + i * lp, x0 + w, y0 + i * lp); } Desen.DrawEllipse(Creion_r, x0 + this.trackBar1.Value, y0+h-lp-this.trackBar2.Value, lp, lp); } } } |
namespace miscare_02 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } System.Drawing.Graphics Desen,g; System.Drawing.Bitmap img; System.Drawing.Pen Creion_a, Creion_r, Creion_gr; int i, x0, y0, w, h, nc, lp, nl; private void Form1_Paint(object sender, PaintEventArgs e) { Desen = this.CreateGraphics(); w = this.Width-135 ; h = this.Height-130; i = 0; nc = 20; // numarul de coloane lp = w / nc;// latimea unui patratel nl = h / lp;// numarul de linii x0 = 35; y0 = 5; img = new Bitmap(w+4*lp,h+2*lp); g = Graphics.FromImage(img); Creion_a = new System.Drawing.Pen(System.Drawing.Color.Blue); Creion_r = new System.Drawing.Pen(System.Drawing.Color.Red); Creion_gr = new System.Drawing.Pen(System.Drawing.Color.LightGray); this.trackBar1.Maximum = w - lp; this.trackBar2.Maximum = h - lp; } private void timer1_Tick(object sender, EventArgs e) { g.Clear(BackColor); //Grid for (i = 0; i <= nc; i++) { g.DrawLine(Creion_gr, x0 + i * lp, y0, x0 + i * lp, y0 + h); } for (i = 0; i <= nl; i++) { g.DrawLine(Creion_gr, x0, y0 + i * lp, x0 + w, y0 + i * lp); } // Contur g.DrawRectangle(Creion_a, x0, y0, w, h); g.DrawEllipse(Creion_r, x0 + this.trackBar1.Value, y0 + h - lp-2 - this.trackBar2.Value, lp, lp); Desen.DrawImage(img, x0, y0); } } } |
System.Drawing.Bitmap img,img1; System.Drawing.Graphics desen,g; int i; private void Form1_Load(object sender, EventArgs e) { img = new Bitmap("instrum.bmp"); img1 = new Bitmap("instrum.bmp"); g = Graphics.FromImage(img); desen = this.CreateGraphics(); g.DrawImage(img, 0, 0); } private void timer1_Tick(object sender, EventArgs e) { i += 1; g.ResetTransform(); g.DrawImage(img1, 0, 0); //imaginea initiala // translatie in centrul imaginii in vederea rotirii g.TranslateTransform(img.Width / 2 , img.Height / 2 ); // rotire g.RotateTransform(i); // revenire la pozitia initiala g.TranslateTransform(-img.Width / 2 , -img.Height / 2 ); // modificarea efectiva a imaginii img g.DrawImage(img, 0, 0); // afisarea pe ecran // desen.DrawImage(img, 0, 0); desen.DrawImage(img1, 0, 0); desen.DrawImage(img, 320, 0); } |
int max_it; //numarul maxim de iteratii int it; //iteratia in_fractal=true; //variabila de tip bool-ean care precizeaza daca setul se afla in fractal for (it=0; it <= max_it ; it++ ) { if((a*a +b*b) >=4){ in_fractal=false; it=max_it; } temp = a*a-b*b + x; b = 2*a*b + y; a=temp; } if(in_fractal) "Deseneaza un pixel colorat"; else "Deseneaza un pixel de culoarea fundalului"; } |
namespace fractal_v0 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { System.Drawing.Graphics Desen; Desen = this.CreateGraphics(); Desen.Clear(this.BackColor); System.Drawing.Pen Creion=new System.Drawing.Pen(System.Drawing.Color.Blue); System.Drawing.Pen Creion_f=new System.Drawing.Pen(this.BackColor); double im_w=400, im_h=300; // latimea si inaltimea imaginii double x, y; //coordonatele curente double x_i=-1.5, y_i=-1; // coordonatele initiale double x_f=1, y_f=1; // coordonatele finale double x0=(x_f-x_i)/im_w; // pasul pe x double y0=(y_f-y_i)/im_h; // pasul pe y double a, b; // a partea reala, b partea imaginara double temp; // necesar pentru calculul Z(n+1) bool in_fractal; // variabila ce indica faptul ca punctul este inauntrul fractalului int i=0,j=0,it; int max_it=25; y=y_i; for ( j=1; j<=im_h; j++) { x=x_i; y+=y0; for ( i=1; i<=im_w; i++) { x+=x0; a=x; b=y; in_fractal=true; for (it=0; it <= max_it ; it++ ) { if((a*a +b*b) >=4){ in_fractal=false; it=max_it; } temp = a*a-b*b + x; b = 2*a*b + y; a=temp; } if(in_fractal) Desen.DrawLine(Creion,i+1,j,i,j); else Desen.DrawLine(Creion_f,i+1,j,i,j); } } } } } |
System.Drawing.Color.FromArgb(r,g,b) |
int r=25*(System.Math.Cos(it)*System.Math.Cos(it)); int g=125*(1-System.Math.Sin(it)); int b=125*(1-System.Math.Cos(it)); |
namespace fractal_v1_1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { System.Drawing.Graphics Desen; Desen = this.CreateGraphics(); double im_w = 400, im_h = 300; // latimea si inaltimea imaginii Desen.Clear(this.BackColor); double x, y; //coordonatele curente double x_i = -2, y_i = -1.3; // coordonatele initiale double x_f = 1, y_f = 1.3; // coordonatele finale double x0 = (x_f - x_i) / im_w; // pasul pe x double y0 = (y_f - y_i) / im_h; // pasul pe y double a=0; // partea reala double b = 0; // partea imaginara double temp; // necesar pentru calculul Z(n+1) int i = 0, j = 0, it; int max_it = 77;// numarul de iteratii y = y_i; for (j = 1; j <= im_h; j++) { x = x_i; y += y0; for (i = 1; i <= im_w; i++) { x += x0; a = x; b = y; for (it = 0; (it <= max_it) && (a * a + b * b <= 4); it++) { temp = a * a - b * b + x; b = 2 * a * b + y; a = temp; } int r = System.Convert.ToInt16( 25 * (System.Math.Cos(it) * System.Math.Cos(it))); int g = System.Convert.ToInt16(125 * (1 - System.Math.Sin(it))); int bl = System.Convert.ToInt16(125 * (1 - System.Math.Cos(it))); System.Drawing.Pen Creion = new System.Drawing.Pen(System.Drawing.Color.FromArgb(r, g, bl)); Desen.DrawLine(Creion, i + 1, j, i, j); } } } } } |
namespace fractal_v1_2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { System.Drawing.Graphics Desen; Desen = this.CreateGraphics(); double im_w = 400, im_h = 300; // latimea si inaltimea imaginii Desen.Clear(this.BackColor); double x, y; //coordonatele curente double x_i = -2, y_i = -1.3; // coordonatele initiale double x_f = 1, y_f = 1.3; // coordonatele finale double x0 = (x_f - x_i) / im_w; // pasul pe x double y0 = (y_f - y_i) / im_h; // pasul pe y double a, b; // a partea reala, b partea imaginara double temp; // necesar pentru calculul Z(n+1) int i = 0, j = 0, it; int max_it = 77;// numarul de iteratii y = y_i; for (j = 1; j <= im_h; j++) { x = x_i; y += y0; for (i = 1; i <= im_w; i++) { x += x0; a = x; b = y; for (it = 0; (it <= max_it) && (a * a + b * b <= 4); it++) { temp = a * a - b * b + x; b = 2 * a * b + y; a = temp; } if (it < 7) { System.Drawing.Pen Creion = new System.Drawing.Pen(System.Drawing.Color.Blue); Desen.DrawLine(Creion, i + 1, j, i, j); } else { int r = System.Convert.ToInt16( 25 * (System.Math.Cos(it) * System.Math.Cos(it))); int g = System.Convert.ToInt16( 125 * (1 - System.Math.Sin(it))); int bl = System.Convert.ToInt16( 125 * (1 - System.Math.Cos(it))); System.Drawing.Pen Creion = new System.Drawing.Pen(System.Drawing.Color.FromArgb(r, g, bl)); Desen.DrawLine(Creion, i + 1, j, i, j); } } } } } } |
System.Drawing.Bitmap Img; Img=new Bitmap(im_w+2, im_h+2, System.Drawing.Imaging.PixelFormat.Format32bppArgb); |
Img.SetPixel(i+1,j+1,System.Drawing.Color.FromArgb(r,g,b)); |
Desen.DrawImage(Img,0,0); |
namespace fractal_v1_3 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { System.Drawing.Graphics Desen; Desen = this.CreateGraphics(); int im_w = 400, im_h = 300; // latimea si inaltimea imaginii System.Drawing.Bitmap Img; Img = new Bitmap(im_w + 2, im_h + 2, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Desen.Clear(this.BackColor); double x, y; //coordonatele curente double x_i = -2, y_i = -1.3; // coordonatele initiale double x_f = 1, y_f = 1.3; // coordonatele finale double x0 = (x_f - x_i) / im_w; // pasul pe x double y0 = (y_f - y_i) / im_h; // pasul pe y double a, b; // a partea reala, b partea imaginara double temp; // necesar pentru calculul Z(n+1) int i = 0, j = 0, it; int max_it = 77;// numarul de iteratii y = y_i; for (j = 1; j <= im_h; j++) { x = x_i; y += y0; for (i = 1; i <= im_w; i++) { x += x0; a = x; b = y; for (it = 0; (it <= max_it) && (a * a + b * b <= 4); it++) { temp = a * a - b * b + x; b = 2 * a * b + y; a = temp; } if (it < 7) { Img.SetPixel(i + 1, j + 1, System.Drawing.Color.Blue); } else { int r = System.Convert.ToInt16( 25 * (System.Math.Cos(it) * System.Math.Cos(it))); int g = System.Convert.ToInt16( 125 * (1 - System.Math.Sin(it))); int bl = System.Convert.ToInt16( 125 * (1 - System.Math.Cos(it))); Img.SetPixel(i + 1, j + 1, System.Drawing.Color.FromArgb(r, g, bl)); } } } Desen.DrawImage(Img, 0, 0); } } } |
namespace fractal_v2_1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { System.Drawing.Graphics Desen; Desen = this.CreateGraphics(); Desen.Clear(this.BackColor); int im_w = 400, im_h = 300; // latimea si inaltimea imaginii System.Drawing.Bitmap Img; Img = new Bitmap(im_w + 2, im_h + 2, System.Drawing.Imaging.PixelFormat.Format32bppArgb); double x, y; //coordonatele curente double x_i, y_i; // coordonatele initiale x_i = System.Convert.ToDouble(this.numericUpDown2.Value); y_i = System.Convert.ToDouble(this.numericUpDown3.Value); double s; //latimea si lungimea fractalului double x0 = (System.Convert.ToDouble(this.numericUpDown4.Value)) / im_w; // pasul pe x double y0 = (System.Convert.ToDouble(this.numericUpDown4.Value)) / im_h;// pasul pe y double a, b; // a partea reala, b partea imaginara double temp; // necesar pentru calculul Z(n+1) int max_it = System.Convert.ToInt16(this.numericUpDown1.Value);// numarul maxim de iteratii y = y_i; int i = 0, j = 0, it; for (j = 1; j <= im_h; j++) { x = x_i; y += y0; for (i = 1; i <= im_w; i++) { it = 1; a = x; b = y; x += x0; while (((a * a + b * b) <= 4) && (it <= max_it)) { temp = a * a - b * b + x; b = 2 * a * b + y; a = temp; it = it + 1; } if (it < 13) { Img.SetPixel(i + 1, j + 1, System.Drawing.Color.Black); } else { int r = System.Convert.ToInt16( 25 * (System.Math.Cos(it) * System.Math.Cos(it))); int g = System.Convert.ToInt16( 125 * (1 - System.Math.Sin(it))); int bl = System.Convert.ToInt16( 125 * (1 - System.Math.Cos(it))); Img.SetPixel(i + 1, j + 1, System.Drawing.Color.FromArgb(r, g, bl)); } } } Desen.DrawImage(Img, 0, 0); } } } |
namespace fractal_v2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { System.Drawing.Graphics Desen; Desen = this.CreateGraphics(); Desen.Clear(this.BackColor); int im_w = 1024, im_h = 700; // latimea si inaltimea imaginii System.Drawing.Bitmap Img; Img = new Bitmap(im_w + 2, im_h + 2, System.Drawing.Imaging.PixelFormat.Format32bppArgb); double x, y; //coordonatele curente double x_i, y_i; // coordonatele initiale x_i = System.Convert.ToDouble(this.numericUpDown2.Value); y_i = System.Convert.ToDouble(this.numericUpDown3.Value); double w = System.Convert.ToDouble(this.numericUpDown4.Value); //latimea fractalului double h = System.Convert.ToDouble(this.numericUpDown5.Value); //inaltimea fractalului double x0 = w / im_w; // pasul pe x double y0 = h / im_h;// pasul pe y double a, b; // a partea reala, b partea imaginara double temp; // necesar pentru calculul Z(n+1) int max_it = System.Convert.ToInt16(this.numericUpDown1.Value);// numarul maxim de iteratii int i, j, it; y = y_i; for (j = 1; j <= im_h; j++) { x = x_i; y += y0; for (i = 1; i <= im_w; i++) { x += x0; it = 1; a = x; b = y; //temp; while (((a * a + b * b) <= 4) && (it <= max_it)) { temp = a * a - b * b + x; b = 2 * a * b + y; it = it + 1; a = temp; } if (it < 15) { Img.SetPixel(i + 1, j + 1, System.Drawing.Color.Black); } else { int r = System.Convert.ToInt16( 25 * (System.Math.Cos(it) * System.Math.Cos(it))); int g = System.Convert.ToInt16( 125 * (1 - System.Math.Sin(it))); int bl = System.Convert.ToInt16( 125 * (1 - System.Math.Cos(it))); Img.SetPixel(i + 1, j + 1, System.Drawing.Color.FromArgb(r, g, bl)); } } } Desen.DrawImage(Img, 0, 0); } } } |
|