CGR b2

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

Moving Boat CGR 22318, Sem III

PART-A PLAN
1.0 Brief Introduction
____________________________________________________

In this program, we have first draw a boat on left side of the screen (x,y) and then
erases it using cleardevice function. We again draw this boat at (x + 5, y). This will
look like a moving boat from left to right direction. We will repeat above steps until
car reaches the right side of screen.

2.0 AIM of Micro-Project

1. To understand performance of program using C language.


2. To understand various graphics functions.
3. Develop a c program for moving object.

1
VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER ENGG.
Moving Boat CGR 22318, Sem III

3.0 Action Plan


____________________________________________________
Sr. Details of Activity Planned Planned Name of Responsible Team Members
No Start Finish
Date Date
1 Project selection Shubham Dahatonde

2 Identifying project outcomes Vedika Sankhe, Shubham Dahatonde

3 Identifying resources required Shubham Dahatonde

4 Algorithm & implementation Shubham Dahatonde, Vedika Sankhe,

5 Final outcome All group members

6 Documentation Vedika Sankhe, Shubham Dahatonde

7 Seminer and viva-vose Aayan khan, Manish Yadav

8 Final submission of Micro project All group members

4.0 Resources Required


____________________________________________________

Sr. No Name of Resource Specification Qty Remarks

1 Computer 500GB HDD, 1


4 Gb RAM,
AMD processor,
Windows 10 OS
2 Turbo C - 1

2
VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER ENGG.
Moving Boat CGR 22318, Sem III

PART-B OUTCOME

1.0 Brief Description


____________________________________________________

In this program, we will first draw a boat and color it. In every iteration of for loop
we keep on increasing the x coordinates of every point of car to make it look like
this boat is moving from left to right. We will use below mentioned graphics
functions in this program.

Function Description

initgraph It initializes the graphics system by loading the passed graphics


driver then changing the system into graphics mode.

getmaxx It returns the maximum X coordinate in current graphics mode and


driver.

getmaxy It returns the maximum X coordinate in current graphics mode and


driver.

setcolor It changes the current drawing colour. Default colour is white. Each
color is assigned a number, like BLACK is 0 and RED is 4. Here we
are using colour constants defined inside graphics.h header file.

setfillstyle It sets the current fill pattern and fill color.

circle It draws a circle with radius r and centre at (x, y).

line It draws a straight line between two points on screen.

3
VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER ENGG.
Moving Boat CGR 22318, Sem III

Function Description

arc It draws a circular arc from start angle till end angle.

floodfill It is used to fill a closed area with current fill pattern and fill color. It takes
any point inside closed area and color of the boundary as input.

cleardevice It clears the screen, and sets current position to (0, 0).

delay It is used to suspend execution of a program for a M milliseconds.

closegraph It unloads the graphics drivers and sets the screen back to text mode.

4
VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER ENGG.
Moving Boat CGR 22318, Sem III

2.0 AIM of Micro-Project

1. To understand performance of program using C language.


2. To understand various graphics functions.
3. Develop a c program for moving object.

2.0 Course Outcomes (CO)

• Develop a program using computer graphics.


• Develop a program for 2D and 3D transformation.

5
VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER ENGG.
Moving Boat CGR 22318, Sem III

4.0 Procedure Followed


____________________________________________________

