GM Lab Manual

30
INFANT JESUS COLLEGE OF ENGINEERING KEELAVALLANADU Department of Computer Science & Engineering CS 1355 Graphics & Multimedia Lab Manual Prepared by R.Indrakumari

Transcript of GM Lab Manual

Page 1: GM Lab Manual

INFANT JESUS COLLEGE OF ENGINEERING

KEELAVALLANADU

Department of Computer Science & Engineering

CS 1355 Graphics & Multimedia Lab Manual

Prepared by

R.Indrakumari

Sr.Lecturer / CSE

Page 2: GM Lab Manual

CS1355 GRAPHICS AND MULTIMEDIA LAB

1. To implement Bresenham’s algorithms for line, circle and ellipse drawing

2. To perform 2D Transformations such as translation, rotation, scaling, reflection and sharing.

3. To implement Cohen-Sutherland 2D clipping and window-viewport mapping

4. To perform 3D Transformations such as translation, rotation and scaling.

5. To visualize projections of 3D images.

6. To convert between color models.

7. To implement text compression algorithm

8. To implement image compression algorithm

9. To perform animation using any Animation software

10. To perform basic operations on image using any image editing software

Page 3: GM Lab Manual

EX NO 1a BRESENHAM’S LINE DRAWING ALGORITHM

AIM

To write a C program to draw a line using Bresenham’s algorithm.

In Bresenham’s approach the pixel position along a line path are determined by sampling unit X intervals. Starting from the left end point(X0, Y0)of a given line we step to each successive columns and plot the pixel whose scan line Y-value is closest to the line path. Assuming the Kth step in process, determined that the pixel at(X k, Yk)decide which pixel to plot in column Xk+1.The choices are (Xk+1, Yk) and (Xk+1,Yk+1)

Algorithm

Step 1: Input the line endpoints and store the left endpoint in (X0, Y0)

Step 2: Load (X0, Y0) in to the frame buffer

Step 3: Calculate constants ∆x, ∆y, 2∆y, and 2∆y -2∆x, and obtain the decision parameters as

P0 = 2 ∆y – ∆x

Step 4 : At each Xk along the line, starting at k = 0, perform the following test.

If Pk < 0, the next point to plot is (Xk+1, Yk) and Pk+1 = Pk+2∆y

Otherwise, the next point to plot is (Xk+1, Yk+1) and

Pk+1 = Pk+2 ∆y - 2 ∆x

Step 5: Repeat step 4 ∆x times

Program#include"stdio.h"#include"conio.h"#include"stdlib.h"#include"graphics.h"#include"dos.h"#include"math.h"void main(){ int driver,mode,k; int xa,xb,ya,yb,dx,dy,x,y,i,p,dy2,dydx2; clrscr(); printf("\n\tEnter(xa,ya)..."); scanf("%d%d",&xa,&ya); printf("\n\tEnter(xb,yb)..."); scanf("%d%d",&xb,&yb); x=xa; y=ya; driver=DETECT; initgraph(&driver,&mode,""); dx=abs(xb-xa); dy=abs(yb-ya); p=(2*dy)-dx; dy2=2*dy;

Page 4: GM Lab Manual

dydx2=2*(dy-dx); line(100,0,100,500); line(0,100,500,100); putpixel(x,y,2); for(i=0;i<=dx;i++) { if(p<0) { x=x+1; putpixel(x,y,2); p+=dy2; } else { x=x+1; y=y+1; putpixel(x,y,2); p+=dydx2; } } getch();}output:

Enter(xa,ya)...100 100Enter(xb,yb)...250 252

EX NO 1b BRESENHAM’S CIRCLE DRAWING ALGORITHM

AIM

To write a C program to draw a circle using Bresenham’s algorithm.

Algorithm

Step 1:Input radius r and circle center(Xc, Yc)and obtain the first point on the circumference of a circle centered on the origin as (X0, Y0) = (0, r)

Step 2: Calculate the initial values of the decision parameter as P0 = 5/4 – r

Step 3: At each position starting at k perform the following test:

If Pk < 0, the next point to plot is (Xk+1, Yk) and Pk+1 = Pk+2 Xk+1 + 1

Otherwise the next point is (Xk+1, Yk-1) and Pk+1 = Pk+2 Xk+1 + 1- 2Yk+1 where 2Xk+1=2Xk+2 and 2Yk+1=2Yk-2

Step 4: Determine symmetry points in the other seven octants

