diff --git a/Graphics Programs/animated-all-at-once-souleh.cpp b/Graphics Programs/animated-all-at-once-souleh.cpp new file mode 100644 index 0000000..246f3c1 --- /dev/null +++ b/Graphics Programs/animated-all-at-once-souleh.cpp @@ -0,0 +1,41 @@ +#include +#include +using namespace std; + +main() { + int gd = DETECT, gm; + initgraph(&gd, &gm, ""); + + outtextxy(100, 100, "Press any key to continue..."); + getch(); + cleardevice(); + + for(int i = 0, j = 0; j <= 75 || i <= 50; i++, j++) { + if(i <= 50) { + putpixel(100-i, 100, WHITE); + putpixel(50, 100+i, WHITE); + putpixel(50+i, 150, WHITE); + putpixel(100, 150+i, WHITE); + putpixel(100-i, 200, WHITE); + putpixel(150+i, 125, WHITE); + putpixel(200-i, 200, WHITE); + putpixel(250+i, 200, WHITE); + putpixel(350+i, 200, WHITE); + putpixel(450+i, 200, WHITE); + putpixel(450+i, 162, WHITE); + putpixel(450+i, 125, WHITE); + putpixel(550+i, 162, WHITE); + } + putpixel(150, 125+j, WHITE); + putpixel(200, 200-j, WHITE); + putpixel(250, 125+j, WHITE); + putpixel(300, 200-j, WHITE); + putpixel(350, 125+j, WHITE); + putpixel(450, 125+j, WHITE); + putpixel(550, 125+j, WHITE); + putpixel(600, 200-j, WHITE); + + } + getch(); + closegraph(); +} \ No newline at end of file diff --git a/Graphics Programs/animated-all-at-once-souleh.gif b/Graphics Programs/animated-all-at-once-souleh.gif new file mode 100644 index 0000000..7a58c37 Binary files /dev/null and b/Graphics Programs/animated-all-at-once-souleh.gif differ diff --git a/Graphics Programs/animated-bird.cpp b/Graphics Programs/animated-bird.cpp new file mode 100644 index 0000000..c55ae2f --- /dev/null +++ b/Graphics Programs/animated-bird.cpp @@ -0,0 +1,63 @@ +#include +#include +#include + +// Wings +void handDown(int i) { + line(85+i,155,45+i,185); + line(85+i,155,115+i,195); + arc(90+i,130,228,292,70); +} + +void handUp(int i) { + line(85+i,155,125+i,115); + line(85+i,155,55+i,118); + arc(90+i,177,60,122,70); +} + +main() { + int gd=DETECT,gm; + initgraph(&gd,&gm,""); + int i=0; + + int midx = getmaxx()/2; + int midy = getmaxy()/2; + + setcolor(WHITE); + settextstyle(SCRIPT_FONT, HORIZ_DIR, 4); + settextjustify(CENTER_TEXT, CENTER_TEXT); + outtextxy(midx, midy+30, "Press any key to start"); + getch(); + cleardevice(); + + for(i=0;i<400;i++) { + // ================================== Bird ==================================== + //Body + circle(150+i,150,20); + arc(90+i,190,50,145,60); + arc(87+i,117,220,320,60); + + //Beak + line(170+i,147,180+i,153); + line(180+i,153,170+i,156); + //Eye + circle(162+i,150,2); + + //Tail + line(10+i,155,40+i,155); + line(10+i,145,40+i,155); + line(10+i,165,40+i,155); + + // To Move Hands + if(i%2==0) + handUp(i); + else + handDown(i); + + delay(40); + + cleardevice(); + } + getch(); + closegraph(); +} \ No newline at end of file diff --git a/Graphics Programs/animated-bird.gif b/Graphics Programs/animated-bird.gif new file mode 100644 index 0000000..785763c Binary files /dev/null and b/Graphics Programs/animated-bird.gif differ diff --git a/Graphics Programs/animated-car.cpp b/Graphics Programs/animated-car.cpp new file mode 100644 index 0000000..1351c14 --- /dev/null +++ b/Graphics Programs/animated-car.cpp @@ -0,0 +1,61 @@ +#include +#include +#include +#include +using namespace std; + +main() { + int gm=DETECT,gd,i; + initgraph(&gm,&gd,""); + + int midx = getmaxx()/2; + int midy = getmaxy()/2; + + setcolor(WHITE); + settextstyle(SCRIPT_FONT, HORIZ_DIR, 4); + settextjustify(CENTER_TEXT, CENTER_TEXT); + outtextxy(midx, midy+30, "Press any key to start"); + getch(); + cleardevice(); + + for(i=0;i<=500;i++) { + // Road + line(0,322,700,322); + + // Car Body + line(0+i,300,13+i,298); + line(13+i,298,30+i,280); + line(30+i,280,80+i,280); + line(80+i,280,97+i,298); + line(97+i,298,120+i,300); + line(0+i,300,0+i,315); + line(0+i,315,25+i,315); + arc(35+i,315,0,180,9); + line(45+i,315,67+i,315); + arc(77+i,315,0,180,9); + line(85+i,315,120+i,315); + line(120+i,300,120+i,315); + + // First Window + line(32+i,285,50+i,285); + line(50+i,285,50+i,295); + line(50+i,295,23+i,295); + line(32+i,285,23+i,295); + + // Second Window + line(60+i,285,78+i,285); + line(60+i,285,60+i,295); + line(60+i,295,85+i,295); + line(78+i,285,85+i,295); + + // Wheels + circle(35+i,315,6); + circle(77+i,315,6); + + delay(30); + + cleardevice(); + } + getch(); + closegraph(); +} \ No newline at end of file diff --git a/Graphics Programs/animated-car.gif b/Graphics Programs/animated-car.gif new file mode 100644 index 0000000..83d8912 Binary files /dev/null and b/Graphics Programs/animated-car.gif differ diff --git a/Graphics Programs/animated-fish-tank.cpp b/Graphics Programs/animated-fish-tank.cpp new file mode 100644 index 0000000..75729c4 --- /dev/null +++ b/Graphics Programs/animated-fish-tank.cpp @@ -0,0 +1,103 @@ +#include +#include +#include +#include +using namespace std; + +void oxygen_bubbles(int i,int y) { + if(y<100) { + // Second Bubble + y=y+200; + if(y>200) { + circle(100,y+110-i,5); + } + } + else { + //First Bubble + circle(100,y+110-i,5); + } +} + +main() { + int gd = DETECT , gm ; + initgraph(&gd,&gm,""); + int i,y=200; + + int midx = getmaxx()/2; + int midy = getmaxy()/2; + + setcolor(WHITE); + settextstyle(SCRIPT_FONT, HORIZ_DIR, 4); + settextjustify(CENTER_TEXT, CENTER_TEXT); + outtextxy(midx, midy+30, "Press any key to start"); + getch(); + cleardevice(); + for(i=0;i<300;i++) { + //Fish 1 + line(150+i,250,190+i,290); + line(150+i,250,90+i,310); + line(90+i,270,150+i,330); + line(190+i,290,150+i,330); + line(90+i,310,90+i,270); + circle(170+i,290,3); + + //Fish 2 + arc(400-i,150,50,320,30); + line(420-i,128,450-i,160); + line(420-i,173,450-i,130); + line(450-i,160,450-i,130); + circle(380-i,150,3); + arc(380-i,150,270,90,20); + + //Oxygen Tank + line(50,300,80,300); + line(80,300,80,370); + line(50,370,80,370); + line(80,305,90,305); + line(80,310,90,310); + line(90,305,90,310); + + oxygen_bubbles(i,y); + y--; + //-------------------------------- Fish Tank body --------------------------- + //Roof + line(50,10,550,10); + line(50,10,10,100); + line(550,10,590,100); + line(10,100,590,100); + + //Border of tank + line(50,100,50,400); + line(550,100,550,400); + line(50,400,550,400); + + //Stones + ellipse(100,390,0,360,20,10); + ellipse(125,370,0,360,25,10); + ellipse(150,390,0,360,25,10); + ellipse(170,375,0,360,15,5); + circle(180,390,10); + ellipse(200,380,0,360,10,15); + circle(220,390,10); + ellipse(250,380,0,360,20,15); + + ellipse(290,390,0,360,20,10); + ellipse(315,370,0,360,25,10); + ellipse(340,390,0,360,25,10); + ellipse(360,375,0,360,15,5); + circle(370,390,10); + ellipse(390,380,0,360,10,15); + circle(410,390,10); + ellipse(440,380,0,360,20,15); + + ellipse(480,390,0,360,20,10); + ellipse(505,370,0,360,25,10); + ellipse(530,390,0,360,21,10); + + delay(50); + + cleardevice(); + } + getch(); + closegraph(); +} \ No newline at end of file diff --git a/Graphics Programs/animated-fish-tank.gif b/Graphics Programs/animated-fish-tank.gif new file mode 100644 index 0000000..0c59305 Binary files /dev/null and b/Graphics Programs/animated-fish-tank.gif differ diff --git a/Graphics Programs/animated-kite.cpp b/Graphics Programs/animated-kite.cpp new file mode 100644 index 0000000..830551e --- /dev/null +++ b/Graphics Programs/animated-kite.cpp @@ -0,0 +1,104 @@ +#include +#include +#include +#include + +void kite(int i) { + int x[4], y[4]; + double t; + /*================================= Kite ==================================*/ + line(150+i,100+i,100+i,160+i); + line(150+i,100+i,200+i,160+i); + + line(100+i,160+i,150+i,210+i); + line(200+i,160+i,150+i,210+i); + + line(150+i,210+i,130+i,230+i); + line(150+i,210+i,170+i,230+i); + line(130+i,230+i,170+i,230+i); + + line(150+i,100+i,150+i,210+i); + line(100+i,160+i,200+i,160+i); + + /*================================= Kite Thread ==================================*/ + x[0]=150+i; + y[0]=210+i; + x[1]=200+i; + y[1]=250+i; + x[2]=250+i; + y[2]=130+i; + x[3]=500+i; + y[3]=500+i; + for (t = 0.0; t < 1.0; t += 0.0005) { + double xt = pow (1-t, 3) * x[0] + 3 * t * pow (1-t, 2) * x[1] + + 3 * pow (t, 2) * (1-t) * x[2] + pow (t, 3) * x[3]; + + double yt = pow (1-t, 3) * y[0] + 3 * t * pow (1-t, 2) * y[1] + + 3 * pow (t, 2) * (1-t) * y[2] + pow (t, 3) * y[3]; + + putpixel (xt, yt, WHITE); + } +} +/*================================= Clouds ==================================*/ +void clouds() { + //================================ Middle cloud=============================== + ellipse(200,30,60,240,10,15); + ellipse(225,20,345,165,20,15); + ellipse(262,27,340,160,20,15); + ellipse(268,42,230,50,20,10); + ellipse(226,46,163,340,31,15); + ellipse(300,21,20,182,21,19); + ellipse(325,31,290,100,21,15); + ellipse(299,45,228,20,33,11); + + //============================== Left Cloud ================================== + ellipse(40,30,60,240,10,15); + ellipse(65,20,345,165,20,15); + ellipse(105,27,340,160,20,15); + ellipse(109,42,230,50,20,10); + ellipse(66,46,163,340,31,17); + + //============================== Right Cloud ================================== + ellipse(450,30,60,240,10,15); + ellipse(475,20,345,165,20,15); + ellipse(512,27,340,160,20,15); + ellipse(518,42,230,50,20,10); + ellipse(476,46,163,340,31,15); +} + +main() { + int gm,gd=DETECT; + initgraph(&gd,&gm,""); + int midx = getmaxx()/2; + int midy = getmaxy()/2; + + setcolor(WHITE); + settextstyle(SCRIPT_FONT, HORIZ_DIR, 4); + settextjustify(CENTER_TEXT, CENTER_TEXT); + outtextxy(midx, midy+30, "Press any key to start"); + getch(); + cleardevice(); + for(int k=1;k<=2;k++) { + for(int i=0;i<61;i++) { + kite(i); + clouds(); + + if(i>=60) { + for(int j=0;j<60;j++) { + int l=i-j; + kite(l); + clouds(); + + delay(40); + + cleardevice(); + } + } + delay(40); + + cleardevice(); + } + } + getch(); + closegraph(); +} \ No newline at end of file diff --git a/Graphics Programs/animated-kite.gif b/Graphics Programs/animated-kite.gif new file mode 100644 index 0000000..185a9d5 Binary files /dev/null and b/Graphics Programs/animated-kite.gif differ diff --git a/Graphics Programs/animated-letter-souleh.cpp b/Graphics Programs/animated-letter-souleh.cpp new file mode 100644 index 0000000..e00d422 --- /dev/null +++ b/Graphics Programs/animated-letter-souleh.cpp @@ -0,0 +1,76 @@ +#include +#include +using namespace std; + +main() { + int gd = DETECT, gm; + initgraph(&gd, &gm, ""); + + outtextxy(100, 100, "Press any key to continue..."); + getch(); + cleardevice(); + + // S letter + for(int i = 0; i <= 50; i++) { + putpixel(100-i, 100, WHITE); + putpixel(50, 100+i, WHITE); + putpixel(50+i, 150, WHITE); + putpixel(100, 150+i, WHITE); + putpixel(100-i, 200, WHITE); + + } + + // O letter + for(int i = 0, j = 0; j <= 75 || i <= 50; i++, j++) { + if(i <= 50) { + putpixel(150+i, 125, WHITE); + putpixel(200-i, 200, WHITE); + } + putpixel(150, 125+j, WHITE); + putpixel(200, 200-j, WHITE); + + } + + // U letter + for(int i = 0, j = 0; j <= 75 || i <= 50; i++, j++) { + if(i <= 50) { + putpixel(250+i, 200, WHITE); + } + putpixel(250, 125+j, WHITE); + putpixel(300, 200-j, WHITE); + + } + + // L letter + for(int i = 0, j = 0; j <= 75 || i <= 50; i++, j++) { + if(i <= 50) { + putpixel(350+i, 200, WHITE); + } + putpixel(350, 125+j, WHITE); + + } + + // E letter + for(int i = 0, j = 0; j <= 75 || i <= 50; i++, j++) { + if(i <= 50) { + putpixel(450+i, 200, WHITE); + putpixel(450+i, 162, WHITE); + putpixel(450+i, 125, WHITE); + } + putpixel(450, 125+j, WHITE); + + } + + // H letter + for(int i = 0, j = 0; j <= 75 || i <= 50; i++, j++) { + if(i <= 50) { + putpixel(550+i, 162, WHITE); + } + putpixel(550, 125+j, WHITE); + putpixel(600, 200-j, WHITE); + + } + + getch(); + closegraph(); +} \ No newline at end of file diff --git a/Graphics Programs/animated-letter-souleh.gif b/Graphics Programs/animated-letter-souleh.gif new file mode 100644 index 0000000..faebaa3 Binary files /dev/null and b/Graphics Programs/animated-letter-souleh.gif differ diff --git a/Graphics Programs/bar.PNG b/Graphics Programs/bar.PNG new file mode 100644 index 0000000..69e9cf2 Binary files /dev/null and b/Graphics Programs/bar.PNG differ diff --git a/Graphics Programs/bar.cpp b/Graphics Programs/bar.cpp new file mode 100644 index 0000000..7bfb7d1 --- /dev/null +++ b/Graphics Programs/bar.cpp @@ -0,0 +1,21 @@ +#include +int main() +{ + int gd = DETECT, gm; + initgraph(&gd, &gm, ""); + int left, top, right, bottom; + + bar(left = 150, top = 150, right = 190, bottom = 350); + + bar(left = 220, top = 250, right = 260, bottom = 350); + + bar(left = 290, top = 200, right = 330, bottom = 350); + + line(100, 50, 100, 350); + + line(100, 350, 400, 350); + + getch(); + closegraph(); + return 0; +} \ No newline at end of file diff --git a/Graphics Programs/bar3d.PNG b/Graphics Programs/bar3d.PNG new file mode 100644 index 0000000..55eaeda Binary files /dev/null and b/Graphics Programs/bar3d.PNG differ diff --git a/Graphics Programs/bar3d.cpp b/Graphics Programs/bar3d.cpp new file mode 100644 index 0000000..7f36eff --- /dev/null +++ b/Graphics Programs/bar3d.cpp @@ -0,0 +1,21 @@ +#include +int main() +{ + int gd = DETECT, gm; + initgraph(&gd, &gm, ""); + int left, top, right, bottom, depth, topflag; + + bar3d(left = 150, top = 250, right = 190, bottom = 350, depth = 20, topflag = 1); + + bar3d(left = 220, top = 150, right = 260, bottom = 350, depth = 20, topflag = 0); + + bar3d(left = 290, top = 200, right = 330, bottom = 350, depth = 20, topflag = 1); + + line(100, 50, 100, 350); + + line(100, 350, 400, 350); + + getch(); + closegraph(); + return 0; +} \ No newline at end of file diff --git a/Graphics Programs/boundary-filling-algorithm.PNG b/Graphics Programs/boundary-filling-algorithm.PNG new file mode 100644 index 0000000..e355fd8 Binary files /dev/null and b/Graphics Programs/boundary-filling-algorithm.PNG differ diff --git a/Graphics Programs/boundary-filling-algorithm.cpp b/Graphics Programs/boundary-filling-algorithm.cpp new file mode 100644 index 0000000..0feffbd --- /dev/null +++ b/Graphics Programs/boundary-filling-algorithm.cpp @@ -0,0 +1,28 @@ +#include + +void boundaryFill4(int x, int y, int fill_color,int boundary_color) +{ + if(getpixel(x, y) != boundary_color && getpixel(x, y) != fill_color) + { + putpixel(x, y, fill_color); + boundaryFill4(x + 1, y, fill_color, boundary_color); + boundaryFill4(x, y + 1, fill_color, boundary_color); + boundaryFill4(x - 1, y, fill_color, boundary_color); + boundaryFill4(x, y - 1, fill_color, boundary_color); + } +} + +int main() +{ + int gd = DETECT, gm; + initgraph(&gd, &gm, ""); + int x = 250, y = 200, radius = 50; + + circle(x, y, radius); + + boundaryFill4(x, y, 6, 15); + + getch(); + closegraph(); + return 0; +} \ No newline at end of file diff --git a/Graphics Programs/bresenham-line-generation-algorithm.PNG b/Graphics Programs/bresenham-line-generation-algorithm.PNG new file mode 100644 index 0000000..ce8eb9e Binary files /dev/null and b/Graphics Programs/bresenham-line-generation-algorithm.PNG differ diff --git a/Graphics Programs/bresenham-line-generation-algorithm.cpp b/Graphics Programs/bresenham-line-generation-algorithm.cpp new file mode 100644 index 0000000..7df4321 --- /dev/null +++ b/Graphics Programs/bresenham-line-generation-algorithm.cpp @@ -0,0 +1,36 @@ +#include +#include +using namespace std; + +void bresenham(int x1, int y1, int x2, int y2) +{ + int m_new = 2 * (y2 - y1); + int slope_error_new = m_new - (x2 - x1); + for (int x = x1, y = y1; x <= x2; x++) + { + putpixel(x, y, WHITE); + delay(30); + slope_error_new += m_new; + if (slope_error_new >= 0) + { + y++; + slope_error_new -= 2 * (x2 - x1); + } + } +} + +int main() +{ + int gd = DETECT, gm; + initgraph (&gd, &gm, ""); + + int x1 = 20, y1 = 20, x2 = 250, y2 = 250; + bresenham(x1, y1, x2, y2); + + x1 = 80, y1 = 20, x2 = 310, y2 = 300; + bresenham(x1, y1, x2, y2); + + getch(); + closegraph(); + return 0; +} \ No newline at end of file diff --git a/Graphics Programs/capacitor.cpp b/Graphics Programs/capacitor.cpp new file mode 100644 index 0000000..43986bf --- /dev/null +++ b/Graphics Programs/capacitor.cpp @@ -0,0 +1,16 @@ +#include + +int main() { + int gd = DETECT, gm; + initgraph(&gd, &gm, ""); + + outtextxy(110, 60, "C"); + + line(80, 100, 100, 100); + line(100, 80, 100, 120); + line(120, 80, 120, 120); + line(120, 100, 140, 100); + + getch(); + closegraph(); +} \ No newline at end of file diff --git a/Graphics Programs/capacitor.png b/Graphics Programs/capacitor.png new file mode 100644 index 0000000..a99a266 Binary files /dev/null and b/Graphics Programs/capacitor.png differ diff --git a/Graphics Programs/circle.PNG b/Graphics Programs/circle.PNG new file mode 100644 index 0000000..bacbfb1 Binary files /dev/null and b/Graphics Programs/circle.PNG differ diff --git a/Graphics Programs/circle.cpp b/Graphics Programs/circle.cpp new file mode 100644 index 0000000..8c39143 --- /dev/null +++ b/Graphics Programs/circle.cpp @@ -0,0 +1,13 @@ +#include + +int main() +{ + int gd = DETECT, gm; + initgraph(&gd, &gm, ""); + + circle(250, 200, 50); + + getch(); + closegraph(); + return 0; +} \ No newline at end of file diff --git a/Graphics Programs/color-bar-chart.PNG b/Graphics Programs/color-bar-chart.PNG new file mode 100644 index 0000000..20c713f Binary files /dev/null and b/Graphics Programs/color-bar-chart.PNG differ diff --git a/Graphics Programs/color-bar-chart.cpp b/Graphics Programs/color-bar-chart.cpp new file mode 100644 index 0000000..5076c5c --- /dev/null +++ b/Graphics Programs/color-bar-chart.cpp @@ -0,0 +1,46 @@ +#include + +int main() +{ + int gd = DETECT, gm; + initgraph(&gd, &gm, ""); + + setcolor(YELLOW); + rectangle(0,30,639,450); + settextstyle(SANS_SERIF_FONT,HORIZ_DIR, 2); + setcolor(WHITE); + outtextxy(275,0,"Bar Chart"); + + setlinestyle(SOLID_LINE,0,2); + + line(100,420,100,60); + line(100,420,600,420); + line(90,70,100,60); + line(110,70,100,60); + line(590,410,600,420); + line(590,430,600,420); + + outtextxy(95,35,"Y"); + outtextxy(610,405,"X"); + outtextxy(85,415,"O"); + + setfillstyle(LINE_FILL,BLUE); + bar(150,100,200,419); + + setfillstyle(XHATCH_FILL,RED); + bar(225,150,275,419); + + setfillstyle(WIDE_DOT_FILL,GREEN); + bar(300,200,350,419); + + setfillstyle(INTERLEAVE_FILL,MAGENTA); + bar(375,125,425,419); + + setfillstyle(HATCH_FILL,BROWN); + bar(450,175,500,419); + + + getch(); + closegraph(); + return 0; +} \ No newline at end of file diff --git a/Graphics Programs/dda-line-generation-algorithm.PNG b/Graphics Programs/dda-line-generation-algorithm.PNG new file mode 100644 index 0000000..48f57e3 Binary files /dev/null and b/Graphics Programs/dda-line-generation-algorithm.PNG differ diff --git a/Graphics Programs/dda-line-generation-algorithm.cpp b/Graphics Programs/dda-line-generation-algorithm.cpp new file mode 100644 index 0000000..b7754a5 --- /dev/null +++ b/Graphics Programs/dda-line-generation-algorithm.cpp @@ -0,0 +1,43 @@ +#include + +int abs (int n) +{ + return ( (n>0) ? n : ( n * (-1))); +} + +void DDA(int X0, int Y0, int X1, int Y1) +{ + int dx = X1 - X0; + int dy = Y1 - Y0; + + int steps = abs(dx) > abs(dy) ? abs(dx) : abs(dy); + + float Xinc = dx / (float) steps; + float Yinc = dy / (float) steps; + + float X = X0; + float Y = Y0; + for (int i = 0; i <= steps; i++) + { + putpixel (X,Y,WHITE); + X += Xinc; + Y += Yinc; + delay(30); + } +} + +int main() +{ + int gd = DETECT, gm; + initgraph (&gd, &gm, ""); + + int X0 = 20, Y0 = 20, X1 = 250, Y1 = 250; + DDA(X0, Y0, X1, Y1); + + X0 = 250, Y0 = 20, X1 = 20, Y1 = 250; + DDA(X0, Y0, X1, Y1); + + getch(); + closegraph(); + return 0; +} \ No newline at end of file diff --git a/Graphics Programs/ellipse.PNG b/Graphics Programs/ellipse.PNG new file mode 100644 index 0000000..c038357 Binary files /dev/null and b/Graphics Programs/ellipse.PNG differ diff --git a/Graphics Programs/ellipse.cpp b/Graphics Programs/ellipse.cpp new file mode 100644 index 0000000..e55897d --- /dev/null +++ b/Graphics Programs/ellipse.cpp @@ -0,0 +1,18 @@ +#include + +int main() +{ + int gd = DETECT, gm; + int x = 250, y = 200; + int start_angle = 0; + int end_angle = 360; + int x_rad = 100; + int y_rad = 50; + initgraph(&gd, &gm, ""); + + ellipse(x, y, start_angle, end_angle, x_rad, y_rad); + + getch(); + closegraph(); + return 0; +} \ No newline at end of file diff --git a/Graphics Programs/floodfill-in-rectangle.PNG b/Graphics Programs/floodfill-in-rectangle.PNG new file mode 100644 index 0000000..59fd651 Binary files /dev/null and b/Graphics Programs/floodfill-in-rectangle.PNG differ diff --git a/Graphics Programs/floodfill-in-rectangle.cpp b/Graphics Programs/floodfill-in-rectangle.cpp new file mode 100644 index 0000000..b44fd2c --- /dev/null +++ b/Graphics Programs/floodfill-in-rectangle.cpp @@ -0,0 +1,34 @@ +#include + +void flood(int x, int y, int new_col, int old_col) +{ + if (getpixel(x, y) == old_col) { + putpixel(x, y, new_col); + flood(x + 1, y, new_col, old_col); + flood(x - 1, y, new_col, old_col); + flood(x, y + 1, new_col, old_col); + flood(x, y - 1, new_col, old_col); + } +} + +int main() +{ + int gd, gm = DETECT; + initgraph(&gd, &gm, ""); + + int top, left, bottom, right; + top = left = 50; + bottom = right = 300; + + rectangle(left, top, right, bottom); + + int x = 51, y = 51; + int newcolor = 12; + int oldcolor = 0; + + flood(x, y, newcolor, oldcolor); + + getch(); + closegraph(); + return 0; +} \ No newline at end of file diff --git a/Graphics Programs/hello-world.cpp b/Graphics Programs/hello-world.cpp new file mode 100644 index 0000000..7f9b8df --- /dev/null +++ b/Graphics Programs/hello-world.cpp @@ -0,0 +1,13 @@ +#include + +int main(void) { + int gdriver = DETECT, gmode; + int x = 130, y = 150; + initgraph(&gdriver, &gmode, ""); + + settextstyle(9, 0, 5); + outtextxy(x, y, "Hello World"); + getch(); + closegraph(); + return 0; +} \ No newline at end of file diff --git a/Graphics Programs/hello-world.png b/Graphics Programs/hello-world.png new file mode 100644 index 0000000..b0071a4 Binary files /dev/null and b/Graphics Programs/hello-world.png differ diff --git a/Graphics Programs/inductive-coil.cpp b/Graphics Programs/inductive-coil.cpp new file mode 100644 index 0000000..4167aff --- /dev/null +++ b/Graphics Programs/inductive-coil.cpp @@ -0,0 +1,24 @@ +#include + +int main() { + + int gd = DETECT, gm; + initgraph(&gd, &gm, ""); + + line(100, 200, 150, 200); + + arc(200, 200, 0, 180, 50); + arc(260, 200, 0, 180, 50); + arc(230, 200, 180, 360, 20); + + arc(320, 200, 0, 180, 50); + arc(290, 200, 180, 360, 20); + + arc(380, 200, 0, 180, 50); + arc(350, 200, 180, 360, 20); + + line(430, 200, 470, 200); + + getch(); + closegraph(); +} \ No newline at end of file diff --git a/Graphics Programs/inductive-coil.png b/Graphics Programs/inductive-coil.png new file mode 100644 index 0000000..647c913 Binary files /dev/null and b/Graphics Programs/inductive-coil.png differ diff --git a/Graphics Programs/mid-point-ellipse-algorithm.PNG b/Graphics Programs/mid-point-ellipse-algorithm.PNG new file mode 100644 index 0000000..b3abc2c Binary files /dev/null and b/Graphics Programs/mid-point-ellipse-algorithm.PNG differ diff --git a/Graphics Programs/mid-point-ellipse-algorithm.cpp b/Graphics Programs/mid-point-ellipse-algorithm.cpp new file mode 100644 index 0000000..d40e846 --- /dev/null +++ b/Graphics Programs/mid-point-ellipse-algorithm.cpp @@ -0,0 +1,80 @@ +#include +using namespace std; + +void midptellipse(int rx, int ry, int xc, int yc, int color) +{ + float dx, dy, d1, d2, x, y; + x = 0; + y = ry; + + d1 = (ry * ry) - (rx * rx * ry) + (0.25 * rx * rx); + dx = 2 * ry * ry * x; + dy = 2 * rx * rx * y; + + while (dx < dy) + { + putpixel(x + xc, y + yc, color); + putpixel(-x + xc, y + yc, color); + putpixel(x + xc, -y + yc, color); + putpixel(-x + xc, -y + yc, color); + + if (d1 < 0) + { + x++; + dx = dx + (2 * ry * ry); + d1 = d1 + dx + (ry * ry); + } + else + { + x++; + y--; + dx = dx + (2 * ry * ry); + dy = dy - (2 * rx * rx); + d1 = d1 + dx - dy + (ry * ry); + } + } + + d2 = ((ry * ry) * ((x + 0.5) * (x + 0.5))) + + ((rx * rx) * ((y - 1) * (y - 1))) - + (rx * rx * ry * ry); + + while (y >= 0) + { + putpixel(x + xc, y + yc, color); + putpixel(-x + xc, y + yc, color); + putpixel(x + xc, -y + yc, color); + putpixel(-x + xc, -y + yc, color); + + if (d2 > 0) + { + y--; + dy = dy - (2 * rx * rx); + d2 = d2 + (rx * rx) - dy; + } + else + { + y--; + x++; + dx = dx + (2 * ry * ry); + dy = dy - (2 * rx * rx); + d2 = d2 + dx - dy + (rx * rx); + } + } +} + +int main() +{ + int gd = DETECT, gm; + initgraph(&gd, &gm, ""); + + outtextxy(100, 100, "Press any key to continue..."); + getch(); + cleardevice(); + + midptellipse(100, 100, 250, 250, WHITE); + midptellipse(100, 100, 250, 250, BLACK); + + getch(); + closegraph(); + return 0; +} \ No newline at end of file diff --git a/Graphics Programs/mid-point-line-generation-algorithm.PNG b/Graphics Programs/mid-point-line-generation-algorithm.PNG new file mode 100644 index 0000000..f1631c3 Binary files /dev/null and b/Graphics Programs/mid-point-line-generation-algorithm.PNG differ diff --git a/Graphics Programs/mid-point-line-generation-algorithm.cpp b/Graphics Programs/mid-point-line-generation-algorithm.cpp new file mode 100644 index 0000000..d063efb --- /dev/null +++ b/Graphics Programs/mid-point-line-generation-algorithm.cpp @@ -0,0 +1,40 @@ +#include +using namespace std; + +void midPoint(int X1, int Y1, int X2, int Y2) +{ + int dx = X2 - X1; + int dy = Y2 - Y1; + + int d = dy - (dx/2); + int x = X1, y = Y1; + + putpixel(x, y, WHITE); + + while (x < X2) + { + x++; + if (d < 0) + d = d + dy; + else + { + d += (dy - dx); + y++; + } + putpixel(x, y, WHITE); + delay(30); + } +} + +int main() +{ + int gd = DETECT, gm; + initgraph (&gd, &gm, ""); + + int X1 = 20, Y1 = 20, X2 = 250, Y2 = 250; + midPoint(X1, Y1, X2, Y2); + + getch(); + closegraph(); + return 0; +} \ No newline at end of file diff --git a/Graphics Programs/npn-transistor.cpp b/Graphics Programs/npn-transistor.cpp new file mode 100644 index 0000000..09481e5 --- /dev/null +++ b/Graphics Programs/npn-transistor.cpp @@ -0,0 +1,18 @@ +#include + +int main() { + int gd = DETECT, gm; + initgraph(&gd, &gm, ""); + + line(100, 100, 100, 200); + line(70, 150, 100, 150); + line(100, 125, 150, 90); + line(100, 175, 150, 210); + line(140, 190, 150, 210); + line(130, 210, 150, 210); + + outtextxy(100, 250, "NPN Transistor"); + + getch(); + closegraph(); +} \ No newline at end of file diff --git a/Graphics Programs/npn-transistor.png b/Graphics Programs/npn-transistor.png new file mode 100644 index 0000000..1a15ca6 Binary files /dev/null and b/Graphics Programs/npn-transistor.png differ diff --git a/Graphics Programs/pnp-transistor.cpp b/Graphics Programs/pnp-transistor.cpp new file mode 100644 index 0000000..f5ecf35 --- /dev/null +++ b/Graphics Programs/pnp-transistor.cpp @@ -0,0 +1,18 @@ +#include + +int main() { + int gd = DETECT, gm; + initgraph(&gd, &gm, ""); + + line(100, 100, 100, 200); + line(70, 150, 100, 150); + line(100, 125, 150, 90); + line(100, 175, 150, 210); + line(100, 175, 110, 200); + line(100, 175, 125, 175); + + outtextxy(200, 150, "PNP Transistor"); + + getch(); + closegraph(); +} \ No newline at end of file diff --git a/Graphics Programs/pnp-transistor.png b/Graphics Programs/pnp-transistor.png new file mode 100644 index 0000000..5d3a2cd Binary files /dev/null and b/Graphics Programs/pnp-transistor.png differ diff --git a/Graphics Programs/rainbow.cpp b/Graphics Programs/rainbow.cpp new file mode 100644 index 0000000..af44471 --- /dev/null +++ b/Graphics Programs/rainbow.cpp @@ -0,0 +1,24 @@ +#include +int main() +{ + int gdriver = DETECT,gmode; + int x, y, i; + initgraph(&gdriver,&gmode,""); + + outtextxy(100, 100, "Press any key to continue..."); + getch(); + cleardevice(); + + x = getmaxx() / 2; + y = getmaxy() / 2; + + for (i=30; i<200; i++) + { + + setcolor(i/10); + arc(x, y, 0, 180, i-10); + } + getch(); + closegraph(); + return 0; +} \ No newline at end of file diff --git a/Graphics Programs/rainbow.gif b/Graphics Programs/rainbow.gif new file mode 100644 index 0000000..b26c5e8 Binary files /dev/null and b/Graphics Programs/rainbow.gif differ diff --git a/Graphics Programs/rectangle.PNG b/Graphics Programs/rectangle.PNG new file mode 100644 index 0000000..810bc99 Binary files /dev/null and b/Graphics Programs/rectangle.PNG differ diff --git a/Graphics Programs/rectangle.cpp b/Graphics Programs/rectangle.cpp new file mode 100644 index 0000000..a912207 --- /dev/null +++ b/Graphics Programs/rectangle.cpp @@ -0,0 +1,15 @@ +#include + +int main() +{ + int gd = DETECT, gm; + int left = 150, top = 150; + int right = 450, bottom = 450; + initgraph(&gd, &gm, ""); + + rectangle(left, top, right, bottom); + + getch(); + closegraph(); + return 0; +} \ No newline at end of file diff --git a/Graphics Programs/resistance-diagram.cpp b/Graphics Programs/resistance-diagram.cpp new file mode 100644 index 0000000..7def35e --- /dev/null +++ b/Graphics Programs/resistance-diagram.cpp @@ -0,0 +1,19 @@ +#include + +int main() { + int gd = DETECT, gm; + initgraph(&gd, &gm, ""); + + line(90, 100, 100, 100); + line(100, 100, 110, 120); + line(110, 120, 120, 100); + line(120, 100, 130, 120); + line(130, 120, 140, 100); + line(140, 100, 150, 120); + line(150, 120, 160, 100); + line(160, 100, 170, 100); + outtextxy(100, 130, "Resisitor"); + + getch(); + closegraph(); +} \ No newline at end of file diff --git a/Graphics Programs/resistance-diagram.png b/Graphics Programs/resistance-diagram.png new file mode 100644 index 0000000..1c61973 Binary files /dev/null and b/Graphics Programs/resistance-diagram.png differ diff --git a/Graphics Programs/shapes.cpp b/Graphics Programs/shapes.cpp new file mode 100644 index 0000000..685a920 --- /dev/null +++ b/Graphics Programs/shapes.cpp @@ -0,0 +1,40 @@ +#include +#include +main() { + int gd=DETECT,gm; + initgraph(&gd,&gm,""); + + // Line Code + line(250,200,350,350); + + // Circle Code + setfillstyle(SOLID_FILL,RED); + circle(140,150,80); + floodfill(141,150,WHITE); + + // Rectangle Code + setfillstyle(SOLID_FILL,BLUE); + line(400,100,600,100); + line(400,100,400,200); + line(400,200,600,200); + line(600,100,600,200); + floodfill(401,110,WHITE); + + // Triangle Code + setfillstyle(SOLID_FILL,YELLOW); + line(140,290,50,450); + line(140,290,230,450); + line(50,450,230,450); + floodfill(141,300,WHITE); + + // Square Code + setfillstyle(SOLID_FILL,MAGENTA); + line(400,300,550,300); + line(400,300,400,450); + line(550,300,550,450); + line(400,450,550,450); + floodfill(401,305,WHITE); + + getch(); + closegraph(); +} \ No newline at end of file diff --git a/Graphics Programs/shapes.png b/Graphics Programs/shapes.png new file mode 100644 index 0000000..a3cbece Binary files /dev/null and b/Graphics Programs/shapes.png differ diff --git a/Graphics Programs/souleh.cpp b/Graphics Programs/souleh.cpp new file mode 100644 index 0000000..f42412c --- /dev/null +++ b/Graphics Programs/souleh.cpp @@ -0,0 +1,44 @@ +#include +#include +using namespace std; + +main() { + int gd = DETECT, gm; + initgraph(&gd, &gm, ""); + + // S letter + line(50, 100, 100, 100); + line(50, 100, 50, 150); + line(50, 150, 100, 150); + line(100, 150, 100, 200); + line(100, 200, 50, 200); + + // O letter + line(150, 125, 200, 125); + line(200, 125, 200, 200); + line(200, 200, 150, 200); + line(150, 200, 150, 125); + + // U letter + line(250, 125, 250, 200); + line(250, 200, 300, 200); + line(300, 200, 300, 125); + + // L letter + line(350, 125, 350, 200); + line(350, 200, 400, 200); + + // E letter + line(450, 125, 450, 200); + line(450, 125, 500, 125); + line(450, 162, 500, 162); + line(450, 200, 500, 200); + + // H letter + line(550, 125, 550, 201); + line(550, 162, 600, 162); + line(600, 125, 600, 201); + + getch(); + closegraph(); +} \ No newline at end of file diff --git a/Graphics Programs/souleh.png b/Graphics Programs/souleh.png new file mode 100644 index 0000000..7b6d813 Binary files /dev/null and b/Graphics Programs/souleh.png differ diff --git a/Graphics Programs/star.cpp b/Graphics Programs/star.cpp new file mode 100644 index 0000000..a935a62 --- /dev/null +++ b/Graphics Programs/star.cpp @@ -0,0 +1,43 @@ +#include +#include +#include +#include +using namespace std; + +void dda(int x1,int y1,int x2,int y2) { + float dx,dy,len,xi,yi,i=1; + dx= x2-x1; + dy= y2-y1; + + if(abs(dx)>=abs(dy)) + len=abs(dx); + else + len=abs(dy); + + xi=x1+0.5; + yi=y1+0.5; + putpixel(xi,yi,WHITE); + dx=(dx)/len; + dy=(dy)/len; + + while(i<=len) { + xi=xi+dx; + yi=yi+dy; + putpixel(xi,yi,WHITE); + i++; + } +} + +main() { + int gd=DETECT,gm; + initgraph(&gd,&gm,""); + dda(100,100,300,100); + dda(100,100,200,300); + dda(300,100,200,300); + dda(100,270,200,50); + dda(300,270,200,50); + dda(100,270,300,270); + getch(); + + closegraph(); +} \ No newline at end of file diff --git a/Graphics Programs/star.png b/Graphics Programs/star.png new file mode 100644 index 0000000..3b1aac6 Binary files /dev/null and b/Graphics Programs/star.png differ diff --git a/Graphics Programs/traffic-light-simulation.cpp b/Graphics Programs/traffic-light-simulation.cpp new file mode 100644 index 0000000..0df7bd6 --- /dev/null +++ b/Graphics Programs/traffic-light-simulation.cpp @@ -0,0 +1,59 @@ +#include + +int main() +{ + int gd = DETECT, gm, midx, midy; + initgraph(&gd, &gm, ""); + + midx = getmaxx()/2; + midy = getmaxy()/2; + + setcolor(WHITE); + settextstyle(SCRIPT_FONT, HORIZ_DIR, 4); + settextjustify(CENTER_TEXT, CENTER_TEXT); + outtextxy(midx, midy-10, "Traffic Light Simulation"); + outtextxy(midx, midy+30, "Press any key to start"); + getch(); + + + cleardevice(); + setcolor(WHITE); + settextstyle(DEFAULT_FONT, HORIZ_DIR, 1); + rectangle(midx-30,midy-80,midx+30,midy+80); + circle(midx, midy-50, 22); + setfillstyle(SOLID_FILL,RED); + floodfill(midx, midy-50,WHITE); + setcolor(BLUE); + outtextxy(midx,midy-50,"STOP"); + getch(); + + + graphdefaults(); + cleardevice(); + setcolor(WHITE); + rectangle(midx-30,midy-80,midx+30,midy+80); + circle(midx, midy, 20); + setfillstyle(SOLID_FILL,YELLOW); + floodfill(midx, midy,WHITE); + setcolor(BLUE); + outtextxy(midx-18,midy-3,"READY"); + getch(); + + + cleardevice(); + setcolor(WHITE); + rectangle(midx-30,midy-80,midx+30,midy+80); + circle(midx, midy+50, 22); + setfillstyle(SOLID_FILL,GREEN); + floodfill(midx, midy+50,WHITE); + setcolor(BLUE); + outtextxy(midx-7,midy+48,"GO"); + setcolor(WHITE); + settextstyle(SCRIPT_FONT, HORIZ_DIR, 4); + outtextxy(midx-150, midy+100, "Press any key to exit..."); + getch(); + + + closegraph(); + return 0; +} \ No newline at end of file diff --git a/Graphics Programs/traffic-light-simulation.gif b/Graphics Programs/traffic-light-simulation.gif new file mode 100644 index 0000000..5707621 Binary files /dev/null and b/Graphics Programs/traffic-light-simulation.gif differ