123 Eng

Engineering the engineers™


Latest Jobs   Forum Map

 


Home
Source Codes
Engineering Colleges

Training  Reports
Seminar Reports
Placement Papers

Forums

   Computer Science / IT
   Electronics
   Electrical
   Mechanical
   Chemical
   Civil

   CAT / MBA

   GMAT / Foreign MBA
Latest Jobs

Engineering Jobs / Technical Jobs
Management Jobs

Sitemap
Terms of use

Displaying  Source Code(s)  
 

 
--------------------------------------------------------------------------------

Paint program in C.

--------------------------------------------------------------------------------

Description : This project is a good program for understanding basics of Graphics in C Shailesh & Nirgun

/* This programs are four seperate programs which combinely output as
Paint .........



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


#include"c:paintmainscre.c"

# define RBACK_GND_ICON 0
# define BACK_GND_ICON 0
# define MAXX 40
# define MAXY 32
# define EXP_FACTOR 4
# define SKIP 1
# define BACK_GND_GRID 1
# define DRAW 0
# define ERASE 2
# define FORE_GND 3


unsigned char icon_image [MAXX][MAXY] ;

int scan ;

iconcreater()
{
int gm = CGAC3, gd = CGA ;
char fname[30] ;

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

init_icon() ;

display_icon() ;

display_grid() ;

while ( 1 )
{
gotoxy ( 2, 25 ) ;
printf ( "F1-Draw F2-Load F3-Save F4-Quit" ) ;

getkey() ;

switch ( scan )
{
case 59 : /* F1 key */

edit_icon() ;
break ;

case 60 : /* F2 key */

/* collect the file name */
gotoxy ( 6, 21 ) ;
printf ( "Enter file name: " ) ;
gets ( fname ) ;

/* erase the message line */
icleartext ( 21 ) ;

load_icon ( fname ) ;
display_icon() ;
display_grid() ;
break ;

case 61 : /* F3 key */

save_icon() ;
break ;

case 62 : /* F4 key */

closegraph() ;
restorecrtmode() ;
mainscreen() ;
mainmenu1();
//exit ( 0 ) ;
}
}
}


load_icon ( char *name )
{
FILE *fp ;


if ( ( fp = fopen ( name, "rb" ) ) == NULL )
{
gotoxy ( 1, 21 ) ;
printf ( "Unable to open file! Press any key..." ) ;
getch() ;

icleartext ( 21 ) ;
return ;
}

fread ( icon_image, sizeof ( icon_image ), 1, fp ) ;
fclose ( fp ) ;
return;
}


icleartext ( int row )
{
int col ;

for ( col = 1 ; col <= 39 ; col++ )
{
gotoxy ( col, row ) ;
printf ( " " ) ;
}
return;
}


init_icon()
{
int x, y ;

for ( x = 0 ; x < MAXX ; x++ )
{
for ( y = 0 ; y < MAXY ; y++ )
icon_image[x][y] = BACK_GND_ICON ;
}
return;
}


display_icon()
{
int x, y ;

setcolor ( 3 ) ;
rectangle ( 0, 0, 41, 33 ) ;

for ( x = 0 ; x < MAXX ; x++ )
{
for ( y = 0 ; y < MAXY ; y++ )
putpixel ( x + 1, y + 1, icon_image[x][y] ) ;
}
return;
}


display_grid()
{
int x, y, xgrid, ygrid ;

for ( x = 0 ; x < MAXX ; x++ )
{
for ( y = 0 ; y < MAXY ; y++ )
{
xgrid = 100 + x * EXP_FACTOR ;
ygrid = y * EXP_FACTOR ;

if ( icon_image[x][y] == 0 )
putpixel ( xgrid, ygrid, 1 ) ;
else
putpixel ( xgrid, ygrid, icon_image[x][y] ) ;
}
}
return;
}



