0% found this document useful (0 votes)
26 views18 pages

P Graph

The document provides an overview of computer graphics, including its definition, applications, and characteristics. It explains the difference between active and passive graphics, describes raster-scan and random-scan displays, and outlines various graphics programming concepts and functions in C. Additionally, it includes sample programs for drawing lines, circles, and other shapes using different algorithms.

Uploaded by

Ravan Kumar
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)
26 views18 pages

P Graph

The document provides an overview of computer graphics, including its definition, applications, and characteristics. It explains the difference between active and passive graphics, describes raster-scan and random-scan displays, and outlines various graphics programming concepts and functions in C. Additionally, it includes sample programs for drawing lines, circles, and other shapes using different algorithms.

Uploaded by

Ravan Kumar
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/ 18

What is Graphics and types of Graphic ,difference between Ac ve and Passive Graphics?

Ans. Computer graphics is an art of drawing pictures, lines, charts, etc using computers with the help of
programming. Computer graphics is made up of number of pixels. Pixel is the smallest graphical picture or unit
represented on the computer screen. It involves computa ons, crea on, and manipula on of data. In other words,
we can say that computer graphics is a rendering tool for the genera on and manipula on of images.

Difference between Ac ve and Passive Graphics are

Applica on of Graphics also its characteris cs of computer graphics

Applica on of computer graphics or Use of computer graphics:-

- Presenta on Graphics

- Computer Art

- Entertainment

- Visualiza on

- Image Processing

1. User interface:- it is now well established fact that graphical interface provide an a rac ve and easy interac on
between users and computer. The built in graphics provide a graphical interface for user. User to interact with
computer only by mouse clicking. Typing is necessary only to input text to be stored and manipulated.

2. Plo ng of graphs and chart: -

In industry, business, government and educa onal organiza on computer graphics is most commonly used to create
2D and 3D graphs mathema cal. Physical and economics func on is form of histogram bars and pie charts. These
graphs and charts are very useful for decision making.
3. Computer aided dra ing and design:- the computer aided dra ing uses graphics to design components and
system electrical, mathema cal, electromechanical and electronic device such as automobile bodies, structure of
building , air plane, ships, very large scale integrated chips and computer networks.

4. Simula on and Anima on :- Use of graphics in simula on makes mathema cal model and mechanical systems
more realis c and easy to study. The interac ve graphics supported by anima on so ware proved the best use in
produc on of anima on movies and cartoon films.

Characteris cs of computer Graphics:-

1. It has to be interac ve.

2. It has to be user friendly.

3. Dynamics.

a. Mo on dynamics: Deals with how the objects going to move.

b. Update dynamics: Deals with what changes the object is going to undergo.

4. Anima ons

Q 3. Define the terms:

Resolu on
Refresh rate
Electron gun
Aspect Ra o

Persistence

Ans. Resolu on:- The maximum number of points /characters that can be displayed without overlap on the screen is
referred to as the resolu on.

- Text mode: - 80 Co

Refresh rate:

The term refresh rate refers to how many mes per second your monitor can display a new image

Electron gun: The primary components of an electron gun in CRT are the heated metal cathode and control grid.
Heat is supplied to the cathode by direc ng a current through a coil of wire called the filament, inside the cylindrical
cathode structure. This cause electrons to be “boiled of” the cathode surface. In the vacuum inside the CRT
envelope, the free nega vely charged electrons are then accelerated toward the phosphor coa ng by a high posi ve
voltage. The accelera ng voltage can be generated with a posi vely charged metal coa ng on the inside of the CRT
envelope near the phosphor screen, or an accelera ng anode can be used.

Aspect ra o:- it is the ra o of ver cal to horizontal points necessary to produce equal lengh in line in both direc ons
on the screen.

Persistence - it is defined as the me they con nue to emit light a er the CRT beam is removed. Persistence is
defined as the me it takes the emi ed light from the screen to decay to one tenth of its original intensity. Lower
persistence phosphors require higher refresh rates to maintain a picture on the screen without flicker. A phosphors
with low persistence is useful for anima on. A high persistence phosphor is useful useful for displaying highly
complex, sta c pictures. Although some phosphor have a persistence greater than 1 second, graphics monitor are
usually constructed with a persistence in the range from 10 to 60 microseconds.
Define Raster Scan display and Random Scan Display and differen ate between them.