Step 5: Move each pixel position(X, Y) onto the circular path centered on(Xc, Yc) and plot the coordinate values as X = X + Xc Y = Y + Yc

Step 6: Repeat steps 3 through until X>=Y

Page 5: GM Lab Manual

EX NO 2 2 -DIMENSIONAL TRANFORMATIONS

AIM

To perform the various 2-dimensional transformations such as translation, scaling, rotation, reflection and shearing.

Algorithm

Step 1: Input the figure.

Step 2: Display the menu as 1.Translation 2.Scaling 3.Rotation 4.Reflection 5.Shearing 6.Exit

Step 3: Get the choice from the user.

Step 4: If the choice is 1 get the translation vector. Add the translation vector to the original coordinate position to move to a new position.

Step 5: If the choice is 2 get the scaling factor. Multiply the coordinate values of each vertex by scaling factors to produce the transformed coordinates.

Step 6: If the choice is 3 get the rotation angle. Rotate the figure with respect to the specified angle.

Step 7: If the choice is 4 get the axis of reflection. Mirror image is generated relative to an axis of reflection by rotating the object 180◦ about the reflection axis.

Step 8: If the choice is 5 shearing is done which causes the transformation that distorts the shape of an object.

Step 9: If choice is 6 exit the program.

Program#include"stdio.h"#include"conio.h"#include"graphics.h"#include"math.h"int gd=0,gm,theta,xf,yf,x1,y1,x2,y2,xa1,xa2,ya1,ya2,a;int midx,midy,tx,ty,choice,sx,sy,sh,xa[10],ya[10],first;int i,n=5;int xf,yf;int xb[10],yb[10];void main(){ do { first=0; org(); getch(); printf("\n1.translation\n2.rotation\n3.scaling\n4.reflection\n5.shear\n6.exit\nenter ur choice\n"); scanf("%d",&choice); //input options switch(choice) { case 1: //translation printf("Enter the translation factor (x,y) :"); //get the factor (x,y) scanf("%d%d",&tx,&ty); org(); rectangle(midx+tx,midy-100+ty,midx+100+tx,midy+ty); //add with x,y

Page 6: GM Lab Manual

getch(); closegraph(); break; case 2: //rotation printf("Enter the angle :"); scanf("%d",&a); org(); rotation(); //call rotation function break; case 3: //scaling printf("Enter the scaling factor (x,y):"); //get the factor scanf("%d%d",&sx,&sy); org(); x1=0; y1=-100; x2=100;

y2=0; xa1=x1*sx+midx; //multiply with x,y ya1=y1*sy+midy; xa2=x2*sx+midx; ya2=y2*sy+midy; rectangle(xa1,ya1,xa2,ya2); getch(); closegraph(); break; case 4: //Reflection org(); rectangle(midx,midy,midx+100,midy+100); getch(); closegraph(); break; case 5: //Shear printf("enter the shear value"); scanf("%d",&sh); cleardevice(); org(); for(i=0;i < n;i++) //multiply with shear factor { xb[i]=xa[i]+sh*(ya[i]-yf); yb[i]=ya[i];   } for(i=0;i < n;i++) line(xb[i],yb[i],xb[(i+1)%n],yb[(i+1)%n]);   getch();  } }while(choice<6); getch();} org() { initgraph(&gd,&gm,""); midx=getmaxx()/2; midy=getmaxy()/2; xf=midx; yf=midy;

Page 7: GM Lab Manual

xa[0]=midx; ya[0]=midy-100; xa[1]=midx+100; ya[1]=midy-100; xa[2]=midx+100;

ya[2]=midy; xa[3]=midx; ya[3]=midy; xa[4]=midx; ya[4]=midy-100; cleardevice(); setcolor(WHITE); line(0,midy,2*midx,midy); line(midx,0,midx,2*midy); setcolor(4); if(first==0) { setlinestyle(SOLID_LINE,1,1); first=1; } else { setlinestyle(DASHED_LINE,1,1); } rectangle(midx,midy-100,midx+100,midy); setlinestyle(SOLID_LINE,1,1); return; } rotation() { theta=(a*2*3.14)/180; for(i=0;i < n;i++) { xb[i]=xf+(xa[i]-xf)*cos(theta)-(ya[i]-yf)*sin(theta); yb[i]=yf+(xa[i]-xf)*sin(theta)-(ya[i]-yf)*cos(theta); } for(i=0;i < n;i++) line(xb[i],yb[i],xb[(i+1)%n],yb[(i+1)%n]); getch(); cleardevice(); return; }

