Professional Documents
Culture Documents
CGR b2
CGR b2
CGR b2
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.
1
VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER ENGG.
Moving Boat CGR 22318, Sem III
2
VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER ENGG.
Moving Boat CGR 22318, Sem III
PART-B OUTCOME
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
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.
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).
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
5
VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER ENGG.
Moving Boat CGR 22318, Sem III
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
7
VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER ENGG.
Moving Boat CGR 22318, Sem III
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;
if (err != grOk) {
printf("Graphics Error: %s\n",
grapherrormsg(err));
return 0;
}
j = 0;
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++;
}
setcolor(DARKGRAY);
setlinestyle(SOLID_LINE, 1, 3);
setcolor(LIGHTBLUE);
delay(250);
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;
/* drawing boat */
setlinestyle(SOLID_LINE, 1, 1);
setcolor(BROWN);
setfillstyle(SOLID_FILL, BROWN);
sector(x, y, 180, 360, 50, 10);
11
VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER ENGG.
Moving Boat CGR 22318, Sem III
getch();
12
VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER ENGG.
Moving Boat CGR 22318, Sem III
13
VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER ENGG.
Moving Boat CGR 22318, Sem III
____________________________________________________
Output:
14
VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER ENGG.
Moving Boat CGR 22318, Sem III
15
VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER ENGG.