Professional Documents
Culture Documents
INDEX
Sr.No 1. 2. 3. 4. 5. 6. 7. 8. 9. 10 11. 12. 13. Topic Introduction to Computer Graphics Applications of Computer Graphics Inbuilt Functions in Computer Graphics Program to draw line with direct method Program to draw line with Bresenham Line Algorithm Program to draw line with Direct Differential Algorithm Program to draw a circle with Direct Method Program to draw circle with Bresenham Circle Algorithm Program to draw circle with Midpoint Circle Algorithm Program to draw circle with Polar Algorithm Program to draw ellipse with Polynomial Algorithm Program to draw ellipse with Polar Algorithm Programs of 2D Transformations. Program to show the Translation of a line Program to show the Scaling Transformation Program to show the Rotation of an object Program to show the Reflection Transformation Program to show Shearing Transformation 14. Programs of Seven Applications Page No. 3 4 7 10 12 14 16 18 20 22 24 26 28 28 30 31 32 34 36
Computer Graphics
Computer graphics are graphics created using computers and, more generally, the representation and manipulation of image data by a computer. The development of computer graphics has made computers easier to interact with, and better for understanding and interpreting many types of data. Developments in computer graphics have had a profound impact on many types of media and have revolutionized animation, movies and the video game industry. The term computer graphics has been used in a broad sense to describe "almost everything on computers that are not text or sound. Typically, the term computer graphics refers to several different things:
the representation and manipulation of image data by a computer the various technologies used to create and manipulate images the images so produced, and the sub-field of computer science which studies methods for digitally synthesizing and manipulating visual content, see study of computer graphics Computer graphics is the life line of today's computer world. Today, computers and computer-generated images touch many aspects of daily life. Computer imagery is found on television, in newspapers, for example in weather reports, or for example in all kinds of medical investigation and surgical procedures. A well-constructed graph can present complex statistics in a form that is easier to understand and interpret. Computer generated imagery can be categorized into several different types: 2D, 3D, 5D, and animated graphics. As technology has improved, 3D computer graphics have become more common, but 2D computer graphics are still widely used. Computer graphics has emerged as a sub-field of computer science
2D Computer Graphics
2D computer graphics are the computer-based generation of digital imagesmostly from twodimensional models, such as 2D geometric models, text, and digital images, and by techniques specific to them. The word may stand for the branch of computer science that comprises such techniques, or for the models themselves.
3D Computer Graphics:
3D computer graphics in contrast to 2D computer graphics are graphics that use a threedimensional representation of geometric data that is stored in the computer for the purposes of performing calculations and rendering 2D images. Such images may be for later display or for real-time viewing. Despite these differences, 3D computer graphics rely on many of the same algorithms as 2D computer vector graphics in the wire frame model and 2D computer raster graphics in the final rendered display. In computer graphics software, the distinction between 2D and 3D is occasionally blurred; 2D applications may use 3D techniques to achieve effects such as lighting, and primarily 3D may use 2D rendering techniques.
Computer Animation
Computer animation is the art of creating moving images via the use of computers. It is a subfield of computer graphics and animation. Increasingly it is created by means of 3D computer graphics, though 2D computer graphics are still widely used for stylistic, low bandwidth, and faster real-time rendering needs. Sometimes the target of the animation is the computer itself, but sometimes the target is another medium, such as film. It is also referred to as CGI (Computergenerated imagery or computer-generated imaging), especially when used in films.
Visualization
Visualization is the process of rendering data as images in order to enhance our understanding. The idea is not new: maps are visualizations of terrain and since the early days of printing graphs and charts have been used to represent both empirical data and mathematical functions. Although visualization is used in nearly all fields of human Endeavour where computers may be used to process and display data, it's fair to say that the technique is used to the greatest extent in the commercial and scientific worlds.
Business Graphics
This term covers charts and graphs that represent economic statistics and which are generally used by managers in both in the public and private sectors. In particular, business visualization is used in analysis, to extract meaning from data, and for presentation, to explain data to an audience. The use of images in economics considerably predates the computer age, but of course computers enable the production of many kinds of highly effective and colorful charts from raw data in seconds; as a result a thriving market in presentation software exists.
Entertainment
Computer Graphics can be seen commonly used in music videos, television advertisement, animation pictures and various movies. Computer graphic techniques are used in these applications to produce transformation of one object into another, the process called morphing. Virtually every game on the computer uses computer graphics or animation. This includes Packman, Doom. Same CD games are actually interactive computer rendered movies such as The Seventh Guest.
Image Processing
Image processing is manipulation of images with the help of computers. Some of the algorithms used in image processing include thinning or skeletonisation, edge detection and contrast enhancement. These are usually implemented in software but may also use special purpose hardware for speed. Image processing contrasts with computer graphics, which is usually more concerned with the generation of artificial images, and visualization, which attempts to understand real-world data by displaying it as an artificial image.
Virtual Reality
Virtual reality is a way for humans to visualize, manipulate and interact with computers and extremely complex data. The visualization part refers to the computer generating visual, auditory or other sensual outputs to the user of a world within the computer. This world may ne CAD model, a scientific simulation, or a view into a database. The user can interact with the world and directly manipulate objects within the world. Interaction with the virtual world, at least with near real time control of the viewpoint, in my opinion, is a critical test for a virtual reality.
6
To draw Line: We have a line function directly to draw a line. It contains 4 parameters x1, y1, x2, y2. Here (x1, y1) are the starting point of the line and (x2, y2) are the ending points of the line. Syntax: line(x1, y1, x2, y2);
Example: line(20,10,30,40); Here x1 should be less than x2 and y1 should be less than y2.
2.
To draw an arc: To draw an arc we have an arc function. It has five parameters x1, y1, staring angle, ending angle, and radius.
To draw circle: to draw circle we have an inbuilt function with three parameters x centre, y centre and radius.
To draw ellipse: to draw ellipse we have an inbuilt function with three six parameters x, y, starting angle, ending angle, x radius and y radius). An ellipse has two radius so we are here x and y radius are used.
Syntax: ellipse(x, y, staring angle, ending angle, x radius, y radius); Example: ellipse (100,150,70,200,60,70);
5.
To plot pixel on screen: to plot a pixel we use putpixel function with three parameters x, y, color. Here x represents pixels on x-axis and y represents pixels on y-axis. Syntax:
putpixel(x, y, COLOR);
Example:
6.
To write text on the screen: to write text on screen we use outtext function. It has three parameters x, y, Name.
Syntax:
Example:
outtextxy (50,100,Poonam);
7.
To set style of the text: to set style of the text we use set text style function. It has three parameters style name, direction, size. Syntax: settextstyle (stylename, direction, size);
Example:
Settextstyle (TRIPLEX_FONT,0,7);
9
8.
To set style of a line: to set style of a line we use set line style function having three parameters style, unsigned pattern, and thickness. By default line is dotted in nature. horizontal-> 0 vertical-> 1 thickness range-> 0-1
Example:
setlinestyle(SOLID_LINE, 0, 1);
9.
To fill color in an object: to fill color in objects we have set fill style in-built function. It has two parameters fill style pattern, color.
Syntax:
10
Example:
Setfillstyle(SOLID_FILL,RED);
Output
12
Output
14
Output
Output
Output
23
} getch(); }
Output
25
Output
27
while(theta1<=theta2) { x=xr*cos(theta1);
28
Output
29
Programs of 2D Transformations
Program to show the Translation of a line
#include<graphics.h> #include<iostream.h> #include<conio.h> #include<dos.h> #include<stdlib.h> void main() { int gd=DETECT,gm; int x,x1,y,y1,r,tx,ty; initgraph(&gd,&gm," "); cleardevice(); setcolor(7); cout<<"enter value x,y,r"; cin>>x>>y>>r; circle(x,y,r);
30
Output
31
closegraph(); }
Output
33
cout<<"Enter value for x1,y1,r"; cin>>x1>>y1>>r; int xn1=x1+p; int yn1=y1+s; circle(xn1,yn1,r); cout<<"which reflection do u want"; cin>>n; if(n=='x') {
36
38
Output
39
pieslice(200,300,220,250,90); setcolor(8); pieslice(200,300,250,300,90); setcolor(9); pieslice(200,300,300,360,90); setcolor(10); outtextxy(150,150,"Food Items"); outtextxy(215,275,"MILK 30%"); outtextxy(175,275,"Egg"); outtextxy(120,275,"Curd"); outtextxy(120,315,"Chicken"); outtextxy(130,355,"Barfi"); getch(); closegraph(); }
41
Output
43
Output
45
Output
48
49
Output
51
while((x<=mx)||(y<=my)) { cleardevice(); setcolor(7); circle(x,y,30); line(x,y+30,x,y+100); line(x,y+100,x-50,y+200); line(x,y+100,x+50,y+200); line(x,y+50,x+50,y+50); line(x+50,y+50,x+75,y+25); line(x-50,y+200,x-75,y+175); line(x+50,y+200,x+75,y+175); circle(x-15,y-10,1); circle(x+15,y-10,1); line(x,y-5,x,y+5); line(x+75,y+25,x+75,y); circle(x+75,y-20,20);
57
Output
58
59