-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
📟 Sample graphics program to practice
- Loading branch information
1 parent
1f89605
commit 3563d69
Showing
58 changed files
with
1,161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include<graphics.h> | ||
#include<iostream> | ||
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); | ||
<!--graphic-screenshot--> | ||
} | ||
getch(); | ||
closegraph(); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include<graphics.h> | ||
#include<conio.h> | ||
#include<dos.h> | ||
|
||
// 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); | ||
<!--graphic-screenshot--> | ||
cleardevice(); | ||
} | ||
getch(); | ||
closegraph(); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include<iostream> | ||
#include<conio.h> | ||
#include<graphics.h> | ||
#include<dos.h> | ||
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); | ||
<!--graphic-screenshot--> | ||
cleardevice(); | ||
} | ||
getch(); | ||
closegraph(); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#include<graphics.h> | ||
#include<conio.h> | ||
#include<cstdio> | ||
#include<dos.h> | ||
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); | ||
<!--graphic-screenshot--> | ||
cleardevice(); | ||
} | ||
getch(); | ||
closegraph(); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#include<conio.h> | ||
#include<graphics.h> | ||
#include<dos.h> | ||
#include<cmath> | ||
|
||
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); | ||
<!--graphic-screenshot--> | ||
cleardevice(); | ||
} | ||
} | ||
delay(40); | ||
<!--graphic-screenshot--> | ||
cleardevice(); | ||
} | ||
} | ||
getch(); | ||
closegraph(); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.