Вы находитесь на странице: 1из 19

GURUKUL VIDYAPEETH CSE 5TH

PROGRAM NO 1
AIM: INTRODUCTION TO COMPUTER GRAPHICS. THEORY:

Computer graphics:
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.

History
The phrase Computer Graphics was coined in 1960 by William Fetter, a graphic designer for Boeing. The field of computer graphics developed with the emergence of computer graphics hardware. Early projects like the Whirlwind and SAGE Projects introduced the CRT as a viable display and interaction interface and introduced the light pen as an input device.

Initial 1960s developments


Further advances in computing led to greater advancements in interactive computer graphics. In 1959, the TX-2 computer was developed at MIT's Lincoln Laboratory. The TX-2 integrated a number of new man-machine interfaces. A light pen could be used to draw sketches on the computer using Ivan Sutherland's revolutionary Sketchpad software. Using a light pen, Sketchpad allowed one to draw simple shapes on the computer screen, save them and even recall them later. The light pen itself had a small photoelectric cell in its tip. This cell emitted an electronic pulse whenever it was placed in front of a computer screen and the screen's electron gun fired directly at it. By simply timing the electronic pulse with the current location of the electron gun, it was easy to pinpoint exactly where the pen was on the screen at any given moment. Once that was determined, the computer could then draw a cursor at that location.

100810392082 Sukhjeet Singh

GURUKUL VIDYAPEETH CSE 5TH

TYPES: 2 D TWO DIMENSIONAL 3 D THREE DIMENSIONAL Two-dimensional:


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. 2D computer graphics are mainly used in applications that were originally developed upon traditional printing anddrawing technologies, such as typography, cartography, technical drawing, advertising, etc.. In those applications, the two-dimensional image is not just a representation of a real-world object, but an independent artifact with added semantic value; twodimensional models are therefore preferred, because they give more direct control of the image than 3D computer graphics, whose approach is more akin to photography than to typography.

Pixel art
Pixel art is a form of digital art, created through the use of raster graphics software, where images are edited on the pixel level. Graphics in most old (or relatively limited) computer and video games, graphing calculator games, and many mobile phone games are mostly pixel art.

Vector graphics
Vector graphics formats are complementary to raster graphics, which is the representation of images as an array of pixels, as it is typically used for the representation of photographic images .Vector graphics consists in encoding information about shapes and colors that comprise the image, which can allow for more flexibility in rendering. There are instances when working with vector tools and formats is best practice and instances when working with raster tools and formats is best practice. There are times when both formats come together. An understanding of the advantages and limitations of each technology and the relationship between them is most likely to result in efficient and effective use of tools

Three-dimensional:

100810392082 Sukhjeet Singh

GURUKUL VIDYAPEETH CSE 5TH

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. 3D computer graphics are often referred to as 3D models. Apart from the rendered graphic, the model is contained within the graphical data file. However, there are differences. A 3D model is the mathematical representation of any three-dimensional object. A model is not technically a graphic until it is visually displayed. Due to 3D printing, 3D models are not confined to virtual space. A model can be displayed visually as a two-dimensional image through a process called 3D rendering, or used in non-graphical computer simulations and calculations. There are some 3D computer graphics software for users to create 3D images.

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 realtime 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 (Computer-generated imageryor computer-generated imaging), especially when used in films

100810392082 Sukhjeet Singh

GURUKUL VIDYAPEETH CSE 5TH

PROGRAM NO 2 (a) Program 2(a) :- Write a program to draw a line.


#include<iostream.h> #include<graphics.h> #include<conio.h> void main() { int gdriver = DETECT, gmode, errorcode; initgraph(&gdriver, &gmode, ""); int x1,x2,y1,y2; cout<<"For first point"<<endl; cout<<"x co-ordinate"<<'\t'; cin>>x1; cout<<"y co-ordinate"<<'\t'; cin>>y1; cout<<"For second point"<<endl; cout<<"x co-ordinate"<<'\t'; cin>>x2; cout<<"y co-ordinate"<<'\t'; cin>>y2; setcolor(getmaxcolor()); line(x1,y1,x2,y2); getch(); closegraph();
} 100810392082 Sukhjeet Singh 4

GURUKUL VIDYAPEETH CSE 5TH

OUTPUT:

100810392082 Sukhjeet Singh

GURUKUL VIDYAPEETH CSE 5TH

PROGRAM NO 2(b)
Program 2(b) :- Write a program to draw a triangle.
#include<iostream.h> #include<graphics.h> #include<conio.h> void main() { int gdriver = DETECT, gmode, errorcode; initgraph(&gdriver, &gmode, ""); int x1,x2,y1,y2,x3,y3; cout<<"For first point"<<endl; cout<<"x co-ordinate"<<'\t'; cin>>x1; cout<<"y co-ordinate"<<'\t'; cin>>y1; cout<<"For second point"<<endl; cout<<"x co-ordinate"<<'\t'; cin>>x2; cout<<"y co-ordinate"<<'\t'; cin>>y2; cout<<"For third point"<<endl; cout<<"x co-ordinate"<<'\t'; cin>>x3; cout<<"y co-ordinate"<<'\t';
100810392082 Sukhjeet Singh 6

GURUKUL VIDYAPEETH CSE 5TH