edit_icon()
{
int x = 0, y = 0, xgrid = 100, ygrid = 0, flag = SKIP ;


gotoxy ( 1, 25 ) ;
printf ( "F1-Draw F2-Skip F3-Erase F4-Wipe F5-End" ) ;

while ( 1 )
{

idrawcursor ( xgrid, ygrid, FORE_GND ) ;

getkey() ; /* receive key */


idrawcursor ( xgrid, ygrid, BACK_GND_ICON ) ;


if ( icon_image[x][y] == 0 )
putpixel ( xgrid, ygrid, BACK_GND_GRID ) ;
else
putpixel ( xgrid, ygrid, icon_image[x][y] ) ;

switch ( scan )
{
case 59 : /* F1 key */

flag = DRAW ;
break ;

case 60 : /* F2 key */

flag = SKIP ;
break ;

case 61 : /* F3 key */

flag = ERASE ;
break ;

case 62 : /* F4 key */

init_icon() ;
display_icon () ;
display_grid() ;
break ;

case 63 : /* F5 key */

icleartext ( 25 ) ;
return ;

case 75 : /* left arrow key */

x-- ;
break ;

case 77 : /* right arrow key */

x++ ;
break ;

case 72 : /* up arrow key */

y-- ;
break ;

case 80 : /* down arrow key */

y++ ;
break ;

case 71 : /* Home key */

x-- ;
y-- ;
break ;

case 73 : /* End key */

x++ ;
y-- ;
break ;

case 79 : /* PgUp key */

x-- ;
y++ ;
break ;

case 81 : /* PgDn key */

x++ ;
y++ ;
break ;

default : /* any other key */

printf ( "a" ) ;
}



if ( x < 0 )
x++ ;

if ( y < 0 )
y++;

if ( x == MAXX )
x-- ;

if ( y == MAXY )
y-- ;

if ( flag == DRAW )
icon_image[x][y] = FORE_GND ;

if ( flag == ERASE )
icon_image[x][y] = BACK_GND_ICON ;


putpixel ( x + 1, y + 1, icon_image[x][y] ) ;


xgrid = 100 + x * EXP_FACTOR ;
ygrid = y * EXP_FACTOR ;


if ( icon_image[x][y] == 0 )
putpixel ( xgrid, ygrid, BACK_GND_GRID ) ;
else
putpixel ( xgrid, ygrid, icon_image[x][y] ) ;
}
}


save_icon()
{
FILE *fp ;
char fname[30] ;


gotoxy ( 6, 21 ) ;
printf ( "Enter the file name: " ) ;
gets ( fname ) ;


icleartext ( 21 ) ;


if ( ( fp = fopen ( fname, "wb" ) ) == NULL )
{
gotoxy ( 1, 21 ) ;
printf ( "Unable to open file! Press any key..." ) ;
getch() ;

icleartext ( 21 ) ;
return ;
}

fwrite ( icon_image, sizeof ( icon_image ), 1, fp ) ;
fclose ( fp ) ;
return;
}


idrawcursor ( int xgrid, int ygrid, int color )
{
int xx, yy ;

for ( xx = xgrid - 2 ; xx <= xgrid + 2 ; xx++ )
putpixel ( xx, ygrid, color ) ;

for ( yy = ygrid - 2 ; yy <= ygrid + 2 ; yy++ )
putpixel ( xgrid, yy, color ) ;
return;
}
//////////////////////////////////////////////////////////////////////////
////


# include "stdio.h"
# include "process.h"
# include "string.h"
# include "stdlib.h"
# include "ctype.h"
# include "conio.h"
# include "fcntl.h"
//# include "types.h"
//# include "stat.h"
# include "dir.h"
# include "dos.h"

# include "c:paintmp1.c"


char *menu[] = {
"^Paint Application",
"^Icon Creater ",
"^Accessories ",
"A^bout Us ",
"^Exit "
} ;

char *accessories[] = {
"^Indian Flag ",
"^Animation ",
"^Screen Saver 1 ",
"Screen Saver 2 ",
"Screen Saver 3 ",
"^Return "
} ;



char *messages[] = {
" PAINT AND ACCESSORIES ",
" Select using Enter or Hot key ",
"Create a new paint application",
"Create a new Icon",
"Different accessories",
"Information about Developer",
"Exit the application",
"Display Indian Flag",
"Display Animation",
"Display screen saver first",
"Display screen saver second",
"Display screen saver third",
"Return to main menu",
"Display memory size",
"Display love calculator",
"Display screen saver third",
"Display screen saver fourth",
"Return to main menu",
"Remove an existing directory",
"List existing directory contents",
"Display directory tree",
"Display calendar of any month & year",
"Display Ascii values & characters",
"Display equipment list",
"A video game",
"Display base memory size",
"Display base memory size",
"Return to main menu ",
" Press any key to continue... ",
" Insufficient space! Press any key... ",
" Developed By : ",
" Rathi Radheshyam G."
} ;



char far *vid_mem;
int ascii, scan ;

void main()
{

int mm_choice ;


#ifdef MA

vid_mem = ( char far * ) 0xb0000000L ;
setmode ( 7 ) ;

#else

vid_mem = ( char far * ) 0xb8000000L ;
setmode ( 3 ) ;

#endif

showmouseptr();
mainscreen() ;
about();
mainmenu1();

}


mainmenu1()
{
int mm_choice;
while ( 1 )
{

mm_choice = popupmenu ( menu, 5, 4, 29, "FDMX", 2 ) ;


switch ( mm_choice )
{
case 1 :
mainpaint() ;
break ;

case 2 :
iconcreater() ;
break ;

case 3 :
access();
break ;

case 4 :
clear();
about();
break;

case 5 :
size ( 6, 7 ) ;
clrscr() ;
exit ( 1 ) ;

case 27 :
size ( 6, 7 ) ;
clrscr() ;
exit ( 1 ) ;
}
}
}