EX NO 3a COHEN-SUTHERLAND ALGORITHM

AIM:

To clip a line using Cohen-Sutherland clipping algorithm.

Algorithm:

The method speeds up the processing of line segments by performing initial tests that reduce the number of intersections that must be calculated.

Page 8: GM Lab Manual

1. Every line endpoint is assigned a four digit binary code, called region code, that identifies the location of the point relative to the boundaries of the clipping rectangle.

2. Each bit position in the region code is used to indicate one of the four relative coordinate positions of the point with respect to the clip window.

Bit 1: left

Bit 2: right

Bit 3: below

Bit 4: above

3. Bit values in the region code are determined by comparing endpoint coordinates values (x, y) with respect to the clip boundaries. eg.Bit 1 is set to 1 if x<xwmin

4. Once we have established region codes for all line endpoints, we can quickly determine which lines are completely outside or inside the clip window.

5. Lines that cannot be identified as completely inside or outside a clip window are checked for intersection with boundaries.

6. Intersection points with a clipping boundary can be calculated using the slope-intercept form of the line equation.

7. The y coordinate of the intersection point at vertical line

)( 11 xxmyy

8. The x coordinate of the intersection point at horizontal line

Program

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

void main()

{

int gd=DETECT, gm;

float i,xmax,ymax,xmin,ymin,x1,y1,x2,y2,m;

float start[4],end[4],code[4];

clrscr();

initgraph(&gd,&gm,"");

printf("\n\tEnter the bottom-left coordinate of viewport: ");

scanf("%f %f",&xmin,&ymin);

printf("\n\tEnter the top-right coordinate of viewport: ");

scanf("%f %f",&xmax,&ymax);

Page 9: GM Lab Manual

printf("\n\tEnter the coordinates for starting point of line: ");

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

printf("\n\tEnter the coordinates for ending point of line: ");

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

for(i=0;i<4;i++)

{

start[i]=0;

end[i]=0;

}

m=(y2-y1)/(x2-x1);

if(x1<xmin)

start[0]=1;

if(x1>xmax)

start[1]=1;

if(y1>ymax)

start[2]=1;

if(y1<ymin)

start[3]=1;

if(x2<xmin)

end[0]=1;

if(x2>xmax)

end[1]=1;

if(y2>ymax)

end[2]=1;

if(y2<ymin)

end[3]=1;

for(i=0;i<4;i++)

code[i]=start[i]&&end[i];

if((code[0]==0)&&(code[1]==0)&&(code[2]==0)&&(code[3]==0))

{

Page 10: GM Lab Manual

if((start[0]==0)&&(start[1]==0)&&(start[2]==0)&&(start[3]==0)&&

(end[0]==0)&&(end[1]==0)&&(end[2]==0)&&(end[3]==0))

{

cleardevice();

printf("\n\t\tThe line is totally visible\n\t\tand not a clipping candidate");

rectangle(xmin,ymin,xmax,ymax);

line(x1,y1,x2,y2);

getch();

}

else

{

cleardevice();

printf("\n\t\t\t\tLine is partially visible");

rectangle(xmin,ymin,xmax,ymax);

line(x1,y1,x2,y2);

getch();

if((start[2]==0)&&(start[3]==1))

{

x1=x1+(ymin-y1)/m;

y1=ymin;

}

if((end[2]==0)&&(end[3]==1))

{

x2=x2+(ymin-y2)/m;

y2=ymin;

}

if((start[2]==1)&&(start[3]==0))

{

x1=x1+(ymax-y1)/m;

y1=ymax;

Page 11: GM Lab Manual

}

if((end[2]==1)&&(end[3]==0))

{

x2=x2+(ymax-y2)/m;

y2=ymax;

}

if((start[1]==0)&&(start[0]==1))

{

y1=y1+m*(xmin-x1);

x1=xmin;

}

if((end[1]==0)&&(end[0]==1))

{

y2=y2+m*(xmin-x2);

x2=xmin;

}

if((start[1]==1)&&(start[0]==0))

{

y1=y1+m*(xmax-x1);

x1=xmax;

}

if((end[1]==1)&&(end[0]==0))

{

y2=y2+m*(xmax-x2);

x2=xmax;

}

clrscr();

cleardevice();

printf("\n\t\tAfter clippling:");

Page 12: GM Lab Manual

rectangle(xmin,ymin,xmax,ymax);

line(x1,y1,x2,y2);

getch();

}

}

else

{

clrscr();

cleardevice();

printf("\nLine is invisible");

rectangle(xmin,ymin,xmax,ymax);

}

getch();

closegraph();

}

OUTPUT:

Enter the bottom-left coordinate of viewport:50 50

Enter the top-right coordinate of viewport:200 200

Enter the coordinates for starting point of line:25 25

Enter the coordinates for ending point of line:220 220

Page 13: GM Lab Manual

EX NO 3b WINDOW TO VIEWPORT MAPPING

AIM:

To write a C program to perform Window to Viewport transformation.

Algorithm

Step1: Draw a world coordinate area selected for display called as window. This window defines what is to be viewed.

Step 2: Draw an area on a display device to which a window is mapped called as Viewport. The viewport defines where it is to be displayed.

Step 3: Now perform the mapping of a part of a world-coordinate scene to device coordinates referred as viewing transformation.

Program

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

#include<math.h>

main()

{

float sx,sy;

int w1,w2,w3,w4,x1,x2,x3,x4,y1,y2,y3,y4,v1,v2,v3,v4;

int gd=DETECT,gm;

initgraph(&gd,&gm,"C:/tc/bgi");

printf("Enter the Co-ordinates x1,y1,x2,y2,x3,y3\n");

scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3);

cleardevice();

w1=5;

w2=5;

w3=635;

w4=465;

rectangle(w1,w2,w3,w4);

line(x1,y1,x2,y2);

line(x2,y2,x3,y3);

Page 14: GM Lab Manual

getch();

v1=425;

v2=75;

v3=550;

v4=250;

sx=(float)(v3-v1)/(w3-w1);

sy=(float)(v4-v2)/(w4-w2);

rectangle(v1,v2,v3,v4);

x1=v1+floor(((float)(x1-w1)*sx)+0.5);

x2=v1+floor(((float)(x2-w1)*sx)+0.5);

x3=v1+floor(((float)(x3-w1)*sx)+0.5);

y1=v2+floor(((float)(y1-w2)*sy)+0.5);

y2=v2+floor(((float)(y2-w2)*sy)+0.5);

y3=v2+floor(((float)(y3-w2)*sy)+0.5);

line(x1,y1,x2,y2);

line(x2,y2,x3,y3);

line(x3,y3,x1,y1);

getch();

return 0;

}