cin>>y3;

setcolor(getmaxcolor()); line(x1,y1,x2,y2); line(x2,y2,x3,y3); line(x3,y3,x1,y1); getch(); closegraph(); }

OUTPUT:

100810392082 Sukhjeet Singh

GURUKUL VIDYAPEETH CSE 5TH

PROGRAM NO 3(a)
Program 3(a) :- Write a program to draw a circle.
#include<iostream.h> #include <graphics.h> #include <conio.h> void main() { int gdriver = DETECT, gmode, errorcode; int x,y; int radius; initgraph(&gdriver, &gmode, ""); cout<<"Enter the centre"<<endl; cout<<"Along x-axis"<<'\t'; cin>>x; cout<<"Along y-axis"<<'\t'; cin>>y; cout<<"Enter the radius"<<endl; cin>>radius; setcolor(getmaxcolor()); circle(x,y,radius); getch(); closegraph(); }

100810392082 Sukhjeet Singh

GURUKUL VIDYAPEETH CSE 5TH

OUTPUT:

100810392082 Sukhjeet Singh

GURUKUL VIDYAPEETH CSE 5TH

PROGRAM NO 3(b)
Program 3(b) :- Write a program to draw a rectangle.
#include<iostream.h> #include<graphics.h> #include<conio.h> int main(void) { int gdriver = DETECT, gmode, errorcode; int left,top, right,bottom; initgraph(&gdriver, &gmode, ""); cout<<"Enter left"; cin>>left; cout<<"Enter top"; cin>>top; cout<<"Enter right"; cin>>right; cout<<"Enter lbottom"; cin>>bottom; rectangle(left,top,right,bottom); getch(); closegraph(); return 0; }

100810392082 Sukhjeet Singh

10

GURUKUL VIDYAPEETH CSE 5TH

OUTPUT:

100810392082 Sukhjeet Singh

11

GURUKUL VIDYAPEETH CSE 5TH

PROGRAM NO 4
Program 4 :- Write a program to draw an ellipse.
#include<iostream.h> #include<graphics.h> #include<conio.h> void main() { int gdriver = DETECT, gmode, errorcode; int x,y; int stangle=0,endangle=360; int xradius,yradius; cout<<"Enter the centre"<<endl; cout<<"Along x-axis"<<'\t'; cin>>x; cout<<"Along y-axis"<<'\t'; cin>>y; cout<<"Enter the radius"<<endl; cout<<"Along x-axis"<<'\t'; cin>>xradius; cout<<"Along y-axis"<<'\t'; cin>>yradius; initgraph(&gdriver, &gmode, ""); setcolor(getmaxcolor());
100810392082 Sukhjeet Singh 12

GURUKUL VIDYAPEETH CSE 5TH

ellipse(x,y, stangle, endangle,xradius, yradius); getch(); closegraph(); }

OUTPUT:

100810392082 Sukhjeet Singh

13

GURUKUL VIDYAPEETH CSE 5TH

PROGRAM NO 5
Program 5:- Write a program to draw a line using DDA algorithm.
#include<iostream.h> #include<conio.h> #include<graphics.h> void main() { int gdriver=DETECT,gmode; float x1,x2,x,y,y1,y2,m,dx,dy,ix,iy; cout<<"enter first co ordinate"; cin>>x1>>y1; cout<<"enter second co ordinate"; cin>>x2>>y2; initgraph(&gdriver,&gmode,""); dx=x2-x1; dy=y2-y1; if(dx>dy) m=dx; else m=dy; ix=dx/m; iy=dy/m;
100810392082 Sukhjeet Singh 14

GURUKUL VIDYAPEETH CSE 5TH

x=x1; y=y1; for(int i=0;i<m;i++) { x=x+ix; y=y+iy; putpixel(x,y,6); } getch(); closegraph(); }

OUTPUT:

100810392082 Sukhjeet Singh

15

GURUKUL VIDYAPEETH CSE 5TH

PROGRAM NO 6
Program 6: To Draw a Circle Using Bresnenhams Algorithm.
#include<stdio.h> #include<conio.h> #include<graphics.h> void circlepoints(int,int); void main() { int x,y,p,r; int gdriver=DETECT,gmode; initgraph(&gdriver,&gmode,"C:\\tc\\bgi:"); clrscr(); printf("enter the radius"); scanf("%d",&r); x=0;y=r;p=1-r; while(x<y) { x++; if(p>0) { p=p+2*(x-y)+1; y--; } else p=p+2*x+1; circlepoints(x,y);
100810392082 Sukhjeet Singh 16

GURUKUL VIDYAPEETH CSE 5TH

} closegraph(); getch(); } void circlepoints(int x,int y)

100810392082 Sukhjeet Singh

17

GURUKUL VIDYAPEETH CSE 5TH

{ putpixel(x+300,y+300,8); putpixel(x+300,-y+300,8); putpixel(-x+300,y+300,8); putpixel(-x+300,-y+300,8); putpixel(y+300,x+300,8); putpixel(y+300,-x+300,8); putpixel(-y+300,x+300,8); putpixel(-y+300,-x+300,8); }

OUTPUT:

100810392082 18 Sukhjeet Singh

GVIET CSEY 5TH

100810392048 CHARAN DASS

19

Вам также может понравиться