setmode ( int mode )
{
union REGS i, o ;

i.h.ah = 0 ; /* service no. */
i.h.al = mode ; /* video mode */
int86 ( 16, &i, &o ) ; /* issue interrupt */

return;
}

clear()
{
int r,c;
for(r=18;r<=22;r++)
{
for(c=10;c<=70;c++)
{
writechar(r,c,177,113); //non work scrren setting
}
}
return;
}



mainscreen()
{
/*int i, j ;

drawbox ( 1, 0, 23, 79, 7 ) ;
drawbox ( 3, 0, 21, 79, 7 ) ;

writechar ( 3, 0, 204, 7 ) ;
writechar ( 3, 79, 185, 7 ) ;
writechar ( 21, 0, 204, 7 ) ;
writechar ( 21, 79, 185, 7 ) ;

for ( i = 4 ; i <= 20 ; i++ )
{
for ( j = 1 ; j <= 78 ; j += 2 )
{
writechar ( i, j, 177, 7 ) ;
writechar ( i, j + 1, 177, 7 ) ;
}
}

writestring ( messages[0], 2, 32, 112 ) ;
writestring ( messages[1], 22, 14, 112 ) ;*/


int r,c,er,ec;
//int count=6,sr=2,sc=1,

size ( 32, 0 ) ;

//background color setting
for( r=0;r<=23;r++)
{
for( c=0;c<=79;c+=2)
{
writechar(r,c,' ',7);
writechar(r,c+1,' ',7);
}
}

for(r=0;r<=24;r++)
{
for(c=0;c<=80;c++)
{
writechar(r,c,177,113); //non work scrren setting
}
}

//status bar & title bar setting
for( c=0;c<=79;c++)
{
r=0; writechar(r,c,' ',90); //title bar
// r=1; writechar(r,c,' ',112); //menu bar
//r=23; writechar(r,c,' ',23);
r=24; writechar(r,c,' ',23); //status bar
}

//mainmenu(mmenu,count,sc,sr); //write main menu item
writestring(messages[0],0,28,95+123-128); //write on title bar
writestring(messages[30],24,1,28);
writestring(messages[31],24,16,28);
writestring ( "Project Guide : ", 24, 49, 26 ) ;
writestring ( "Prof. Auti A.G.", 24, 65, 26+128 ) ;

//about();
return;
}


about()
{
int area ;
char *p ;

size ( 32, 0 ) ; /* hide cursor */
//music(3);

/* allocate memory, if unsuccessful terminate execution */
area = ( 17 - 6 + 1 ) * ( 60 - 19 + 1 ) * 2 ;
p = malloc ( area ) ;
if ( p == NULL )
exit(0) ;

/* create dialogue box */
savevideo ( 6, 19, 17, 60, p ) ;
menubox ( 6, 19, 16, 58, 9, 0 ) ;
drawbox ( 6, 19, 16, 58 , 10+128 ) ;

writestring ( "PAINT AND ACCESSORIES ", 7, 29,9 ) ;
writestring ( "Version 1.00", 8, 33,8 ) ;
writestring ( "* Developed By * ", 10, 31, 9 ) ;
writestring ( "RATHI RADHESHYAM GOVARDHANDAS ", 12, 25, 10 ) ;
writestring ( " B.C.S. 3rd Year ", 13, 30, 8 ) ;
writestring ( "R. S. College, Latur ", 14, 29, 8 ) ;
// writestring ( "S. R. T. University, Nanded ", 15, 26, 8 ) ;
writestring ( "Project Guide : Prof. Auti A.G.", 15, 24, 8 ) ;
music(1);
//writestring(messages[28],24,13,26);
//scout("B.C.S. 3rd YEAR",15,32,31);
//scout("RAJARSHI SHAHU COLLEGE,LATUR",17,26,31);
//scout("S.R.T. UNIVERSITY,NANDED",19,28,31);
//writestring ( "Rathi Radheshyam G.", 12, 29, 9 ) ;
//writestring(messages[31],24,59,26);

/* display OK button */
/*menubox ( 14, 36, 15, 43, 32, -1 ) ;
writestring ( "OK", 14, 38, 4 ) ;*/

/* continue till either Esc is hit or OK is selected */
while ( 1 )
{
getkey() ;

if ( ascii == 27 || ascii != 'O' || ascii == 'o' )
// exit(0);
break ;
}

restorevideo ( 6, 19, 17, 60, p ) ;
free ( p ) ;

//size ( 5, 7 ) ; /* show cursor */

return;
}

writechar ( int r, int c, char ch, int attb )
{
char far *v ;

v = vid_mem + r * 160 + c * 2 ; /* calculate address in VDU memory
corresponding to row r and column c */

*v = ch ; /* store ascii value of character */
v++ ;
*v = attb ; /* store attribute of character */

return;
}



writestring ( char *s, int r, int c, int attb )
{
while ( *s != '
 

 

 

Contribute content or training reports / feedback / Comments
job placement papers
All rights reserved © copyright 123ENG