0% found this document useful (0 votes)
6 views50 pages

Computer Graphics Real 50 Programs

The document contains a series of C programs that implement various graphics algorithms and techniques using the graphics.h library. Each program demonstrates a specific functionality, such as line and circle drawing algorithms, transformations, animations, and event handling. The output of each program is described, indicating the visual result produced by the code.

Uploaded by

xpr4567
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views50 pages

Computer Graphics Real 50 Programs

The document contains a series of C programs that implement various graphics algorithms and techniques using the graphics.h library. Each program demonstrates a specific functionality, such as line and circle drawing algorithms, transformations, animations, and event handling. The output of each program is described, indicating the visual result produced by the code.

Uploaded by

xpr4567
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

Program 1: DDA Line Drawing Algorithm

#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// DDA Line Drawing Algorithm


// [Sample code here for dda line drawing algorithm]

getch();
closegraph();
}

// Output: A line drawn from point A to B using DDA algorithm.


Program 2: Bresenham Line Drawing Algorithm
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Bresenham Line Drawing Algorithm


// [Sample code here for bresenham line drawing algorithm]

getch();
closegraph();
}

// Output: A line drawn from point A to B using Bresenham algorithm.


Program 3: Midpoint Circle Drawing Algorithm
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Midpoint Circle Drawing Algorithm


// [Sample code here for midpoint circle drawing algorithm]

getch();
closegraph();
}

// Output: A circle drawn using midpoint circle algorithm.


Program 4: Midpoint Ellipse Drawing Algorithm
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Midpoint Ellipse Drawing Algorithm


// [Sample code here for midpoint ellipse drawing algorithm]

getch();
closegraph();
}

// Output: An ellipse drawn using midpoint ellipse algorithm.


Program 5: Line Clipping using Cohen-Sutherland
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Line Clipping using Cohen-Sutherland


// [Sample code here for line clipping using cohen-sutherland]

getch();
closegraph();
}

// Output: Line clipped to viewport using Cohen-Sutherland algorithm.


Program 6: Line Clipping using Liang-Barsky
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Line Clipping using Liang-Barsky


// [Sample code here for line clipping using liang-barsky]

getch();
closegraph();
}

// Output: Line clipped to viewport using Liang-Barsky algorithm.


Program 7: Polygon Clipping using Sutherland-Hodgeman
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Polygon Clipping using Sutherland-Hodgeman


// [Sample code here for polygon clipping using sutherland-hodgeman]

getch();
closegraph();
}

// Output: Polygon clipped using Sutherland-Hodgeman algorithm.


Program 8: 2D Translation of Object
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// 2D Translation of Object
// [Sample code here for 2d translation of object]

getch();
closegraph();
}

// Output: Object translated to new position.


Program 9: 2D Rotation of Object
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// 2D Rotation of Object
// [Sample code here for 2d rotation of object]

getch();
closegraph();
}

// Output: Object rotated around a pivot point.


Program 10: 2D Scaling of Object
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// 2D Scaling of Object
// [Sample code here for 2d scaling of object]

getch();
closegraph();
}

// Output: Object resized using scaling transformation.


Program 11: 2D Shearing
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// 2D Shearing
// [Sample code here for 2d shearing]

getch();
closegraph();
}

// Output: Object sheared horizontally or vertically.


Program 12: Reflection about X-Axis
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Reflection about X-Axis


// [Sample code here for reflection about x-axis]

getch();
closegraph();
}

// Output: Object reflected about X-axis.


Program 13: Reflection about Y-Axis
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Reflection about Y-Axis


// [Sample code here for reflection about y-axis]

getch();
closegraph();
}

// Output: Object reflected about Y-axis.


Program 14: Reflection about Origin
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Reflection about Origin


// [Sample code here for reflection about origin]

getch();
closegraph();
}

// Output: Object reflected about origin.


Program 15: Bresenham Circle Drawing Algorithm
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Bresenham Circle Drawing Algorithm


// [Sample code here for bresenham circle drawing algorithm]

getch();
closegraph();
}

// Output: A circle drawn using Bresenham's algorithm.


Program 16: Flood Fill Algorithm
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Flood Fill Algorithm


// [Sample code here for flood fill algorithm]

getch();
closegraph();
}

// Output: Area filled using flood fill algorithm.


Program 17: Boundary Fill Algorithm
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Boundary Fill Algorithm


// [Sample code here for boundary fill algorithm]

getch();
closegraph();
}

// Output: Area filled using boundary fill algorithm.


Program 18: Translation with Animation
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Translation with Animation


// [Sample code here for translation with animation]

getch();
closegraph();
}

// Output: Object smoothly translated with animation.


Program 19: Circle Pattern Design
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Circle Pattern Design


// [Sample code here for circle pattern design]

getch();
closegraph();
}

// Output: Pattern of multiple circles drawn.


Program 20: Colorful Concentric Circles
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Colorful Concentric Circles


// [Sample code here for colorful concentric circles]

getch();
closegraph();
}

// Output: Multiple concentric circles with different colors.


Program 21: 2D House using Basic Shapes
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// 2D House using Basic Shapes


// [Sample code here for 2d house using basic shapes]

getch();
closegraph();
}

// Output: House designed using lines, rectangles, and circles.


Program 22: Clock Design using Line and Circles
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Clock Design using Line and Circles


// [Sample code here for clock design using line and circles]

getch();
closegraph();
}