Ans. 1. Raster –Scan display:- it is based on television technology. In a Raster –Scan system the electron beam is
swept across the screen, one row at a me from top to bo om. As the electron beam moves across each row, the
beam intensity is turned on and off to create a pa ern of illuminated spots. Picture defini on is stored in a memory
are called the refresh buffer or frame buffer. This memory area holds the set of intensity values for all the screen
points. Stored intensity values are then retrieved from the refresh buffer and “painted” on the screen one row (Scan
line) at a me. Each screen point is referred as pixel or pel. Shortened form of picture element. At the end of each
scan line the electron beam returns to the le side of the screen to begin displaying the next scan line. And at the
end it returns to top le corner of the screen.

Printers are also the example of Raster –Scan system.

1. Random –scan display:- in this technique the electron beam is directed only to the part of screen where the
picture is to be drawn rather than scanning from le to right and top to bo om as in raster scan. It is also called
vector display, stroke- wri ng display or Calligraphic display. Picture difini on is now stored as a set of line
drawing commands in an area of memory reffered to as the refresh display file. Some mes the refresh display
file is called the display list, display program or simplay the refresh buffer. To display a specified picture, the
system cycles through the set of commands in display file, drawing each component line in turn. All the line
drawing command are processed, the system cycles back to the first line command in the list. Random- scan
displays are designed to draw all the component lines of picture 30 to 60 mes each second. Random scan
monitors draw a picture one line at a me and for this reason are reffered to as vector. Advantages
Colored CRT Monitor:

The CRT Monitor display by using a combina on of phosphors. The phosphors are different colors. There are two
popular approaches for producing color displays with a CRT are:

1. Beam Penetra on Method

2. Shadow-Mask Method

Beam Penetration Method:

The Beam-Penetration method has been used with random-scan monitors. In this method,
the CRT screen is coated with two layers of phosphor, red and green and the displayed color
depends on how far the electron beam penetrates the phosphor layers. This method produces
four colors only, red, green, orange and yellow. A beam of slow electrons excites the outer
red layer only; hence screen shows red color only. A beam of high-speed electrons excites
the inner green layer. Thus screen shows a green color.

Shadow-Mask Method:
o Shadow Mask Method is commonly used in Raster-Scan System because they produce a
much wider range of colors than the beam-penetration method.
o It is used in the majority of color TV sets and monitors.

Direct view storage tube and Random Scan System ?


The direct-view storage tube is nor- mainly used to display informa on stored on the screen. In that mode,
the wri ng gun's beam scans (i.e. writes on) the target, crea ng a charge that is posi ve rela ve to the
flood-gun electrons, and thereby causing the phosphor to luminesce.
Random-scan system

In a random scan system, an applica on and graphics package are stored in memory, and graphics commands are
translated into a display file that a display processor accesses to refresh the screen.

What are the following terms:

 Graphics .h
 Graphics driver
 Graphics mode
 Init graph
 BGI
 Close graph
 DETECT

Ans. Graphics .h

The graphics. h header file provides access to a simple graphics library that makes it possible to draw lines,
rectangles, ovals, arcs, polygons, images, and strings on a graphical window.

Graphics driver

Graphics Driver: It is a pointer to an integer specifying the graphics driver to be used. It tells the compiler that what
graphics driver to use or to automa cally detect the drive.

Initgraph
The “initgraph” func on is used to ini alize the display into graphics mode. This func on is a part of the “graphics. h”
header file. So this file is included in the program before execu ng “initgraph” func on.

BGI (Borland Graphics Interface)

BGI was a C/C++ graphics library for the Borland compilers.

Close graph

The header file graphics. h contains closegraph() func on which closes the graphics mode, deallocates all memory
allocated by graphics system and restores the screen to the mode it was in before you called initgraph

Detect

