Graphics file
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Graphics file

on

  • 3,965 views

 

Statistics

Views

Total Views
3,965
Views on SlideShare
3,965
Embed Views
0

Actions

Likes
1
Downloads
172
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft Word

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Graphics file Document Transcript

  • 1. INTRODUCTION TO GRAPHICSComputer graphics are graphics created using computers and, more generally,the representation and manipulation of image data by a computer with help fromspecialized software and hardware. The development of computer graphics hasmade computers easier to interact with, and better for understanding andinterpreting many types of data. Developments in computer graphics have had aprofound impact on many types of media and have revolutionizedanimation, movies and the video game industry.The term computer graphics has been used in a broad sense to describe "almosteverything on computers that is not text or sound". Typically, the term computergraphics 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 contentAlthough computer graphics is a vast field that encompasses almost any graphicalaspect, we are mainly interested in the generation of images of 3-dimensionalscenes. Computer imagery has applications for film special effects, simulation andtraining, games, medical imagery, flying logos, etc. 1|Page
  • 2. Concepts and Principles 1. ImageIn common usage, an image or picture is an artifact, usually two-dimensional, thathas a similar appearance to some subject—usually a physical object or a person.Images may be two-dimensional, such as a photograph, screen display, and as wellas a three-dimensional, such as a statue. They may be captured by opticaldevices—such as cameras, mirrors, lenses, telescopes, microscopes, etc. andnatural objects and phenomena, such as the human eye or water surfaces. 2. PixelEach pixel is a sample of an original image, where more samples typically providea more accurate representation of the original. The intensity of each pixel isvariable; in color systems, each pixel has typically three or four components suchas red, green, and blue, or cyan, magenta, yellow, and black. 3. GraphicsGraphics are visual presentations on some surface, such as a wall, canvas,computer screen, paper, or stone to brand, inform, illustrate, or entertain. Examples are photographs , drawings, Line Art, graphs, diagrams, typography,numbers, symbols, geometric designs, maps, engineering drawings, or otherimages. Graphics often combine text, illustration, and color. 4. RenderingRendering is the process of generating an image from a model, by means ofcomputer programs. The model is a description of three dimensional objects in astrictly defined language or data structure. It would contain geometry, viewpoint,texture, lighting, and shading information. 2|Page
  • 3. APPLICATION OF GRAPHICS Computers have become a powerful tool for the rapid and economical productionof pictures. Advances in computer technology have made interactive computergraphics a practical tool. Today, computer graphics is used in the areas as science,engineering, medicine, business, industry, government, art, entertainment,advertising, education, and training. Computer-aided design Computer simulation Digital art Education Graphic design Info graphics Information visualization Rational drug design Scientific visualization Video Games Virtual reality Web design 1. COMPUTER AIDED DESIGNA major use of computer graphics is in design processes, particularly forengineering and architectural systems. For some design applications; objects arefirst displayed in a wireframe outline form that shows the overall sham and internalfeatures of objects. Software packages for CAD applications typically provide thedesigner with a multi-window environment. Each window can show enlargedsections or different views of objects. Standard shapes for electrical, electronic,and logic circuits are often supplied by the design package. The connectionsbetween the components have been mad automatically. Animations are often usedin CAD applications. When object designs are complete, realistic lighting modelsand surface rendering are applied. Manufacturing process of object can also be 3|Page
  • 4. controlled through CAD. Interactive graphics methods are used to layout thebuildings. Three-dimensional interior layouts and lighting also provided. Withvirtual-reality systems, the designers can go for a simulated walk inside thebuilding. 2. PRESENTATION GRAPHICSIt is used to produce illustrations for reports or to generate slide for withprojections. Examples of presentation graphics are bar charts, line graphs, surfacegraphs, pie charts and displays showing relationships between parameters. 3-Dgraphics can provide more attraction to the presentation. 3. COMPUTER ARTComputer graphics methods are widely used in both fine are and commercial artapplications. The artist uses a combination of 3D modeling packages, texturemapping, drawing programs and CAD software. Pen plotter with speciallydesigned software can create “automatic art”. “Mathematical Art” can be producedusing mathematical functions, fractal procedures. These methods are also appliedin commercial art. Animations are also used frequently in advertising, andtelevision commercials are produced frame by frame. Film animations require 24frames for each second in the animation sequence. A common graphics methodemployed in many commercials is morphing, where one object is transformed intoanother. 4|Page
  • 5. 4. ENTERTAINMENTCG methods are now commonly used in making motion pictures, music videos andtelevision shows.Many TV series regularly employ computer graphics method.Graphics objects can be combined with a live action. 5. EDUCATION AND TRAININGComputer-generated models of physical, financial and economic systems are oftenused as educational aids. For some training applications, special systems aredesigned. Eg. Training of ship captains, aircraft pilots etc., Some simulators haveno video screens, but most simulators provide graphics screen for visual operation.Some of them provide only the control panel. 6. VISUALIZATIONThe numerical and scientific data are converted to a visual form for analysis and tostudy the behavior called visualization. Producing graphical representation forscientific data sets are calls scientific visualization. And business visualization isused to represent the data sets related to commerce and industry. The visualizationcan be either 2D or 3D. 7. IMAGE PROCESSINGComputer graphics is used to create a picture. Image processing applies techniquesto modify or interpret existing pictures. To apply image processing methods, theimage must be digitized first. Medical applications also make extensive use ofimage processing techniques for picture enhancements, simulations of operations,etc. 5|Page
  • 6. 8. GRAPHICAL USER INTERFACENowadays software packages provide graphics user interface (GUI) for the user towork easily. A major component in GUI is a window. Multiple windows can beopened at a time. To activate any one of the window, the user needs just to checkon that window. Menus and icons are used for fast selection of processingoperations.SOME INBUILT GRAPHICS FUNCTION 1. Initgraph( )It is use to initialize the graph. Initgraph initializes the graphics system by loadinga graphics driver from disk and putting the system into graphics mode.To start the graphics system, first call the initgraph function. Initgraph loads thegraphics driver and puts the system into graphics mode.Syntax:- #include <graphics.h> void initgraph(int *graphdriver, int *graphmode, char *path driver); 2. Closegraph( )It is used to close the graph . Closegraph deallocates all memory allocated by thegraphics system, then restores the screen to the mode it was in before you calledinitgraphSyntax:- #include <graphics.h> void closegraph(int wid=ALL_WINDOWS); 6|Page
  • 7. 3. Line( )The line statement we use in C programming for graphics and it is a part ofGRAPHICS.H header fileSyntax:-line(x1, y1, x2, y2) 4. Arc( )The arc statement we use in C programming for draw curve onThe screen and it is a part of GRAPHICS.HSyntax:-arc (midx, midy, stangle, endangle, radius); 5. Circle( )Circle function in computer graphics give value center of the circle and then its radius.Syntax:-circle(xcentre,ycentre,radius); 6. getmaxx( )getmaxx() function is used to get the maximum x value of graphics screen, usuallyit is 639 for VGA driver and VGAHI graphics mode. getmaxy is used to get themaximum y value of graphics screen.Syntax:-rectangle(0,0,getmaxx(),getmaxy()) 7|Page
  • 8. 7. Floodfill ( )The floodfill is use to paint the screen or specific areawithin boundaries through apoint , i.e.-e in Circle,Ellipse,Box, or any kind of shape which is fully locked areaor two dimensional .Syntax:-floodfill (int x, int y, int border) 8. Setfillstyle ( )It is used to choose the style and color .Syntax: setsfillstyle( int pattern, int color) 9. Setcolor ( )It can be sets the current drawing color.Syntax:-Setcolor(int color); 10. cleardevice ( )Cleardevice erases (that is, fills with the current background color) the entiregraphics screen and moves the CP (current position) to home (0,0).Syntaxvoid cleardevice(void); 8|Page
  • 9. 11. delay ( )Delay function is used to suspend execution of a program for a particular time.Syntax :- void delay(unsigned int); 12.Outtextxy ( )outtextxy displays a text string in the viewport at the given position (x, y), usingthe current justification settings and the current font, direction, and size. Tomaintain code compatibility when using several fonts, use textwidth and textheightto determine the dimensions of the string.If a string is printed with the default font using outtext or outtextxy, any part of thestring that extends outside the current viewport is truncated. outtextxy is for use ingraphics mode; it will not work in text mode.Syntax:-void outtextxy(int x, int y, char *textstring); 13.Rectangle ( )This sets up a new Rectangle object called recOne. In between the round bracketsof Rectangle, we have two sets of numbers. The first set (150, 10) is how far to theleft you want your rectangle, and how far down. The second set (50, 200) is thewidth of the rectangle, and then the height.Syntax:-Rectangle recOne = new Rectangle( 150, 10, 50, 200 ); 14.Ellipse ( ) It is used to draw the ellipse. Syntax :-ellipse(xcentre, ycentre, StAngle, EndAngle, xRadius, Yradius); 9|Page
  • 10. 15.Setbkcolor ( )setbkcolor function changes current background colore.g.setbkcolor(YELLLOW) changes the current background color toYELLOW.Remember that default drawing color is WHITE and background color isBLACK.Syntax :-void setbkcolor(int color);16.Getmaxy ( )getmaxy function returns the maximum Y coordinate for current graphics modeand driver.Syntax :- int getmaxy(); 10 | P a g e
  • 11. 1. Program to show the „DIRECT METHOD” for drawing a line.#include<iostream.h>#include<conio.h>#include<graphics.h>void main(){clrscr(); int gd=DETECT, gm; int x1,y1,x2,y2,m=0,c=0; initgraph(&gd,&gm,""); cout<<"Enter the value of starting and ending points"; cin>>x1>>y1>>x2>>y2; m= (y2-y1)/(x2-x1); c=y1-(m*x1);while(x1<=x2){ if(m<=1) { y1=(m*x1)+c; x1++; putpixel(x1,y1,RED); } else 11 | P a g e
  • 12. { x1=(y1-c)/m; y1++; putpixel(x1,y1,RED); }}getch();closegraph();} OUTPUT: 12 | P a g e
  • 13. 2. Program to show “DIGITAL DIFFERENTIAL ANALYZER”Algorithm.#include<iostream.h>#include<conio.h>#include<graphics.h>void main(){clrscr(); int gd=DETECT, gm; int x1,y1,x2,y2,m=0,c=0; initgraph(&gd,&gm,""); cout<<"Enter the value of x1,y1,x2,y2"; cin>>x1>>y1>>x2>>y2; m=(y2-y1)/(x2-x1); c=y1-(m*x1); while(x1<=x2) { if(m<=1) { x1=x1+1; y1=y1+m; putpixel(x1,y1,RED); } else 13 | P a g e
  • 14. { y1=y1+1; x1=x1+1/m; putpixel(x1,y1,RED); } }getch();closegraph();} OUTPUT: 14 | P a g e
  • 15. 3. Program to show “BRESENHAM LINE” Algorithm.#include<iostream.h>#include<conio.h>#include<graphics.h>void main(){clrscr(); int gd=DETECT, gm; int x1,y1,x2,y2,dy,dx,f,fe,fne; initgraph(&gd,&gm,""); cout<<"Enter the value of x1 and y1"; cin>>x1>>y1; cout<<"Enter the value of x2 and y2"; cin>>x2>>y2; dy=y2-y1; dx=x2-x1; f=2dy-dx; fe=2dy; fne=2dy-2dx; while(x1<=x2) { if(f<=0) { 15 | P a g e
  • 16. f=f+fe; x1++; putpixel(x1,y1,WHITE); } else { f=f+fne; x1++; y1++; putpixel(x1,y1,WHITE); } }getch();closegraph();} OUTPUT: 16 | P a g e
  • 17. 4. Program of “DIRECT METHOD” to draw a circle.#include<iostream.h>#include<conio.h>#include<graphics.h>void main(){clrscr(); int gd=DETECT, gm; int xc,yc,xend ,r; initgraph(&gd,&gm,""); cout<<”Enter x-centre, y-centre and radius”; cin>>xc>>yc>>r; int x=0; xend=r/sqrt(2); while(x<xend) { y=sqrt(r*r-x*x); putpixel(x+xc, y+yc, WHITE); putpixel(y+xc, x+yc, RED); putpixel(y+xc, -x+yc, WHITE); putpixel(-x+xc, y+yc, RED); putpixel(-x+xc, -y+yc, WHITE); putpixel(-y+xc, x+yc, RED); 17 | P a g e
  • 18. putpixel(x+xc,-y+yc,WHITE); x++; } getch(); closegraph();} OUTPUT: 18 | P a g e
  • 19. 5. Program of “POLAR COORDINATES METHOD” to draw a circle.#include<iostream.h>#include<conio.h>#include<graphics.h>void main(){clrscr(); int gd=DETECT,gm; int xc,yc,x,y ,r,th; initgraph(&gd,&gm,""); cout<<”Enter x-centre, y-centre and radius”; cin>>xc>>yc>>r; th=1/r; x=0; y=r; while(x<y) { putpixel(x+xc, y+yc, WHITE); putpixel(y+xc, x+yc, RED); putpixel(y+xc, -x+yc, WHITE); putpixel(-x+xc, y+yc, RED); putpixel(-x+xc, -y+yc, WHITE); putpixel(-y+xc, x+yc, RED); 19 | P a g e
  • 20. putpixel(x+xc,-y+yc,WHITE); float temp=y; y=y*cos(th)+x*sin(th); x=x*cos(th)-temp*sin(th); }getch();} OUTPUT: 20 | P a g e
  • 21. 6. Program of “MID-POINT METHOD” to draw a circle.#include<iostream.h>#include<conio.h>#include<graphics.h>void main(){clrscr(); int gd=DETECT, gm; int xc,yc,x,y,r,f; initgraph(&gd,&gm,""); cout<<”Enter x-centre, y-centre and radius”; cin>>xc>>yc>>r; x=0; y=r; f=1-r; while(x<=y) { if(f<0) { f=f+(3+2*x); x++; } else { 21 | P a g e
  • 22. f=f+(2*x-2*y+5) x++; y--; } putpixel(x+xc, y+yc, WHITE); putpixel(y+xc, x+yc, RED); putpixel(y+xc, -x+yc, WHITE); putpixel(-x+xc, y+yc, RED); putpixel(-x+xc, -y+yc, WHITE); putpixel(-y+xc, x+yc, RED); putpixel(x+xc,-y+yc,WHITE); }getch();closegraph();}OUTPUT: 22 | P a g e
  • 23. 7. Program of “BRESENHAM‟S ALGORITHM” to draw a circle.# include<iostream.h># include<conio.h># include<graphics.h>void cpoint(int,int,int,int);void main(){clrscr();int xc,yc,r,f,fe,fse,x,y;int gd=DETECT, gm;initgraph(&gd,&gm,"");cout<<"nEnter x-center,y-center,radius : ";cin>>xc>>yc>>r;x=0;y=r;f=3-r;while(x<=y){ if(f<0) { fe=4*x+6; f=f+fe; x++; cpoint(x,y,xc,yc); } else if(f>0) {fse=10+(4*x)-(4*y); 23 | P a g e
  • 24. f=f+fse; x++; y--; cpoint(x,y,xc,yc); }}getch();}void cpoint(int x,int y, int xc, int yc){ putpixel(x+xc,y+yc,1); putpixel(y+xc,x+yc,1); putpixel(-x+xc,y+yc,1); putpixel(-y+xc,x+yc,1); putpixel(-x+xc,-y+yc,1); putpixel(-y+xc,-x+yc,1); putpixel(x+xc,-y+yc,1); putpixel(y+xc,-x+yc,1);}OUTPUT:- 24 | P a g e
  • 25. 8. Program to draw an Ellipse using Direct Method#include<iostream.h>#include<conio.h>#include<graphics.h>#include<math.h>void main(){int gd,gm;float xc,yc,xr,yr;gd=DETECT,gm;initgraph(&gd,&gm,"");cout<<"Enter xcentre ,ycentre, xradius,yradius";cin>>xc>>yc>>xr>>yr;float x=0;float y=xr;while(x<=y){y=yr*sqrt(1-((x*x)/(xr*xr)));putpixel(x+xc,y+yc,WHITE);putpixel(-x+xc,y+yc,WHITE);putpixel(-x+xc,-y+yc,WHITE);putpixel(x+xc,-y+yc,WHITE);x++;}getch();} 25 | P a g e
  • 26. OUTPUT:9. Program to draw an Ellipse using Polar Co-ordinates Method#include<iostream.h>#include<conio.h>#include<graphics.h>#include<math.h>void main(){int gd=DETECT, gm;clrscr();initgraph(&gd,&gm," ");float xc,yc,xr,yr;cout<<"Enter xc,yc,xr,yr"; 26 | P a g e
  • 27. cin>>xc>>yc>>xr>>yr;float theta1=0;float theta2=90;while(theta1<theta2){float x=xr*cos(theta1);float y=yr*sin(theta1);putpixel(x+xc,y+yc,WHITE);putpixel(-x+xc,y+yc,WHITE);putpixel(-x+xc,-y+yc,WHITE);putpixel(x+xc,-y+yc,WHITE);theta1++;}getch();}OUTPUT: 27 | P a g e
  • 28. 10 .Program to draw an Ellipse using Mid Point method.#include<iostream.h>#include<conio.h>#include<graphics.h>#include<math.h>void main(){ int gd=DETECT, gm; initgraph(&gd,&gm,""); float xc,yc,x,y,xr,yr,f; cout<<"Enter xc,yc,xr ,yr"; cin>>xc>>yc>>xr>>yr; x=0; y=yr; f=(yr*yr)+(xr*xr)/4-(xr*xr)*yr; while(2*(yr*yr)*x<=2*(xr*xr)*y) { if(f<=0) { f=f+(3+(2*x))*(yr*yr); x++; putpixel(x+xc,y+yc,WHITE); putpixel(-x+xc,y+yc,WHITE); putpixel(-x+xc,-y+yc,WHITE); putpixel(x+xc,-y+yc,WHITE); } else 28 | P a g e
  • 29. { f=f+3*(yr*yr)+2*x*(yr*yr)+2*(xr*xr)-2*y*(xr*xr); x++; y--; putpixel(x+xc,y+yc,WHITE); putpixel(-x+xc,y+yc,WHITE);putpixel(-x+xc,-y+yc,WHITE); putpixel(x+xc,-y+yc,WHITE); } } f=(yr*yr)/4-2*(xr*xr)*yr+(xr*xr); while(y>=0) { if(f<=0) { f=f+(3-(2*y))*(xr*xr); x++; y--; putpixel(x+xc,y+yc,WHITE); putpixel(-x+xc,y+yc,WHITE); putpixel(-x+xc,-y+yc,WHITE); putpixel(x+xc,-y+yc,WHITE); } else { f=f+2*(yr*yr)+2*x*(yr*yr)+3*(xr*xr)-2*y*(xr*xr); y--; putpixel(x+xc,y+yc,WHITE); putpixel(-x+xc,y+yc,WHITE); 29 | P a g e
  • 30. putpixel(-x+xc,-y+yc,WHITE); putpixel(x+xc,-y+yc,WHITE); } } getch(); closegraph();}OUTPUT:STATIC APPLICATION11. Program to make a flag.#include<graphics.h>#include<conio.h>#include<iostream.h>void main(){int gd = DETECT,gm; 30 | P a g e
  • 31. clrscr();initgraph(&gd,&gm," ");setcolor(5);line(20,50,20,180);line(20,50,100,50);line(20,70,100,70);line(20,90,100,90);line(20,110,100,110);line(100,50,100,110);circle(60,80,10);line(52,80,68,80);line(60,72,60,88);setfillstyle(SOLID_FILL,22);floodfill(21,51,5);setfillstyle(SOLID_FILL,7);floodfill(21,75,5);setfillstyle(SOLID_FILL,2);floodfill(21,95,5);setfillstyle(SOLID_FILL,7);floodfill(81,75,5);setfillstyle(SOLID_FILL,7);floodfill(61,81,5);getch();closegraph();} 31 | P a g e
  • 32. Output:-DYNAMIC APPLICATIONS12. Program to show stars and moon on the screen.#include<iostream.h>#include<stdlib.h>#include<graphics.h>#include<conio.h>#include<dos.h>void main(){int x,y,i;int gd=DETECT,gm; 32 | P a g e
  • 33. initgraph(&gd,&gm," ");outtextxy(350,350,"GOOD NIGHT JI");circle(200,200,50);setfillstyle(1,15);floodfill(200,200,15);setcolor(0);setfillstyle(1,0);circle(180,180,50);floodfill(180,180,0);for (i=0;i<1000;i++){x = random(1500);y = random(1500);putpixel(x,y,15);}getch();closegraph();} 33 | P a g e
  • 34. Output:-13. Program to implement an application of circle to show the differentpatterns and colors.#include<iostream.h>#include<stdlib.h>#include<conio.h>#include<graphics.h>#include<dos.h>#include<math.h>void circlepoints(float,float,float,float);void main() 34 | P a g e
  • 35. {int gd=DETECT,gm;initgraph(&gd,&gm," ");float x,y,xc,yc,r,xend;cout<<"enter xc,yc,radius";cin>>xc>>yc>>r;x=0;xend=r/sqrt(2);while(x<xend) { y=sqrt(r*r-x*x); circlepoints(x,y,xc,yc); delay(100); x++; } while(!kbhit()) { setfillstyle(random(10),random(7)); floodfill(xc,yc,7); } getch(); closegraph(); void circlepoints(float x,float y,float xc,float yc){ 35 | P a g e
  • 36. putpixel(x+xc,y+yc,7); putpixel(y+xc,x+yc,7); putpixel(-y+xc,x+yc,7); putpixel(-x+xc,y+yc,7); putpixel(-x+xc,-y+yc,7); putpixel(-y+xc,-x+yc,7); putpixel(x+xc,-y+yc,7); putpixel(y+xc,-x+yc,7);}Output 36 | P a g e