You are on page 1of 49

Lab 9:

#include<iostream>

#include<graphics.h>

#include<math.h>

#include<dos.h>

void liangbarsky(int a1, int b1, int a2, int b2)

int x1,y1,x2,y2,i;

int xx1,xx2,yy1,yy2,dx,dy;

float t1,t2,p[4],q[4],temp;

int xmin,xmax,ymin,ymax;

xmin=60;

ymin=40;

xmax=140;

ymax=100;

x1=a1;

y1=b1;

x2=a2;

y2=b2;

dx=x2-x1;

dy=y2-y1;

p[0]=-dx;

p[1]=dx;

p[2]=-dy;

p[3]=dy;
q[0]=x1-xmin;

q[1]=xmax-x1;

q[2]=y1-ymin;

q[3]=ymax-y1;

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

if(p[i]==0)

//cout<<"line is parallel to one of the clipping boundary";

if(q[i]>=0)

if(i<2)

if(y1<ymin)

y1=ymin;

if(y2>ymax)

y2=ymax;

line(x1,y1,x2,y2);

if(i>1)

{
if(x1<xmin)

x1=xmin;

if(x2>xmax)

x2=xmax;

line(x1,y1,x2,y2);

t1=0;

t2=1;

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

temp=q[i]/p[i];

if(p[i]<0)

if(t1<=temp)

t1=temp;

else

{
if(t2>temp)

t2=temp;

if(t1<t2)

xx1 = x1 + t1 * p[1];

xx2 = x1 + t2 * p[1];

yy1 = y1 + t1 * p[3];

yy2 = y1 + t2 * p[3];

setcolor(RED);

line(xx1,yy1,xx2,yy2);

delay(2000);

int main()

int gd=DETECT,gm;

initgraph(&gd,&gm,"c:\\turboc3\\bgi");

int xmin,xmax,ymin,ymax;

xmin=60;

ymin=40;

xmax=140;

ymax=100;

rectangle(xmin,ymin,xmax,ymax);
rectangle(5,5,190,150);

//original lines

line(70,80,80,60);

line(110,60,130,20);

line(10,65,40,10);

line(75,120,160,45);

line(120,140,170,80);

delay(2000);

//clipped lines

liangbarsky(70,80,80,60);

liangbarsky(110,60,130,20);

liangbarsky(10,65,40,10);

liangbarsky(75,120,160,45);

liangbarsky(120,140,170,80);

getch();

closegraph();

return 0;

Lab 8:
include <bits/stdc++.h>

#include <graphics.h>

using namespace std;

// Global Variables

int xmin, xmax, ymin, ymax;

// Lines where co-ordinates are (x1, y1) and (x2, y2)


struct lines {

int x1, y1, x2, y2;

};

// This will return the sign required.

int sign(int x)

if (x > 0)

return 1;

else

return 0;

// CohenSutherLand LineClipping Algorithm As Described in theory.

// This will clip the lines as per window boundaries.

void clip(struct lines mylines)

// arrays will store bits

// Here bits implies initial Point whereas bite implies end points

int bits[4], bite[4], i, var;

// setting color of graphics to be RED

setcolor(RED);

// Finding Bits

bits[0] = sign(xmin - mylines.x1);

bite[0] = sign(xmin - mylines.x2);

bits[1] = sign(mylines.x1 - xmax);

bite[1] = sign(mylines.x2 - xmax);


bits[2] = sign(ymin - mylines.y1);

bite[2] = sign(ymin - mylines.y2);

bits[3] = sign(mylines.y1 - ymax);

bite[3] = sign(mylines.y2 - ymax);

// initial will used for initial coordinates and end for final

string initial = "", end = "", temp = "";

// convert bits to string

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

if (bits[i] == 0)

initial += '0';

else

initial += '1';

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

if (bite[i] == 0)

end += '0';

else

end += '1';

// finding slope of line y=mx+c as (y-y1)=m(x-x1)+c

// where m is slope m=dy/dx;

float m = (mylines.y2 - mylines.y1) / (float)(mylines.x2 - mylines.x1);

float c = mylines.y1 - m * mylines.x1;

// if both points are inside the Accept the line and draw

if (initial == end && end == "0000") {


// inbuild function to draw the line from(x1, y1) to (x2, y2)

line(mylines.x1, mylines.y1, mylines.x2, mylines.y2);

return;

// this will contain cases where line maybe totally outside for partial

else {

// taking bitwise end of every value

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

int val = (bits[i] & bite[i]);

if (val == 0)

temp += '0';

else

temp += '1';

// as per algo if AND is not 0000 means line is completely outside

if (temp != "0000")

return;

// Here contain cases of partial inside or outside

// So check for every boundary one by one

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

// if boths bit are same hence we cannot find any

if (bits[i] == bite[i])

continue;

// Otherwise there exist a intersection


// Case when initial point is in left xmin

if (i == 0 && bits[i] == 1) {

var = round(m * xmin + c);

mylines.y1 = var;

mylines.x1 = xmin;

// Case when final point is in left xmin

if (i == 0 && bite[i] == 1) {

var = round(m * xmin + c);

mylines.y2 = var;

mylines.x2 = xmin;

// Case when initial point is in right of xmax

if (i == 1 && bits[i] == 1) {

var = round(m * xmax + c);

mylines.y1 = var;

mylines.x1 = xmax;

// Case when final point is in right of xmax

if (i == 1 && bite[i] == 1) {

var = round(m * xmax + c);

mylines.y2 = var;

mylines.x2 = xmax;

// Case when initial point is in top of ymin


if (i == 2 && bits[i] == 1) {

var = round((float)(ymin - c) / m);

mylines.y1 = ymin;

mylines.x1 = var;

// Case when final point is in top of ymin

if (i == 2 && bite[i] == 1) {

var = round((float)(ymin - c) / m);

mylines.y2 = ymin;

mylines.x2 = var;

// Case when initial point is in bottom of ymax

if (i == 3 && bits[i] == 1) {

var = round((float)(ymax - c) / m);

mylines.y1 = ymax;

mylines.x1 = var;

// Case when final point is in bottom of ymax

if (i == 3 && bite[i] == 1) {

var = round((float)(ymax - c) / m);

mylines.y2 = ymax;

mylines.x2 = var;

// Updating Bits at every point

bits[0] = sign(xmin - mylines.x1);


bite[0] = sign(xmin - mylines.x2);

bits[1] = sign(mylines.x1 - xmax);

bite[1] = sign(mylines.x2 - xmax);

bits[2] = sign(ymin - mylines.y1);

bite[2] = sign(ymin - mylines.y2);

bits[3] = sign(mylines.y1 - ymax);

bite[3] = sign(mylines.y2 - ymax);

} // end of for loop

// Initialize initial and end to NULL

initial = "", end = "";

// Updating strings again by bit

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

if (bits[i] == 0)

initial += '0';

else

initial += '1';

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

if (bite[i] == 0)

end += '0';

else

end += '1';

// If now both poits lie inside or on boundary then simply draw


if (initial == end && end == "0000") {

line(mylines.x1, mylines.y1, mylines.x2, mylines.y2);

return;

// else line was completely outside hence rejected

else

return;

// Driver Function

int main()

int gd = DETECT, gm;

// Setting values of Clipping window

xmin = 100;

xmax = 200;

ymin = 120;

ymax = 200;

// initialize the graph

initgraph(&gd, &gm, NULL);

// Drawing Window using Lines

line(xmin, ymin, xmax, ymin);

line(xmax, ymin, xmax, ymax);

line(xmax, ymax, xmin, ymax);

line(xmin, ymax, xmin, ymin);


// Assume 4 lines to be clipped

struct lines mylines[5];

// Setting the coordinated of 4 lines

mylines[0].x1 = 110;

mylines[0].y1 = 160;

mylines[0].x2 = 160;

mylines[0].y2 = 140;

mylines[1].x1 = 55;

mylines[1].y1 = 175;

mylines[1].x2 = 80;

mylines[1].y2 = 130;

mylines[2].x1 = 75;

mylines[2].y1 = 190;

mylines[2].x2 = 135;

mylines[2].y2 = 180;

mylines[3].x1 = 160;

mylines[3].y1 = 210;

mylines[3].x2 = 220;

mylines[3].y2 = 170;

mylines[4].x1 = 170;

mylines[4].y1 = 70;

mylines[4].x2 = 240;

mylines[4].y2 = 115;

// Drawing Initial Lines without clipping

for (int i = 0; i < 5; i++) {


line(mylines[i].x1, mylines[i].y1,

mylines[i].x2, mylines[i].y2);

delay(1000);

// Drawing clipped Line

for (int i = 0; i < 5; i++) {

// Calling clip() which in term clip the line as per window and draw

clip(mylines[i]);

delay(1000);

delay(4000);

getch();

// For Closing the graph.

closegraph();

return 0;

Lab7:
#include<graphics.h>

#include<conio.h>

#include<stdio.h>

int main ()

int W_xmax, W_ymax, W_xmin, W_ymin;

int V_xmax, V_ymax, V_xmin, V_ymin;


float sx, sy;

int x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18,x19,x20,x21,x22;

int y1,y2,y3,y4,y5,y6,y7,y8,y9,y10,y11,y12,y13,y14,y15,y16,y17,y18,y19,y20,y21,y22;

x1=60;

x2=140;

x3=220;

x4=300;

x5=300;

x6=220;

x7=140;

x8=60;

x9=120;

x10=55;

x16=55;

x11=70;

x17=70;

x12=65;

x18=65;

x13=80;

x19=80;

x14=75;

x20=75;

x15=90;

x21=90;

x22=120;
y1=160;

y2=100;

y3=160;

y4=80;

y5=320;

y6=240;

y7=300;

y8=240;

y9=200;

y10=224;

y16=176;

y11=234;

y17=166;

y12=217;

y18=183;

y13=227;

y19=173;

y14=210;

y20=190;

y15=220;

y21=180;

y22=280;

int gr = DETECT, gm;

initgraph (&gr, &gm, "C:\\TURBOC3\\BGI");

cleardevice ();
delay (50);

//World

W_xmin = 20;

W_xmax = 340;

W_ymin = 20;

W_ymax = 400;

rectangle (W_xmin, W_ymin, W_xmax, W_ymax);

outtextxy (W_xmin, W_ymin - 10, "World");

//drawing a triangle

line (x1, y1, x2, y2);

line (x2, y2, x3, y3);

line (x3, y3, x4, y4);

line (x4, y4, x5, y5);

line (x5, y5, x6, y6);

line (x6, y6, x7, y7);

line (x7, y7, x8, y8);

line (x8, y8, x9, y9);

line (x9, y9, x1, y1);

line (x1, y1, x16, y16);

line (x16, y16, x17, y17);

line (x17, y17, x18, y18);

line (x18, y18, x19, y19);

line (x19, y19, x20, y20);

line (x20, y20, x21, y21);

line (x8, y8, x10, y10);


line (x10, y10, x11, y11);

line (x11, y11, x12, y12);

line (x12, y12, x13, y13);

line (x13, y13, x14, y14);

line (x14, y14, x15, y15);

//line (x, y, x, y);

//Window

W_xmin = 0;

W_xmax = 120;

W_ymin = 200;

W_ymax = 280;

// viewport

V_xmin = 380;

V_ymin = 100;

V_xmax = 620;

V_ymax = 320;

rectangle (V_xmin, V_ymin, V_xmax, V_ymax);

outtextxy (V_xmin, V_ymin - 10, "Viewport");

// calculatng Sx and Sy

sx = (float) (V_xmax - V_xmin) / (W_xmax - W_xmin);

sy = (float) (V_ymax - V_ymin) / (W_ymax - W_ymin);

x8 = V_xmin + (float) ((x8 - W_xmin) * sx);

x9 = V_xmin + (float) ((x9 - W_xmin) * sx);

x10 = V_xmin + (float) ((x10 - W_xmin) * sx);

x11 = V_xmin + (float) ((x11 - W_xmin) * sx);


x12 = V_xmin + (float) ((x12 - W_xmin) * sx);

x13 = V_xmin + (float) ((x13 - W_xmin) * sx);

x14 = V_xmin + (float) ((x14 - W_xmin) * sx);

x15 = V_xmin + (float) ((x15 - W_xmin) * sx);

x22 = V_xmin + (float) ((x22 - W_xmin) * sx);

//x = V_xmin + (float) ((x - W_xmin) * sx);

//x = V_xmin + (float) ((x - W_xmin) * sx);

//x = V_xmin + (float) ((x - W_xmin) * sx);

y8 = V_ymin + (float) ((y8 - W_ymin) * sy);

y9 = V_ymin + (float) ((y9 - W_ymin) * sy);

y10 = V_ymin + (float) ((y10 - W_ymin) * sy);

y11 = V_ymin + (float) ((y11 - W_ymin) * sy);

y12 = V_ymin + (float) ((y12 - W_ymin) * sy);

y13 = V_ymin + (float) ((y13 - W_ymin) * sy);

y14 = V_ymin + (float) ((y14 - W_ymin) * sy);

y15 = V_ymin + (float) ((y15 - W_ymin) * sy);

y22 = V_ymin + (float) ((y22 - W_ymin) * sy);

// drawing triangle

line (x8, y8, x9, y9);

line (x8, y8, x22, y22);

//line (x1, y1, x16, y16);

line (x8, y8, x10, y10);

line (x10, y10, x11, y11);

line (x11, y11, x12, y12);

line (x12, y12, x13, y13);


line (x13, y13, x14, y14);

line (x14, y14, x15, y15);

getch ();

closegraph ();

return 0;

Lab 6:
#include <graphics.h>

#include <stdlib.h>

#include <math.h>

#include <stdio.h>

#include <conio.h>

void function1(int rx,int ry,int xc,int yc)

float dx, dy, d1, d2, x, y;

x = 0;

y = ry;

d1 = (ry * ry) - (rx * rx * ry) + (0.25 * rx * rx);

dx = 2 * ry * ry * x;

dy = 2 * rx * rx * y;

while (dx < dy)

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

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

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


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

if (d1 < 0)

x++;

dx = dx + (2 * ry * ry);

d1 = d1 + dx + (ry * ry);

else

x++;

y--;

dx = dx + (2 * ry * ry);

dy = dy - (2 * rx * rx);

d1 = d1 + dx - dy + (ry * ry);

delay(25);

d2 = ((ry * ry) * ((x + 0.5) * (x + 0.5))) + ((rx * rx) * ((y - 1) * (y - 1))) - (rx * rx *

ry * ry);

while (y >= 0)

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

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

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

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


if (d2 > 0)

y--;

dy = dy - (2 * rx * rx);

d2 = d2 + (rx * rx) - dy;

else

y--;

x++;

dx = dx + (2 * ry * ry);

dy = dy - (2 * rx * rx);

d2 = d2 + dx - dy + (rx * rx);

delay(25);

int main()

initwindow(1026,786);

function1(80,65,200,200);

function1(60,35,200,170);

function1(40,65,200,200);

setcolor(RED);

settextstyle(1,0,4);
outtextxy(95,300,"TOYOTA");

getch();

closegraph();

return 0;

Lab5:

#include <graphics.h>

#include<iostream>

using namespace std;

void circle(int xc, int yc, int x, int y, int col)

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

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

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

putpixel(xc-x,yc-y,col);

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

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

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

putpixel(xc-y,yc-x,col);

//smile

void semicircle(int xc, int yc, int x, int y, int col)

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

putpixel(xc-x,yc+y,col);
}

//frown

void semicircle1(int xc, int yc, int x, int y, int col)

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

putpixel(xc-x,yc-y,col);

void bresenham(int xc, int yc, int r, int ch, int col)

int x=0, y=r;

int d= 3- 2*r;

if(ch==1)

circle(xc,yc,x,y,col);

else if(ch==2)

semicircle(xc,yc,x,y,col);

else if(ch==3)

semicircle1(xc,yc,x,y,col);

while(y>=x)

x++;

if(d>0)

y--;

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

}
else

d=d+4*x+6;

if(ch==1)

circle(xc,yc,x,y,col);

else if(ch==2)

semicircle(xc,yc,x,y,col);

else if(ch==3)

semicircle1(xc,yc,x,y,col);

//horizontal

void bresenham1(int x0, int x1, int y, int col)

for(int x=x0; x<x1;x++)

putpixel(x,y,col);

int main()

initwindow(1026,768);

//happy

bresenham(200,200,100,1,14); //face

bresenham(150,150,10,1,15); //leye

bresenham(250,150,10,1,15); //reye

bresenham(200,200,60,2,12); //lip
//sad

bresenham(450,200,100,1,14); //face

bresenham(400,150,10,1,15); //leye

bresenham(500,150,10,1,15); //reye

bresenham(450,300,60,3,12); //lip

//emotionless

bresenham(700,200,100,1,14); //face

bresenham(650,150,10,1,15); //leye

bresenham(750,150,10,1,15); //reye

bresenham1(650,750,250,12); //lip

//shock

bresenham(325,450,100,1,14); //face

bresenham(275,400,10,1,15); //leye

bresenham(375,400,10,1,15); //reye

bresenham(325,500,20,1,12); //lip

//upside smile

bresenham(575,450,100,1,14); //face

bresenham(525,500,10,1,15); //leye

bresenham(625,500,10,1,15); //reye

bresenham(575,450,60,3,12); //lip

getch();

closegraph();

return 0;

}
Lab4:
1.spider web:
#include<bits/stdc++.h>

#include<graphics.h>

using namespace std;

void Bresenhams(int x0,int y0,int x1,int y1)

int dx = x1 - x0;

int dy = y1 - y0;

int x = x0;

int y = y0;

if(x0<=x1 && y0<=y1)

if(abs(dx)>abs(dy))

putpixel(x,y,WHITE);

int pk=(2*abs(dy))-abs(dx);

for(int i=0;i<abs(dx);i++)

x=x+1;

if(pk<0)

pk=pk+(2*abs(dy));

else

{
y=y+1;

pk=pk+(2*abs(dy))-(2*abs(dx));

putpixel(x,y,WHITE);

else

putpixel(x,y,WHITE);

int pk=(2*abs(dx))-abs(dy);

for(int i=0;i<abs(dy);i++)

y=y+1;

if(pk<0)

pk=pk+(2*abs(dx));

else

x=x+1;

pk=pk+(2*abs(dx))-(2*abs(dy));

putpixel(x,y,WHITE);

else
{

if(abs(dx)>abs(dy))

putpixel(x,y,WHITE);

int pk=(2*abs(dy))-abs(dx);

for(int i=0;i<abs(dx);i++)

x=x+1;

if(pk<0)

pk=pk+(2*abs(dy));

else

y=y-1;

pk=pk+(2*abs(dy))-(2 * abs(dx));

putpixel(x,y,WHITE);

else

putpixel(x,y,WHITE);

int pk=(2*abs(dx))-abs(dy);

for(int i=0;i<abs(dy);i++)

y=y+1;
if(pk<0)

pk=pk+(2*abs(dx));

else

x=x-1;

pk=pk+(2*abs(dx))-(2*abs(dy));

putpixel(x,y,WHITE);

int main()

initwindow(1026,786);

Bresenhams(400,200,400,600);

Bresenhams(200,400,600,400);

Bresenhams(250,250,550,550);

Bresenhams(550,250,250,550);

Bresenhams(250,250,200,400);

Bresenhams(250,250,400,200);

Bresenhams(400,200,550,250);

Bresenhams(550,250,600,400);

Bresenhams(600,400,550,550);

Bresenhams(400,600,550,550);
Bresenhams(250,550,400,600);

Bresenhams(200,400,250,550);

Bresenhams(288,288,250,400);

Bresenhams(288,288,400,250);

Bresenhams(400,250,512,288);

Bresenhams(512,288,550,400);

Bresenhams(550,400,512,512);

Bresenhams(400,550,512,512);

Bresenhams(288,512,400,550);

Bresenhams(250,400,288,512);

Bresenhams(326,326,300,400);

Bresenhams(326,326,400,300);

Bresenhams(400,300,473,326);

Bresenhams(473,326,500,400);

Bresenhams(500,400,473,473);

Bresenhams(400,500,473,473);

Bresenhams(327,473,400,500);

Bresenhams(300,400,327,473);

getch();

closegraph();

return 0;

2.table lamp:
#include<bits/stdc++.h>

#include<graphics.h>
using namespace std;

void Bresenhams(int x0,int y0,int x1,int y1)

int dx = x1 - x0;

int dy = y1 - y0;

int x = x0;

int y = y0;

if(x0<=x1 && y0<=y1)

if(abs(dx)>abs(dy))

putpixel(x,y,WHITE);

int pk=(2*abs(dy))-abs(dx);

for(int i=0;i<abs(dx);i++)

x=x+1;

if(pk<0)

pk=pk+(2*abs(dy));

else

y=y+1;

pk=pk+(2*abs(dy))-(2*abs(dx));

putpixel(x,y,WHITE);

}
}

else

putpixel(x,y,WHITE);

int pk=(2*abs(dx))-abs(dy);

for(int i=0;i<abs(dy);i++)

y=y+1;

if(pk<0)

pk=pk+(2*abs(dx));

else

x=x+1;

pk=pk+(2*abs(dx))-(2*abs(dy));

putpixel(x,y,WHITE);

else

if(abs(dx)>abs(dy))

putpixel(x,y,WHITE);

int pk=(2*abs(dy))-abs(dx);
for(int i=0;i<abs(dx);i++)

x=x+1;

if(pk<0)

pk=pk+(2*abs(dy));

else

y=y-1;

pk=pk+(2*abs(dy))-(2 * abs(dx));

putpixel(x,y,WHITE);

else

putpixel(x,y,WHITE);

int pk=(2*abs(dx))-abs(dy);

for(int i=0;i<abs(dy);i++)

y=y+1;

if(pk<0)

pk=pk+(2*abs(dx));

else

x=x-1;
pk=pk+(2*abs(dx))-(2*abs(dy));

putpixel(x,y,WHITE);

int main()

initwindow(1026,786);

int lamp[10];

int i=0;

bool check = true;

lamp[0]=300;

lamp[1]=200;

lamp[2]=500;

lamp[3]=200;

lamp[4]=550;

lamp[5]=300;

lamp[6]=250;

lamp[7]=300;

lamp[8]=300;

lamp[9]=200;

Bresenhams(300,200,500,200);

Bresenhams(300,200,250,300);
Bresenhams(250,300,550,300);

Bresenhams(500,200,550,300);

Bresenhams(390,300,390,400);

Bresenhams(410,300,410,400);

Bresenhams(300,400,500,400);

Bresenhams(300,410,500,410);

Bresenhams(300,400,300,410);

Bresenhams(500,400,500,410);

while(i<10)

setcolor(getmaxcolor());

if(check)

setfillstyle(SOLID_FILL,WHITE);

else

setfillstyle(SOLID_FILL,BLACK);

fillpoly(5,lamp);

check = !check;

i++;

delay(1000);

closegraph();

return 0;

Lab 3;

1.name:
#include<stdio.h>

#include<graphics.h>

#include<math.h>

int abs (int n)

return ( (n>0) ? n : ( n * (-1)));

void DDA(int X0, int Y0, int X1, int Y1)

int dx = X1 - X0;

int dy = Y1 - Y0;

int steps = abs(dx) > abs(dy) ? abs(dx) : abs(dy);

float Xinc = dx / (float) steps;

float Yinc = dy / (float) steps;

float X = X0;

float Y = Y0;

for (int i = 0; i <= steps; i++)

putpixel (round(X),round(Y),YELLOW);

X += Xinc;

Y += Yinc;

delay(5);

}
int main()

int gd = DETECT, gm;

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

int X0, Y0, X1, Y1;

DDA(50,50,50,100); //k

DDA(50,50,100,71); //k

DDA(50,80,100,71); //k

DDA(50,80,100,100); //a

DDA(174,50,152,100); //a

DDA(174,50,200,100); //a

DDA(159,79,189,80); //n

DDA(250,52,250,100); //n

DDA(250,52,300,52); //n

DDA(251,100,300,100); //n

DDA(300,81,300,100); //n

DDA(270,81,300,81); //n

DDA(350,52,350,100); //a

DDA(350,100,400,100); //a

DDA(400,51,400,100); //a

DDA(450,51,450,101); //n
DDA(450,101,500,101); //n

return 0;

2.name:
#include<stdio.h>

#include<graphics.h>

#include<math.h>

int abs (int n)

return ( (n>0) ? n : ( n * (-1)));

void DDA(int x1, int y1, int x2, int y2)

int dx = x2 - x1;

int dy = y2 - y1;

int m=1;

int steps = abs(dx) > abs(dy) ? abs(dx) : abs(dy);

float Xinc = dx / (float) steps;

float Yinc = dy / (float) steps;

float X = x1;
float Y = y1;

for (int i = 0; i <= steps; i++)

if(m<2){

X=X+Xinc;

Y=Y+Yinc;

m=m+1;

else{

X=X+Xinc;

Y=Y+Yinc;

putpixel(round(X),round(Y),WHITE);

m=0;

delay(5);

int main()

int gd = DETECT, gm;

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

int x1, y1 , x2 , y2;

DDA(50,50,50,100); //k
DDA(50,50,100,71); //k

DDA(50,80,100,71); //k

DDA(50,80,100,100); //a

DDA(174,50,152,100); //a

DDA(174,50,200,100); //a

DDA(159,79,189,80); //n

DDA(250,52,250,100); //n

DDA(250,52,300,52); //n

DDA(251,100,300,100); //n

DDA(300,81,300,100); //n

DDA(270,81,300,81); //n

DDA(350,52,350,100); //a

DDA(350,100,400,100); //a

DDA(400,51,400,100); //a

DDA(450,51,450,101); //n

DDA(450,101,500,101); //n

return 0;

}
Lab 2:
1.rainbow:
#include<stdio.h>

#include<graphics.h>

#include<dos.h>

// function for making of rainbow

void rainbow()

// auto detection

int gdriver = DETECT,gmode;

int x, y, i;

// initialize graphics mode(passed three arguments to

// initgraph function)

// &gdriver is the address of gdriver variable, &gmode is

// the address of gmode and

// "C:\\Turboc3\\BGI" is the directory path where BGI files are stored

initgraph(&gdriver,&gmode,"C:\\Turboc3\\BGI");

x = getmaxx() / 2;//finding centre x-ordinate of screen

y = getmaxy() / 2;//finding centre y-ordinate of screen

for (i=30; i<200; i++)


{

// delay function under dos.h for holding the

// function for some time

delay(100);

// selecting color for making of rainbow

setcolor(i/10);

// making of arc with fixed centre and increasing radius

arc(x, y, 0, 180, i-10);

// driver program

int main()

rainbow();

return 0;

2.olymbics:
#include<graphics.h>

#include<bits/stdc++.h>

using namespace std;

int main()

initwindow(1094,768);
setcolor(BLUE);

circle(300,200,50);

setcolor(WHITE);

circle(410,200,50);

setcolor(RED);

circle(520,200,50);

setcolor(YELLOW);

circle(355,250,50);

setcolor(GREEN);

circle(475,250,50);

getch();

closegraph();

return 0;

3.bouncing ball:
#include <stdio.h>

#include <conio.h>

#include <graphics.h>

#include <dos.h>

int main() {

int gdriver = DETECT, gmode;

int i, x, y, flag=0;

initgraph(&gdriver,&gmode,"C:\\TURBOC3\\BGI");
/* get mid positions in x and y-axis */

x = getmaxx()/2;

y = 30;

while (!kbhit())

if(y >=getmaxy()-30 || y <= 30)

flag=!flag;

/* draws the gray board */

setcolor(RED);

setfillstyle(SOLID_FILL, RED);

circle(x, y, 30);

floodfill(x, y,RED);

/* delay for 50 milli seconds */

delay(50);

/* clears screen */

cleardevice();

if(flag)

y = y +5;

else

{
y=y - 5;

getch();

closegraph();

return 0;

Covid ad:
#include<bits/stdc++.h>

#include<graphics.h>

using namespace std;

int main()

initwindow(1280,800);

//vaccine

line(475,450,475,520);

rectangle(455,520,495,650);

rectangle(470,650,480,680);

line(455,680,495,680);

//Human 1

circle(720,500,10);

line(720,510,720,550);

line(720,550,710,600);

line(720,520,710,550);
line(720,520,730,550);

line(720,550,730,600);

//Human 2

circle(770,500,10);

line(770,510,770,550);

line(770,550,760,600);

line(770,520,760,550);

line(770,520,780,550);

line(770,550,780,600);

//text

settextstyle(1,0,6);

outtextxy(330,50,"Covid Vaccination");

//text

settextstyle(1,0,5);

outtextxy(400,200,"Get Vaccinated");

//text

settextstyle(1,0,3);

outtextxy(270,350,"One shot can help you prevent from COVID-19");

//text

settextstyle(1,0,3);

outtextxy(400,400,"STAY SAFE");

//text

settextstyle(1,0,3);

outtextxy(670,400,"SAVE LIFE");

int i=0;
while(1)

//right corona

setcolor(i%16);

circle(1100,250,60);

setcolor(i%16);

circle(1070,220,10);

setcolor(i%16);

circle(1130,220,10);

setcolor(i%16);

circle(1025,185,10);

setfillstyle(SOLID_FILL,i%16);

floodfill(1025,185,i%16);

setcolor(i%16);

line(1030,190,1045,230);

setcolor(i%16);

circle(1175,185,10);

setfillstyle(SOLID_FILL,i%16);

floodfill(1175,185,i%16);

setcolor(i%16);

line(1170,190,1155,230);

//left corona

setcolor(i%16);

circle(200,250,60);

setcolor(i%16);
circle(170,220,10);

setcolor(i%16);

circle(230,220,10);

setcolor(i%16);

circle(125,185,10);

setfillstyle(SOLID_FILL,i%16);

floodfill(125,185,i%16);

setcolor(i%16);

line(130,190,145,230);

setcolor(i%16);

circle(275,185,10);

setfillstyle(SOLID_FILL,i%16);

floodfill(275,185,i%16);

setcolor(i%16);

line(270,190,255,230);

i++;

delay(100);

getch();

closegraph();

return 0;

You might also like