Detects your system's graphics adapter and chooses the mode that provides the highest resolu on for that adapte

WAP in C to construct a line by Direct method ?

Ans. Program to draw a line by direct method using equa on y = mx+c.

#include<stdio.h>

#include<graphics.h>

#include<stdlib.h>

#include<math.h>

void main()

float x,y,x1,y1,x2,y2,dx,dy,m,xe,c;

int gdriver=DETECT,gmode;

initgraph(&gdriver,&gmode,"C:\\turboc3\\bgi");

prin ("enter the star ng point");

scanf("%f%f",&x1,&y1);

prin ("ener the ending point");

scanf("%f%f",&x2,&y2);

dx=x2-x1;

dy=y2-y1;

m=dy/dx;

if(dx>0)

x=x1;

y=y1;

xe=x2;
}

else if(dx<0)

x=x2;

y=y2; xe=x1;

c=y-m*x;

while(x<=xe)

putpixel(x,y,WHITE);

x=x+1;

y=m*x+c;

getch();

closegraph();

WAP in C to construct a line by DDA

Program of DDA Line Drawing algorithm

#include<stdio.h>

#include<graphics.h>

#include<stdlib.h>

#include<conio.h>

#include<math.h>

void main()

{ int x1,y1,x2,y2,i;

float x,y,dx,dy,length;

int gd=DETECT,gm;

prin ("enter the star ng point");

scanf("%d%d",&x1,&y1);

prin ("ener the ending point");

scanf("%d%d",&x2,&y2);
initgraph(&gd,&gm,"C:\\turboc3\\bgi");

if(abs(x2-x1)>abs(y2-y1))

length=abs(x2-x1);

else

length=abs(y2-y1);

dx=(x2-x1)/length;

dy=(y2-y1)/length; x=x1;

y=y1;

i=0;

while(i<=length)

putpixel(x,y,WHITE);

x=x+dx;

y=y+dy;

i++;

getch();

closegraph();

WAP of Bresenham’s line drawing algorithm

#include<stdio.h>

#include<graphics.h>

#include<stdlib.h>

#include<conio.h>

#include<math.h>

void main()

int x,y,x1,y1,x2,y2,dx,dy,p,i;

int gdriver=DETECT,gmode;

prin ("enter the first point");

scanf("%d%d",&x1,&y1);

prin ("enter the second point");

scanf("%d%d",&x2,&y2);
clrscr();

initgraph(&gdriver,&gmode,"C:\\turboc3\\bgi");

dx=x2-x1;

dy=y2-y1;

p=2*dy-dx;

x=x1; y=y1;

i=0;

while(i<=dx)

putpixel(x,y,WHITE);

delay(100);

if(p<0)

x=x+1;

p=p+2*dy;

else

x=x+1;

y=y+1;

p=p+2*dy-2*dx;

i++;

getch();

closegraph();

WAP in C to construct a circle using Bresenham’s circle ?

#include<stdio.h>

#include<graphics.h>

#include<stdlib.h>

#include<conio.h>

#include<math.h>
void main()

int gdriver=DETECT,gmode;

int x,y,xc,yc,r,d;

initgraph(&gdriver,&gmode,"C:\\turboc3\\bgi");

prin (“ enter the centre of point of the circle);

scanf(“%d%d”,&xc,&yc);

prin (“ enter the radius of the circle);

scanf(“%d” ,&r);

d=3-2*r;

x=0;

y=r;

while(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 );

putpixel( y+xc , x+yc, WHITE );

putpixel( y+xc , -x+yc ,WHITE );

putpixel( -y+xc , -x+yc ,WHITE );

putpixel(-y+xc , x+yc ,WHITE );

if(d<=0)

d=d+4*x+6;

else

d=d+4*(x-y)+10;
y=y-1;

x=x+1;

getch();

closegraph();

WAP in C to construct a mid-point circle ?

#include<stdio.h>

#include<graphics.h>

#include<stdlib.h>

#include<conio.h>

#include<math.h>

void main()

int gdriver=DETECT,gmode;

int x,y,xc,yc,r,d;

initgraph(&gdriver,&gmode,"C:\\turboc3\\bgi");

prin (“ enter the centre of point of the circle);

scanf(“%d%d”,&xc,&yc);

prin (“ enter the radius of the circle);

scanf(“%d” ,&r);

p=1-r;

x=o;

y=r;
while (x<=y)

putpixel( x+xc, y+yc ,WHITE );

putpixel( -x+xc, -y+yc ,WHITE );

putpixel( y+xc , -x+yc ,WHITE );

putpixel( -y+xc , -x+yc ,WHITE );

putpixel( y+xc , x+yc, WHITE );

putpixel(-y+xc , x+yc ,WHITE );

if(p<=0)

p=p+2*x+1;

else

p=p+2*(x-y)+5;

y=y-1;

x=x+1;

getch()

closegraph();

WAP to show a circle in a program ?


WAP to show a
pixel in a program ?

#include<stdio.h>

#include<graphics.h>

#include<stdlib.h>

#include<math.h>

void main()

float x,y,x1,y1,x2,y2,dx,dy,m,xe,c;

int gdriver=DETECT,gmode;

initgraph(&gdriver,&gmode,"C:\\turboc3\\bgi");

putpixel(100,300,WHITE);

getch();

closegraph();

WAP to show rectangle in a program ?

#include<stdio.h>

#include<graphics.h>

#include<stdlib.h>

#include<math.h>

void main()

float x,y,x1,y1,x2,y2,dx,dy,m,xe,c;
int gdriver=DETECT,gmode;

initgraph(&gdriver,&gmode,"C:\\turboc3\\bgi");

rect(100,100,200,200);

getch();

closegraph();

WAP to show line in a program ?

#include<stdio.h>

#include<graphics.h>

#include<stdlib.h>

#include<math.h>

void main()

float x,y,x1,y1,x2,y2,dx,dy,m,xe,c;

int gdriver=DETECT,gmode;

initgraph(&gdriver,&gmode,"C:\\turboc3\\bgi");

line(100,100,100,300);

getch();

closegraph();

WAP to show arc in a program ?

#include<stdio.h>

#include<graphics.h>

#include<stdlib.h>

#include<math.h>

void main()

float x,y,x1,y1,x2,y2,dx,dy,m,xe,c;

int gdriver=DETECT,gmode;

initgraph(&gdriver,&gmode,"C:\\turboc3\\bgi");

arc(100,100,0,90,50);
getch();

closegraph();

ASSIGNMENT OF GRAPHICS
Ellipse genera ng:

Ellipse func on is used to draw an ellipse with centre (x,y) and stangle specifics star ng angle end angle specifics the
end angle and fifith and sixth parameter specifics the x and y radius of the ellipse .

Syntax : void ellipse ( int x, int y ,int stangle , int end angle, int xradius ,int yradius );

Ellipse(200,200,0,360,50,25);

2D Transla on :

In 2D transla on mean a original shape of polygon ca replace on pos on to another posi on or simply we can say
that re -posi on of original shape of polygon .

2D Scaling :

In this case we see that shape of polygon can increase and decrease according to our need .

Condi on for small , big and original shape

Sx,Sy >1 ( increasing order )

Sx,Sy<1( decreasing order )

Sx,Sy=1(original or same )

Sx,Sy >1 ( increasing order )


Sx,Sy<1( decreasing order )

Sx,Sy=1(original or same )

2D Rota on :

In 2D rota on we can change the posi on of any polygon through angle like ACW and CW

Back -face detec on :

It is an object space method for back face or hidden surface detec on & removal .

Consider a polyhedron & perform inside – outside test .


P(x,y,z)

A point p(x,y,z) is inside or polygon surface with plane parameter A,B<C & D

If Ax+By+Cz+D<0 ( inside)

Ax+By+Cz+D>0 ( outside)

Ax+By+Cz+D=0 ( no change)

Depth buffer:

Image space approach { implemented in screen coordina on system }

The basic idea is to test depth of each surface to determine the closest ( Visible surface )

1. Frame buffer 2. Depth buffer

To overside the closer polygon from the far ones two buffer named .

You might also like