Assignment: 1
Course Code: CAP616 Course Title: Computer Graphics Submitted by: Karan Gaba Reg No.:10900899 Roll no: D1901-A17 (Bca/Mca)
Part A
1. Differentiate between Random and Raster Scan Systems. Ans Raster scan and random scan are two types of display systems that use CRT monitors. These are used to project or exhibit softcopy information in the form of alphanumeric or graphic symbology. The information that is displayed using these two techniques is not permanent which is why it is called softcopy information. All the information that is presented in graphical form can only be viewed as long as it is there on the display screen which is the CRT monitor. Raster scan is based upon television technology which uses an electron beam that is swept across the screen and it creates a pattern of illuminated spots. In the case of random scan the electron beam is directed to only those parts of the screen where the picture is to be drawn. In random scan, one line of the picture is drawn at a time which is why it is also called a vector display. The display in random scan is basically a computer controlled oscilloscope. For a layman, raster scan and random scan can be described in a very simple way of using a pencil to draw something on a screen. The first way would be to lift and lower the pencil and draw anything on the screen. This is a tedious procedure and looks old now. Another way is to draw many parallel lines across the screen and using pressure the intensity can be varied to present different shades and thus achieving the graphical represent that you require on the CRT monitor. This makes it easy to draw horizontal and vertical lines at the same time and is called raster scan. However, neither of the two types is being used these days as a new advanced method of individual pixels has been developed that can be used to turn on and off independently to emit and absorb light.
2. Compare and Contrast DDA and Bresenham's Line drawing algorithms. Ans DDA is used in drawing straight line to form a line, triangle or polygon in computer graphics. DDA analyzes samples along the line at regular interval of one coordinate as the integer and for the other coordinate it rounds off the integer that is nearest to the line. Bresenham Algorithm is much accurate and much more efficient than DDA. It scans the coordinates but instead of rounding them off it takes the incremental value in account by adding or subtracting and therefore can be used for drawing circle and curves.
3. Explicate in detail the various Graphic display devices. Ans. A graphic display device receives data and instructions from an external computer and displays graphic patterns such as alphanumeric characters, symbols, etc., upon a cathode ray tube in accordance therewith. The graphic display device has a pattern generator for storing luminance data controlling the formation on the cathode ray tube of predetermined patterns, and a refresh memory for receiving and storing data designating the particular arrangement of patterns to be displayed, and is characterized by an arrangement reducing the required capacity of the pattern generator memory. Pursuant to the invention, the pattern generator is formed with a random access memory into which data can be written and from which data can be read, and has means operated on a time sharing multiplexing basis with data reading operations for writing luminance data supplied by the external computer into the pattern generator memory, and for storing in the refresh memory the addresses of the luminance data written into the pattern generator memory. The pattern generator need store formation data for only those characters actually being displayed on the cathode ray tube, and memory requirements are minimized. Flat panel displays Encompass a growing number of technologies enabling video displays that are much lighter and thinner than traditional television and video displays that use cathode ray tubes, and
are usually less than 100 mm (4 inches) thick. They can be divided into two general categories; volatile and static. The first ever flat panel television was introduced in 1998 by Philips. In many applications, specifically modern portable devices such as laptops, cellular phones, and digital cameras, whatever disadvantages exist are made up for by the portability requirements. LCD A liquid crystal display (LCD) is a thin, flat electronic visual display that uses the light modulating properties of liquid crystals (LCs). LCDs have displaced cathode ray tube(CRT) displays in most applications. They are usually more compact, lightweight, portable, less expensive, more reliable, and easier on the eyes. They are available in a wider range of screen sizes than CRT and plasma displays, and since they do not use phosphors, they cannot suffer image burn-in. Its low electrical power consumption enables it to be used in battery-powered electronic equipment. PLASMA PANELS A panel typically has millions of tiny cells in compartmentalized space between two panels of glass.. With flow of electricity (electrons), some of the electrons strike mercury particles as the electrons move through the plasma, momentarily increasing the energy level of the molecule until the excess energy is shed. Depending on the phosphors used, different colors of visible light can be achieved. Each pixel in a plasma display is made up of three cells comprising the primary colors of visible light.
Part B
4. Implement DDA algorithm on graph for line drawing using values x1=60,y1=30 and x2=30 ,y2=60 for line 1 and x1=30,y1=30 and x2=60 ,y2=40for line 2? (find the point of intersection of two lines if they intersect? Ans void line (int x1,int y1,int x2,int y2) { int dx=x2-x1,dy=y2-y1,t,i; float xin ,yin ,x=x1,y=y1; if(abs(dx)>abs(dy)) { t=abs(dx); } else { t=abs(dy); } xin=dx/(float)t; yin=dy/(float)t; putpixel(round(x),round(y),2) for(i=0;i<t;i++) { x+=xincrement; y+=yincrement; putpixel(round(x),round(y),2); } }
FOR LINE 1: x1=60,y1=30 and x2=30 ,y2=60 dx=60-30=30; dy= 60-30=30; m=1=1 t=30 xin=30/30=1
yin=30/30=1
FOR LINE 2: x1=30,y1=30,x2=60,y2=40 dx=60-30=30; dy= 40-30=10; m=1/3<1 t=30 xin=30/30=1 yin=10/30=1/3
5. Scan convert the circle of radius 15 units using bresenham algorithm. Ans. #include<iostream.h> #include<conio.h> #include<graphics.h> #include<dos.h> void main() { int gd=DETECT,gm; initgraph(&gd,&gm,""); int x,y,d,tx,ty; int rd; cout<<"Enter radius:"; cin>>rd; cout<<"Enter the center:"; cin>>tx>>ty; x=0; y=r; d=3-2*rd; while(x<=y) { putpixel(x+tx,y+ty,1); putpixel(-x+tx,y+ty,2); putpixel(x+tx,-y+ty,3); putpixel(-x+tx,-y+ty,4); putpixel(y+ty,x+tx,5); putpixel(y+ty,-x+tx,6); putpixel(-y+ty,x+tx,7); putpixel(-y+ty,-x+tx,8); x++;
if(d<0) { d=d+4*x+6; } else { y--; d=d+4*(x-y)+10; } } getch(); } 6. Magnify the triangle with vertices A (0,0), B(1,1), C(6,3) to twice its size while keeping C(6,3) Fixed. Ans. Given: A (0, 0), B (1, 1), C (6, 3) As C (6, 3) is kept fixed, new co-ordinates could be referred as A(x, y) and B(x, y) Solution: By scaling formula, assuming z coordinate as constant we have A(x) = A(x) = A(x) = A(y) = A(y) = A(y) = B(x) = B(x) = B(x) = B(y) = B(y) = B(y) = xf+(x-xf)s 6+(0-6)2 -6 yf +(y-yf)s 3+(0-3)2 -3 xf +(x-xf)s 6+(1-6)2 -4 xf +(x-xf)s 3+(1-6)2 -1 ; f=fixed, s=magnifying size
A(x,y)=(-6,-3) , B(x,y)=(-4,-1) and C (6, 3) [fixed] , are the new points after magnifying the triangle by 2