Page 15: GM Lab Manual

EX NO 4 3-D TRANSFORMATIONS

AIM

To perform the various 3-dimensional transformations such as translation, scaling, rotation.

Algorithm

Step 1: Input the figure.

Step 2: Display the menu as 1.Translation 2.Scaling 3.Rotation 4.Exit

Step 3: Get the choice from the user.

Step 4: If the choice is 1 a point or an object is translated from position P to position P' with the operation P'=T.P where tx,ty and tz specifying translation distances.

x'=x+ tx

y'=y+ ty

z'=z+ tz

Step 5: If the choice is 2 the scaling transformation of a position P can be written as P'=S.P where scaling parameters sx,sy and sz are assigned any positive values.

x'=x.sx

y'=y.sy

z'=z.sz

Step 6: If the choice is 3 get the rotation angle. Rotate the figure with respect to the axis of rotation.

Step 6a: About z axis rotation

x'=xcosӨ-ysinӨ

y'=xsinӨ+ycosӨ

z'=z

Rotation can be expressed as P'=Rz(Ө).P

Step 6b: About x axis rotation

y'=ycosӨ-zsinӨ

z'=ysinӨ+zcosӨ

x'=x

Rotation can be expressed as P'=Rx(Ө).P

Page 16: GM Lab Manual

Step 6c: About y axis rotation

z'=zcosӨ-xsinӨ

x'=zsinӨ+xcosӨ

y'=y

Rotation can be expressed as P'=Ry(Ө).P

Step 7: If choice is 4 exit the program.

Program

#include <stdio.h>

#include <stdlib.h>

#include<graphics.h>

#include<conio.h>

#include<math.h>

#define yorg getmaxy()-100

#define xorg 100

void draw3d(int s,int x[20],int y[20],int d);

int x[20],y[20],x1[20],y1[20],tx,ty,sx,sy,sz,i,s,d;

void main()

