Graphics
Graphics
rakibhasancse20
March 2025
1
1 Shape
2
// circle (x , y , 50) ; // Face
// line ( x - 20 , y - 25 , x - 8 , y - 10) ; // Left eyebrow
// line ( x + 22 , y - 25 , x + 10 , y - 10) ; // Right eyebrow
// circle ( x - 20 , y - 10 , 10) ; // Left eye ( big circle )
// circle ( x + 25 , y - 10 , 10) ; // Right eye ( big circle )
// circle ( x - 15 , y - 10 , 3) ; // Left eye dot
// circle ( x + 20 , y - 10 , 3) ; // Right eye dot
// arc (x , y + 30 , 20 , 160 , 20) ; // Frown
// arc (x , y +20 , 250 , 290 , 15) ; // Frown
// }
int main () {
int gd = DETECT , gm ;
initgraph (& gd , & gm , " C :\\ Turboc3 \\ BGI " ) ;
d r a w _ w i n k _ s m i le y (100 , 100) ;
d r a w _ g l a s s e s _ s m i l e y (250 , 100) ;
draw_smiley (400 , 100) ;
d r a w _ a n g r y _ s m i l e y (550 , 100) ;
getch () ;
closegraph () ;
return 0;
}
3
Figure 2: 19i maget wo.cpp
4
rectangle ( x + 15 , y + 10 , x + 105 , y + 65) ;
// Stand
rectangle ( x + 50 , y + 80 , x + 70 , y + 90) ;
rectangle ( x + 20 , y + 90 , x + 100 , y + 100) ;
// Power button
circle ( x + 60 , y + 73 , 5) ;
floodfill ( x +60 , y +73 , WHITE ) ;
}
int main () {
int gd = DETECT , gm ;
initgraph (& gd , & gm , " C :\\ Turboc3 \\ BGI " ) ;
getch () ;
closegraph () ;
return 0;
}
5
floodfill (x , y +50 , WHITE ) ;
int main () {
int gd = DETECT , gm ;
initgraph (& gd , & gm , " C :\\ Turboc3 \\ BGI " ) ;
setbkcolor ( BLACK ) ;
cleardevice () ;
getch () ;
closegraph () ;
return 0;
}
6
Figure 4: 18i maget wo.cpp
// Speakers
circle ( x + 25 , y + 30 , 15) ;
circle ( x + 95 , y + 30 , 15) ;
circle ( x + 25 , y + 30 , 7) ; // Inner speaker
circle ( x + 95 , y + 30 , 7) ;
// Buttons
rectangle ( x + 50 , y + 10 , x + 70 , y + 20) ;
circle ( x + 60 , y + 40 , 5) ;
// Profile icon
setcolor (15) ; // Black elements inside
circle ( x + 30 , y + 25 , 12) ; // Head
arc ( x + 30 , y + 50 , 0 , 180 , 15) ; // Shoulders
7
line ( x +15 , y +50 , x +45 , y +50) ;
int main () {
int gd = DETECT , gm ;
initgraph (& gd , & gm , NULL ) ;
getch () ;
closegraph () ;
return 0;
}
\\ reccir . cpp
# include < stdio .h >
# include < math .h >
# include < graphics .h >
// Draw Circle
8
circle ( cx , cy , r ) ;
// Draw Rectangle
rectangle ( x1 , y1 , x2 , y2 ) ;
int main () {
int gd = DETECT , gm ;
initgraph (& gd , & gm , " C :\\ Turboc3 \\ BGI " ) ;
// Input Circle
printf ( " Enter ␣ circle ␣ center ␣ ( cx , ␣ cy ) ␣ and ␣ radius ␣ ( r ) : ␣ " ) ;
scanf ( " % d ␣ % d ␣ % d " , & cx , & cy , & r ) ;
// Input Rectangle
printf ( " Enter ␣ bottom - left ␣ ( x1 , ␣ y1 ) ␣ and ␣ top - right ␣ ( x2 , ␣ y2 ) ␣ of ␣
rectangle : ␣ " ) ;
scanf ( " % d ␣ % d ␣ % d ␣ % d " , & x1 , & y1 , & x2 , & y2 ) ;
// Check condition
if ( i s R e c t a n g l e I n s i d e C i r c l e ( cx , cy , r , x1 , y1 , x2 , y2 ) ) {
printf ( " The ␣ rectangle ␣ is ␣ inside ␣ the ␣ circle .\ n " ) ;
} else {
printf ( " The ␣ rectangle ␣ is ␣ NOT ␣ inside ␣ the ␣ circle .\ n " ) ;
}
9
3 check if a line touch the circle
// linecircle . cpp
int main () {
int gd = DETECT , gm ;
initgraph (& gd , & gm , " C :\\ Turboc3 \\ BGI " ) ;
// Input Circle
printf ( " Enter ␣ circle ␣ center ␣ ( cx , ␣ cy ) ␣ and ␣ radius ␣ ( r ) : ␣ " ) ;
scanf ( " % lf ␣ % lf ␣ % lf " , & cx , & cy , & r ) ;
// Input Line
printf ( " Enter ␣ line ␣ endpoints ␣ ( x1 , ␣ y1 ) ␣ and ␣ ( x2 , ␣ y2 ) : ␣ " ) ;
10
scanf ( " % lf ␣ % lf ␣ % lf ␣ % lf " , & x1 , & y1 , & x2 , & y2 ) ;
// Draw Circle
circle ( cx , cy , r ) ;
// Draw Line
line ( x1 , y1 , x2 , y2 ) ;
4 House
# include < graphics .h >
# include < conio .h >
void house ()
{
setcolor ( WHITE ) ;
setlinestyle ( SOLID_LINE , 0 , 3) ; // Thicker lines to ensure
visibility
// Roof
line (280 , 150 , 400 , 50) ;
line (285 , 155 , 400 , 60) ;
line (400 , 60 , 500 , 159) ;
line (400 , 50 , 510 , 155) ;
line (280 , 150 , 285 , 155) ;
line (500 , 159 , 510 , 155) ;
// House Body
rectangle (294 , 151 , 494 , 280) ;
setcolor (0) ;
setcolor (15) ;
// Door
rectangle (364 , 280 , 426 , 189) ;
circle (370 , 230 , 4) ;
// Windows
rectangle (364 , 120 , 426 , 151) ;
line (395 , 120 , 395 , 151) ;
line (364 , 136 , 426 , 136) ;
11
rectangle (310 , 250 , 350 , 200) ;
line (310 , 225 , 350 , 225) ;
line (330 , 200 , 330 , 250) ;
// Chimney
line (440 , 88 , 440 , 50) ;
line (450 , 99 , 450 , 50) ;
rectangle (438 , 47 , 452 , 52) ;
}
int main ()
{
int gd = DETECT , gm ;
initgraph (& gd , & gm , NULL ) ;
setbkcolor ( BLACK ) ;
cleardevice () ;
house () ;
getch () ;
closegraph () ;
}
12
5 White house
13
bar (220 ,260 ,280 ,380) ;
bar (320 ,260 ,380 ,380) ;
int main () {
int gd = DETECT , gm ;
initgraph (& gd , & gm , " C :\\ Turboc3 \\ BGI " ) ;
setbkcolor ( BLACK ) ;
cleardevice () ;
draw_image () ;
printf ( " % d ␣ % d ␣ " , getmaxx () , getmaxy () ) ;
getch () ;
closegraph () ;
return 0;
}
14
int main () {
int gd = DETECT , gm ;
initgraph (& gd , & gm , " C :\\ Turboc3 \\ BGI " ) ;
while (1) {
drawCircle (x , y , radius ) ; // Draw the circle
closegraph () ;
return 0;
}
while (1) {
ch = getch () ; // Get user input
15
if ( ch == ’l ’) x -= 10; // Move left
else if ( ch == ’r ’) x += 10; // Move right
else if ( ch == ’u ’) y -= 10; // Move up
else if ( ch == ’d ’) y += 10; // Move down
else if ( ch == ’q ’) break ; // Exit on ’q ’
int main () {
int gd = DETECT , gm ;
initgraph (& gd , & gm , " C :\\ Turboc3 \\ BGI " ) ; // Initialize graphics
mode
closegraph () ;
return 0;
}
8 Plane
Figure 7: Plane
void draw_plane ()
{
setlinestyle ( SOLID_LINE , 0 , THICK_WIDTH ) ;
16
line (210 , 150 , 420 , 150) ;
line (210 , 250 , 480 , 250) ;
arc (480 , 240 , 280 , 360 , 10) ;
line (490 , 240 , 450 , 170) ;
line (450 , 170 , 420 , 150) ;
arc (210 , 200 , 205 , 270 , 50) ;
arc (214 , 178 , 190 , 220 , 65) ;
line (149 , 188 , 140 , 120) ;
line (140 , 120 , 210 , 150) ;
setcolor ( BLACK ) ;
line (290 , 250 , 345 , 250) ;
setcolor ( WHITE ) ;
setcolor (0) ;
line (460 , 190 , 474 , 190) ;
line (474 , 190 , 474 , 210) ;
setcolor ( WHITE ) ;
floodfill (458 , 192 , 0) ;
}
int main ()
{
int gd = DETECT , gm ;
initgraph (& gd , & gm , NULL ) ;
draw_plane () ;
getch () ;
closegraph () ;
return 0;
}
17
9 Shower
Figure 8: Shower
void shower ()
{
arc (200 , 200 , 0 , 180 , 40) ;
line (160 , 200 , 240 , 200) ;
18
line (100 , 110 , 100 , 130) ;
floodfill (200 , 190 , WHITE ) ;
floodfill (200 , 150 , WHITE ) ;
int main ()
{
int gd = DETECT , gm ;
initgraph (& gd , & gm , " ␣ " ) ;
shower () ;
getch () ;
closegraph () ;
}
19
10 Shower with animation
Figure 9: Shower
void draw_shower ()
{
// Shower
arc (200 , 200 , 0 , 180 , 40) ;
line (160 , 200 , 240 , 200) ;
// Pipe
20
floodfill (200 , 150 , WHITE ) ;
// head
floodfill (200 , 190 , WHITE ) ;
int main ()
{
int gd = DETECT , gm ;
initgraph (& gd , & gm , " " ) ;
draw_shower () ;
outtextxy (100 , 400 , " Press ␣ any ␣ key ␣ to ␣ start ␣ water " ) ;
int y = 220;
while (! kbhit () ) // Run animation until another key is pressed
{
cleardevice () ;
draw_shower () ;
draw_droplets ( y ) ;
delay (100) ;
y += 10;
if ( y > getmaxy () ) y = 220; // Reset position
}
closegraph () ;
return 0;
}
21
11 DIRECT USE OF LINE EQUATION
// *************************************
// * DIRECT USE OF LINE EQUATION *
// *************************************
int main ( )
{
int x1 , y1 , x2 , y2 ;
float m ,c ,x , y ;
/* request auto detection */
int gdriver = DETECT , gmode , errorcode ;
x1 =200;
x2 =350;
y1 =250;
y2 =450;
m =( y2 - y1 ) /( x2 - x1 ) ;
c = y1 - m * x1 ;
printf ( " Direct ␣ Use ␣ of ␣ the ␣ Line ␣ Equation ␣ " ) ;
if (m <=1)
{
x = x1 ;
while (x <= x2 )
{
y=m*x+c;
putpixel (x ,y ,3) ;
x = x +1;
}
}
if (m >1)
{
y = y1 ;
while (y <= y2 )
{
y = y +1;
x =( y - c ) / m ;
putpixel (x ,y ,3) ;
}
}
getch () ;
closegraph () ;
return 0;
}
22
12 Cycle
void cycle ()
{
setlinestyle ( SOLID_LINE , 0 , THICK_WIDTH ) ;
int main ()
{
int gd = DETECT , gm ;
initgraph (& gd , & gm , " ␣ " ) ;
23
cycle () ;
getch () ;
closegraph () ;
}
24