Thursday, February 13, 2020

Flood Fill Algorithm Implementation in C-Language

Flood Fill Algorithm Implementation in C-Language

Flood Fill Algorithm fills area bordered with multiple color.
Flood fill algorithm replaces interior color with fill color instead of checking boundary color.
It uses 4-connected or 8- connected approach.


Program:


#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<dos.h>
void flood_fill_algo(int,int,int,int);
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
setbkcolor(8);
setcolor(3);
rectangle(200,200,250,250);
flood_fill_algo(201,201,0,4);

getch();

}
void flood_fill_algo(int x,int y,int old_c,int new_c)
{
int a=getpixel(x,y);
if(a==old_c)
{
//delay(10);
putpixel(x,y,new_c);
flood_fill_algo(x+1,y,old_c,new_c);
flood_fill_algo(x-1,y,old_c,new_c);
flood_fill_algo(x,y+1,old_c,new_c);
flood_fill_algo(x,y-1,old_c,new_c);
}

}


Output: 


Wednesday, February 12, 2020

Boundary Fill Algorithm implementation in C Language

Boundary Fill Algorithm implementation in C Language


Boundary Fill Algorithm



In Boundary fill algorithm start filling from a inside point towards outward till the boundary. 
It accepts coordinates of inside point (seed point), fill color and boundary color.

It fills seed pixel with fill color and test neighbors of seed pixel. If neighbor pixel is not having fill color or boundary color then paint with fill color this process continues till boundary. Neighbors are tested using 4-connected or 8- connected approach.

Program for Boundary Fill Algorithm

#include<stdio.h>

#include<graphics.h>

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

void boundary_fill_algo(int,int,int,int); // function prototype


void main()


{


int gd=DETECT,gm;


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


setbkcolor(12); //used to set background color


setcolor(6); //used to set circle boundary color


circle(200,200,40); // function used to draw circle directly


boundary_fill_algo(200,200,6,3);//boundary_fill function call 

setcolor(8);

rectangle(300,300,350,350);

boundary_fill(301,301,8,10);

setcolor(6);

circle(450,200,40);

boundary_fill(450,200,6,3);

getch();

}

//boundary_fill function definition 

void boundary_fill_algo(int x,int y,int bound_col,int fill_col)

{

int b=getpixel(x,y);

if(b!=bound_col & b!=fill_col)

{

 delay(50);   //delay() function adds delay into execution

 putpixel(x,y,fill_col);

 boundary_fill_algo( x+1, y, bound_col, fill_col);

 boundary_fill_algo( x-1, y, bound_col, fill_col);

 boundary_fill_algo( x, y+1, bound_col, fill_col);

 boundary_fill_algo( x, y-1, bound_col, fill_col);

}

}


Output:




Thursday, February 6, 2020

Important Keyboard Shortcuts while Performing Computer graphics Programs in Turbo C.

Important Keyboard  Shortcuts and commands used in Computer graphics Programming  in C or C++ (in TC) . 


Many time we are using shortcuts to do some function while writing and executing computer graphics program in  C or C++  language in TC.Shortcuts are also useful when our mouse is not working properly.


Following is the list of few important shortcuts and commands:

Sr.No. Description Shortcut or command
1 Program Compilation Alt+F9
2 Program Execution Ctrl+F9
3 Save program F2
4 Seeing Output if program returns into blue screen Alt+F5
5 Increasing or Decreasing size of TC window Alt+Enter
6 Copy Ctrl+Insert
7 Cut Shift+Delete
8 Paste Shift+Insert
9 To change directory in command Prompt cd directrory_name
10 To come out of directory cd..
11 Select Menu (File,edit etc) F10
12 Go to Cursor F5

Tuesday, February 4, 2020

Character Generation program using C-Language

Character Generation program using C-Language

Following program will draw character using bitmap method.

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

void main()
{
int gd=DETECT,gm,i,j;
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
int a[8][5]={{0,0,1,0,0},
    {0,1,1,1,0},
    {0,1,0,1,0},
    {1,1,0,1,1},
    {1,0,0,0,1},
    {1,1,1,1,1},
    {1,0,0,0,1},
    {1,0,0,0,1}};

int b[8][5]={{1,1,1,1,0},
    {1,0,0,0,1},
    {1,0,0,0,1},
    {1,1,1,1,0},
    {1,0,0,0,1},
    {1,0,0,0,1},
    {1,0,0,0,1},
    {1,1,1,1,0}};

int c[8][5]={{0,1,1,1,0},
    {1,0,0,0,0},
    {1,0,0,0,0},
    {1,0,0,0,0},
    {1,0,0,0,0},
    {1,0,0,0,0},
    {1,0,0,0,0},
    {0,1,1,1,0}};
int d[8][5]={{1,1,1,1,0},
    {1,0,0,0,1},
    {1,0,0,0,1},
    {1,0,0,0,1},
    {1,0,0,0,1},
    {1,0,0,0,1},
    {1,0,0,0,1},
    {1,1,1,1,0}};
for(i=0;i<8;i++)
{
for(j=0;j<5;j++)
{
putpixel(100+j,100+i,5*a[i][j]);
putpixel(107+j,100+i,6*b[i][j]);
putpixel(114+j,100+i,7*c[i][j]);
putpixel(121+j,100+i,9*d[i][j]);
}
}
getch();

}




Monday, February 3, 2020

Character generation methods in Computer Graphics

Character generation methods:

 Bitmap Method:

    Use of Pixel Array to display character.Font of Character can be increased by increasing pixel array size.


 Stroke Method:

   Character can be drawn using graphics Primitives like Line, Curve etc.Font size can be increasing length /width of graphics primitives. 

 Starburst Method:

   Fixed pattern of 24 lines is used.
   Each character is stored in 24 bits representation.
   Bit for The line highlighted to be set as 1 and non highlighting set as 0.
 24 bit code for A is:100001110011110000001100