{

int gd=DETECT,gm,ch,a,theta;

initgraph(&gd,&gm,"");

printf("\tEnter the No of sides : ");

scanf("%d",&s);

for(i=0;i<s;i++)

{

printf("\t(x%d , y%d) :",i,i);

scanf("%d%d",&x[i],&y[i]);

}

printf("\tDepth :");

scanf("%d",&d);

clrscr();

Page 17: GM Lab Manual

cleardevice();

axis();

setcolor(RED);

draw3d(s,x,y,d);

getch();

do

{

clrscr();

cleardevice();

setcolor(WHITE);

printf("\t\t\t3D TRANSFORMATIONS \n");

printf("\t1.TRANSLATION\n\t2.SCALING\n\t3.ROTATION\n\t4.EXIT\n\tENTER YOUR CHOICE :");

scanf("%d",&ch);

switch(ch)

{

case 1:

printf("\tEnter the translation factor (tx,ty) :");

scanf("%d%d",&tx,&ty);

clrscr();

cleardevice();

axis();

setcolor(RED);

draw3d(s,x,y,d);

getch();

cleardevice();

for(i=0;i<s;i++)

{

x1[i]=x[i]+tx;

y1[i]=y[i]+ty;

}

Page 18: GM Lab Manual

axis();

setcolor(DARKGRAY);

setlinestyle(DASHED_LINE,1,1);

draw3d(s,x,y,d);

setlinestyle(SOLID_LINE,1,1);

setcolor(RED);

draw3d(s,x1,y1,d);

getch();

break;

case 2:

printf("\tEnter the Scaling factor (sx,sy,sz) :");

scanf("%d%d%d",&sx,&sy,&sz);

clrscr();

cleardevice();

axis();

setcolor(RED);

draw3d(s,x,y,d);

getch();

cleardevice();

for(i=0;i<s;i++)

{

x1[i]=x[i]*sx;

y1[i]=y[i]*sy;

}

axis();

setcolor(DARKGRAY);

setlinestyle(DASHED_LINE,1,1);

draw3d(s,x,y,d);

setlinestyle(SOLID_LINE,1,1);

setcolor(RED);

Page 19: GM Lab Manual

draw3d(s,x1,y1,sz*d);

getch();

break;

case 3:

printf("\tRotation angle :");

scanf("%d",&a);

clrscr();

cleardevice();

axis();

setcolor(RED);

draw3d(s,x,y,d);

getch();

cleardevice();

theta=(a*2*3.14)/180;

for(i=0;i<s;i++)

{

x1[i]=x[0]+((x[i]-x[0])*cos(theta))-((y[i]-y[0])*sin(theta));

y1[i]=y[0]+((y[i]-y[0])*cos(theta))+((x[i]-x[0])*sin(theta));

}

axis();

setcolor(DARKGRAY);

setlinestyle(DASHED_LINE,1,1);

draw3d(s,x,y,d);

setlinestyle(SOLID_LINE,1,1);

setcolor(RED);

draw3d(s,x1,y1,d);

getch();

break;

default :

break;

Page 20: GM Lab Manual

}

}while(ch<4);

closegraph();

}

axis()

{

setcolor(WHITE);

line(100,0,100,getmaxy()-100);

outtextxy(90,10,"x");

line(100,getmaxy()-100,getmaxx(),getmaxy()-100);

outtextxy(getmaxx()-10,getmaxy()-110,"y");

line(100,getmaxy()-100,0,getmaxy());

outtextxy(10,getmaxy()-10,"z");

return;

}

void draw3d(int s,int x[20],int y[20],int d)

{

int i,j,k=0;

for(j=0;j<2;j++)

{

for(i=0;i<s-1;i++)

{

line(x[i]+xorg-k,yorg-y[i]+k,x[i+1]+xorg-k,yorg-y[i+1]+k);

}

line(x[i]+xorg-k,yorg-y[i]+k,x[0]+xorg-k,yorg-y[0]+k);

k=d;

}

for(i=0;i<s;i++)

{

line(x[i]+xorg,yorg-y[i],x[i]+xorg-d,yorg-y[i]+d);

Page 21: GM Lab Manual

}

}

OUTPUT:

Enter the No of sides :4

(x0 , y0):100 100

(x1 , y1):200 100

(x2, y2) :200 200

(x3 , y3):100 200

Depth : 45

ENTER THE CHOICE :1

Enter the translation factor (tx,ty) :15 15

ENTER THE CHOICE :2

Enter the Scaling factor (sx,sy,sz) :2 1 1

ENTER THE CHOICE :3

Rotation angle :75

EX NO 5 PROJECTIONS OF 3D IMAGES

AIM

To write a C program to show the perspective projection of a 3D image.

Algorithm