Step 1: Start
Step 2: initialize position for boat
x = 50, y = getmaxy() / 2 + 140;
while (x + 60 < getmaxx() && (!kbhit()))
Step 3: setting the color of the river/sea
Step 4: draw the river/sea
rectangle(0, getmaxy() / 2 + 150, getmaxx(), getmaxy())
Step 5: drawing rain drops
while (i< 700 ) {
line(x1, y1, x2, y2);
x1 = x1 + 20;
y2 = y2 + 50;
i++;
Step 6: drawing the boat
setfillstyle(SOLID_FILL, BROWN);
sector(x, y, 180, 360, 50, 10);
Step 6: leg and body of stick man
Step 7: head and hand of stick man
Step 8: moving the position of boat and stick man
Step 9: deallocate memory allocated for graphic screen
Step 10:Stop

6
VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER ENGG.
Moving Boat CGR 22318, Sem III

Start

initialize position for boat


x = 50, y = getmaxy() / 2 + 140;
while (x + 60 < getmaxx() && (!kbhit()))

setting the color of the river/sea

draw the river/sea


rectangle(0, getmaxy() / 2 + 150,
getmaxx(), getmaxy())

drawing rain drops


while (i< 700 ) {
line(x1, y1, x2, y2);
x1 = x1 + 20;
y2 = y2 + 50;
i++;

drawing the boat


setfillstyle(SOLID_FILL, BROWN);
sector(x, y, 180, 360, 50, 10);

7
VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER ENGG.
Moving Boat CGR 22318, Sem III

Draw leg and body of stick


man

Draw head and hand of stick man

moving the position of boat and


stick man

deallocate memory allocated for


graphic screen

Stop

8
VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER ENGG.
Moving Boat CGR 22318, Sem III

#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <dos.h>

int main() {
int gdriver = DETECT, gmode, err;
int i = 0, j, x, y, x1, y1, x2, y2;

initgraph(&gdriver, &gmode, "C:/TURBOC3/BGI");


err = graphresult();

if (err != grOk) {
printf("Graphics Error: %s\n",
grapherrormsg(err));
return 0;
}

j = 0;

/* initialize position for boat */


x = 50, y = getmaxy() / 2 + 140;

while (x + 60 < getmaxx() && (!kbhit())) {


/* setting positions for rain */
x1 = 10, i = y1 = 0;
x2 = 0, y2 = 50;

/* clears graphic screen */


cleardevice();

/* setting the color of the river/sea */


setcolor(LIGHTBLUE);
setlinestyle(SOLID_LINE, 1, 1);
setfillstyle(SOLID_FILL, LIGHTBLUE);

/* draw the river/sea */


rectangle(0, getmaxy() / 2 + 150, getmaxx(), getmaxy());
floodfill(getmaxx() - 10, getmaxy() - 10, LIGHTBLUE);

9
VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER ENGG.
Moving Boat CGR 22318, Sem III

/* rain drops */
setlinestyle(DASHED_LINE, 1, 2);
while (i< 700 ) {
line(x1, y1, x2, y2);
x1 = x1 + 20;
y2 = y2 + 50;
i++;
}

/* drawing the boat */


setlinestyle(SOLID_LINE, 1, 2);
setcolor(BROWN);
setfillstyle(SOLID_FILL, BROWN);
sector(x, y, 180, 360, 50, 10);

setcolor(DARKGRAY);
setlinestyle(SOLID_LINE, 1, 3);

/* leg and body of stick man */


line(x + 40, y - 15, x + 40, y - 40);
line(x + 40, y - 15, x + 45, y - 10);
line(x + 45, y - 10, x + 45, y);
line(x + 40, y - 15, x + 37, y);

/* head and hand of stick man */


circle(x + 40, y - 45, 5);
line(x + 40, y - 35, x + 50, y - 30);
line(x + 40, y - 35, x + 35, y - 32);
line(x + 35, y - 32, x + 45, y - 25);
line(x + 60, y - 45, x + 27, y + 10);

/* moving the position of boat and stick man */


x++;

setcolor(LIGHTBLUE);
delay(250);

/* clears the graphic device */


cleardevice();

10
VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER ENGG.
Moving Boat CGR 22318, Sem III

/* drawing sea/river */
setlinestyle(SOLID_LINE, 1, 1);
setfillstyle(SOLID_FILL, LIGHTBLUE);
rectangle(0, getmaxy() / 2 + 150, getmaxx(), getmaxy());
floodfill(getmaxx() - 10, getmaxy() - 10, LIGHTBLUE);

/* rain drops */
setlinestyle(DASHED_LINE, 1, 2);
x1 = 10, i = y1 = 0;
x2 = 0, y2 = 70;

while (i < 700) {


line(x1, y1, x2, y2);
x1 = x1 + 30;
y2 = y2 + 60;
i++;
}

/* drawing boat */
setlinestyle(SOLID_LINE, 1, 1);
setcolor(BROWN);
setfillstyle(SOLID_FILL, BROWN);
sector(x, y, 180, 360, 50, 10);

/* body and leg of stic man */


setcolor(DARKGRAY);
setlinestyle(SOLID_LINE, 1, 3);
line(x + 40, y - 15, x + 40, y - 40);
line(x + 40, y - 15, x + 45, y - 10);
line(x + 45, y - 10, x + 45, y);
line(x + 40, y - 15, x + 37, y);

/* head, hands of stick man */


circle(x + 40, y - 45, 5);
line(x + 40, y - 35, x + 52, y - 30);
line(x + 40, y - 35, x + 37, y - 32);
line(x + 37, y - 32, x + 49, y - 25);
line(x + 60, y - 45, x + 27, y + 10);

11
VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER ENGG.
Moving Boat CGR 22318, Sem III

/* forwarding the position of the boat */


x++;

/* sleep for 250 milliseconds */


delay(250);

/* clears the graphic device */


cleardevice();
j++;
}

getch();

/* deallocate memory allocated for graphic screen */


closegraph();
return 0;
}

12
VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER ENGG.
Moving Boat CGR 22318, Sem III

5.0 Resources Used


____________________________________________________

Sr. No Name of Resource Specification Qty Remarks

1 Computer 500GB HDD, 1


4 Gb RAM,
AMD processor,
Windows 7 OS
2 TurboC++ - 1

13
VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER ENGG.
Moving Boat CGR 22318, Sem III

6.0 Outputs of Micro-Projects

____________________________________________________
Output:

14
VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER ENGG.
Moving Boat CGR 22318, Sem III

7.0 Skill Developed

Ability to develop C program using graphics function

15
VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER ENGG.

You might also like