// Output: Analog clock layout using lines and circles.


Program 23: Smiley Face Design
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Smiley Face Design


// [Sample code here for smiley face design]

getch();
closegraph();
}

// Output: Smiley face created using basic shapes.


Program 24: Car Animation
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Car Animation
// [Sample code here for car animation]

getch();
closegraph();
}

// Output: A simple car moving across screen.


Program 25: Ball Bouncing Animation
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Ball Bouncing Animation


// [Sample code here for ball bouncing animation]

getch();
closegraph();
}

// Output: Ball bouncing with gravity effect.


Program 26: Star Pattern Drawing
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Star Pattern Drawing


// [Sample code here for star pattern drawing]

getch();
closegraph();
}

// Output: A star shape drawn using line segments.


Program 27: Rotating Line
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Rotating Line
// [Sample code here for rotating line]

getch();
closegraph();
}

// Output: Line rotating about one end.


Program 28: Rotating Polygon
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Rotating Polygon
// [Sample code here for rotating polygon]

getch();
closegraph();
}

// Output: Polygon rotating about its center.


Program 29: Scaling with Respect to Fixed Point
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Scaling with Respect to Fixed Point


// [Sample code here for scaling with respect to fixed point]

getch();
closegraph();
}

// Output: Object scaled with respect to a given point.


Program 30: 2D Composite Transformation
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// 2D Composite Transformation
// [Sample code here for 2d composite transformation]

getch();
closegraph();
}

// Output: Multiple transformations applied sequentially.


Program 31: Cubic Bezier Curve
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Cubic Bezier Curve


// [Sample code here for cubic bezier curve]

getch();
closegraph();
}

// Output: Smooth curve drawn using Bezier control points.


Program 32: Hermite Curve
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Hermite Curve
// [Sample code here for hermite curve]

getch();
closegraph();
}

// Output: Curve drawn using Hermite polynomial.


Program 33: 2D Bar Chart Design
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// 2D Bar Chart Design


// [Sample code here for 2d bar chart design]

getch();
closegraph();
}

// Output: Bar chart created using rectangles.


Program 34: 2D Pie Chart Design
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// 2D Pie Chart Design


// [Sample code here for 2d pie chart design]

getch();
closegraph();
}

// Output: Pie chart created using circle segments.


Program 35: Circle using Trigonometric Method
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Circle using Trigonometric Method


// [Sample code here for circle using trigonometric method]

getch();
closegraph();
}

// Output: Circle drawn using sin/cos method.


Program 36: Ellipse using Trigonometric Method
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Ellipse using Trigonometric Method


// [Sample code here for ellipse using trigonometric method]

getch();
closegraph();
}

// Output: Ellipse drawn using parametric equations.


Program 37: 2D Robot Structure
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// 2D Robot Structure
// [Sample code here for 2d robot structure]

getch();
closegraph();
}

// Output: Simple robot figure drawn using primitives.


Program 38: Human Face Using Graphics Primitives
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Human Face Using Graphics Primitives


// [Sample code here for human face using graphics primitives]

getch();
closegraph();
}

// Output: A cartoon-style human face.


Program 39: Drawing Indian Flag
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Drawing Indian Flag


// [Sample code here for drawing indian flag]

getch();
closegraph();
}

// Output: Indian national flag drawn using rectangles and circles.


Program 40: Animating a Walking Man
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Animating a Walking Man


// [Sample code here for animating a walking man]

getch();
closegraph();
}

// Output: Stick figure walking animation.


Program 41: Mouse Event Handling
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Mouse Event Handling


// [Sample code here for mouse event handling]

getch();
closegraph();
}

// Output: Circle drawn where mouse is clicked.


Program 42: Keyboard Event Handling
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Keyboard Event Handling


// [Sample code here for keyboard event handling]

getch();
closegraph();
}

// Output: Object moves with arrow keys.


Program 43: Simple Paint Tool
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Simple Paint Tool


// [Sample code here for simple paint tool]

getch();
closegraph();
}

// Output: Draw with mouse clicks and drags.


Program 44: Bouncing Ball with Sound
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Bouncing Ball with Sound


// [Sample code here for bouncing ball with sound]

getch();
closegraph();
}

// Output: Ball bounces and plays sound on impact.


Program 45: Drawing Dashed Line
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Drawing Dashed Line


// [Sample code here for drawing dashed line]

getch();
closegraph();
}

// Output: Line drawn with dashed pattern.


Program 46: Bar Graph from User Input
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Bar Graph from User Input


// [Sample code here for bar graph from user input]

getch();
closegraph();
}

// Output: Bar graph dynamically drawn from input.


Program 47: Drawing Rectangle with Mouse
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Drawing Rectangle with Mouse


// [Sample code here for drawing rectangle with mouse]

getch();
closegraph();
}

// Output: Rectangle drawn by dragging mouse.


Program 48: Animating Flag Waving
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Animating Flag Waving


// [Sample code here for animating flag waving]

getch();
closegraph();
}

// Output: Waving effect on flag using sine wave.


Program 49: Digital Clock Display
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Digital Clock Display


// [Sample code here for digital clock display]

getch();
closegraph();
}

// Output: Real-time digital clock display using graphics.


Program 50: Fireworks Animation
#include <graphics.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

// Fireworks Animation
// [Sample code here for fireworks animation]

getch();
closegraph();
}

// Output: Random fireworks effect using circle and lines.

You might also like