Step1: Get the coordinates to draw the cube.

Step 2: Read the reference point.

Step 3: Read the view plane.

Step 4: For a perspective projection object positions are transformed to the view plane along lines that converge to a point called the projection reference point.

Step 5: The projected view of an object is determined by calculating the intersection point of the projection lines with the view plane.

Program

#include <stdio.h>

#include <stdlib.h>

#include<graphics.h>

Page 22: GM Lab Manual

#include<conio.h>

void draw3d(int s,int x[20],int y[20],int d);

void main()

{

int gd=DETECT,gm;

int x[20],y[20],i,s,d;

initgraph(&gd,&gm,"");

printf("Enter the No of sides : ");

scanf("%d",&s);

for(i=0;i<s;i++)

{

printf("(x%d,y%d) :",i,i);

scanf("%d%d",&x[i],&y[i]);

}

printf("Depth :");

scanf("%d",&d);

draw3d(s,x,y,d);

getch();

setcolor(14);

for(i=0;i<s-1;i++)

{

line(x[i]+200,y[i],x[i+1]+200,y[i+1]);

}

line(x[i]+200,y[i],x[0]+200,y[0]);

getch();//top view

for(i=0;i<s-1;i++)

{

line(x[i],300,x[i+1],300);

line(x[i],300+d*2,x[i+1],300+d*2);

line(x[i],300,x[i],300+d*2);

Page 23: GM Lab Manual

line(x[i+1],300,x[i+1],300+d*2);

}

getch();//side view

for(i=0;i<s-1;i++)

{

line(10,y[i],10,y[i+1]);

line(10+d*2,y[i],10+d*2,y[i+1]);

line(10,y[i],10+d*2,y[i]);

line(10,y[i+1],10+d*2,y[i+1]);

}

getch();

closegraph();

}

void draw3d(int s,int x[20],int y[20],int d)

{

int i,j,k=0;

for(j=0;j<2;j++)

{

for(i=0;i<s-1;i++)

line(x[i]+k,y[i]-k,x[i+1]+k,y[i+1]-k);

line(x[i]+k,y[i]-k,x[0]+k,y[0]-k);

k=d;

}

for(i=0;i<s;i++)

line(x[i],y[i],x[i]+d,y[i]-d);

}

Page 24: GM Lab Manual

EX NO 6 RGB TO HSV COLOR MODEL

Aim

To implement the color models using c/c++ program RGB Color in C program CS1355-Graphics & Multimedia Lab

Algorithm

Start the program for Color ModelInclude the necessary packageGet the character by through getche() functionDepends upon there key value increase there RGB range in appropriate rectangular boxUsing the following functionsetrgbpalette(1,R,G,B);setfillstyle(1);bar(x,y,x1,y2);Rectangle(x1,y1,x2,y2);Draw the color modelFinally terminate the color model program

Page 25: GM Lab Manual

Program

#include<stdio.h>#include<conio.h>#include<graphics.h>#include<stdlib.h>void main(){int gd=DETECT,gm,n;float r=0,g=0,b=0;float y=0,i=0,q=0;float c=0,m=0,y1=0;initgraph(&gd,&gm,"");printf("(r,g,b)keys for incrementing R,G,B values respectively\n");printf("(shift+(r,g,b))keys for decrementing R,G,B values respectively\n");printf("press esc to exit\n");setcolor(15);while(1){gotoxy(18,10);printf("R G B");c=1.0-r;m=1.0-g;y1=1.0-y;gotoxy(47,10);printf("C M Y");y=0.299*r+0.587*g+0.144*b;i=0.596*r-0.275*g-0.3218*b;q=0.212*r-0.528*g+0.311*b;gotoxy(18,23);printf("Y I Q");switch(getche()){case 'r':r++;break;case 'g':g++;break;case 'b':b++;break;case 'R':r--;break;case 'G':g--;break;case 'B':b--;break;case 27:closegraph();

Page 26: GM Lab Manual

exit(0);}if(r>255)r=0;if(g>255)g=0;if(b>255)b=0;setrgbpalette(1,r,g,b);setfillstyle(1,1);bar(50,50,270,250);rectangle(50,50,270,250);setrgbpalette(2,c,m,y1);setfillstyle(1,2);bar(275,50,495,250);rectangle(275,50,495,250);setrgbpalette(3,y,i,q);setfillstyle(1,3);bar(50,255,270,455);rectangle(50,255,270,455);}}Output color model in RGB color Red, Green Blue