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 Brush In C (Project)

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

Description : Paint Brush is intresting paint program which has symmetry function which give some good designs. This program is same as MSPaint with some more/less features. Save the Program in two files paint.c and mouse.c in same directory and compile each file and run paint.c.

/* Paint.c */

#include <graphics.h>
#include <fcntl.h>
#include <math.h>
#include <sys/stat.h>
#include <dir.h>

#include "d: urboc2gamesmouse.c"

void *p;
int color=16,bkc=0,area;
int i,j,l=10,w=10,c=1,symx=0,symy=0,flag=0;
int starflag=0,sqflag=0,lineflag=0,pixelflag=0,eraseflag=0;
int x,y,dx=10,dy=10,but=1,col=4;
char str[30],*string;

int lx1,lx2,ly1,ly2,lflag=0;

void main()
{
initgraphics();
area=imagesize(0,0,300,300);
p=malloc(area);
button3d(dx,dy,l,w,7);
letter(dx,dy,l,w,'.',col);
set_m_ptr(150,150);
show_m_ptr();
setcolor(15);
rectangle(0,0,301,301);
rectangle(1,1,302,302);
rectangle(310-1,250-1,330+1,270+1);
rectangle(330-1,270-1,350+1,290+1);
setfillstyle(1,0);
bar(1,1,300,300);

button3d(310,10,50,10,7);
letter(310,10,50,10," Symm",12);
button3d(310,25,50,10,7);
letter(310,25,50,10," Help",12);
button3d(310,40,50,10,7);
letter(310,40,50,10," Save",12);
button3d(310,55,50,10,7);
letter(310,55,50,10," Load",12);
button3d(310,70,50,10,7);
letter(310,70,50,10," Exit",12);
button3d(310,85,50,10,7);
letter(310,85,50,10," Dele",12);
button3d(310,100,50,10,7);
letter(310,100,50,10," List",12);
button3d(310,115,50,10,7);
letter(310,115,50,10," Eras",12);
button3d(310,130,50,10,7);
letter(310,130,50,10," Draw",12);
button3d(310,145,50,10,7);
letter(310,145,50,10," Line",12);


button3d(450,20,80,50,2);
letter(450,40,50,80," STYLE",12);



for(w=10;w<=160;w+=10)
{
button3d(370,w,50,10,7);
color-=1;
letter(370,w,50,10,"",color);
}
setcolor(7);
rectangle(479,449,629,469);
rectangle(480,450,630,470);
get_m_button(&but,&dx,&dy);
while(1)
{
setcolor(0);
outtextxy(500,460,str);
if(but==0) show_m_ptr();
if(but==1&&dx<=300&&dy<=300)
{
hide_m_ptr();
if(pixelflag==1)
if(symx==1||symy==1) {
lineflag=starflag=sqflag=lflag=0;pixelflag=1; }
putpixel(dx-1,dy-1,c);
if(symx==1)
putpixel(300-(dx-1),dy-1,c);
if(symy==1)
putpixel(dx-1,300-(dy-1),c);
if(symy==1&&symx==1)
{
lineflag=starflag=sqflag=lflag=0;pixelflag=1;
putpixel(300-(dx-1),300-(dy-1),c);
putpixel(300-(dy-1),dx-1,c);
putpixel(dy-1,300-(dx-1),c);
putpixel(300-(dy-1),300-(dx-1),c);
putpixel(dy-1,dx-1,c);

}
if(lineflag==1) { setcolor(c);outtextxy(dx,dy,"\"); }
if(lineflag==2) { setcolor(c);outtextxy(dx,dy-2,"/"); }
if(starflag==1) { setcolor(c);outtextxy(dx,dy,"*"); }
if(sqflag==1) { setcolor(c);outtextxy(dx,dy,""); }



if(eraseflag==1)
{
show_m_ptr();
setcolor(bkc);
outtextxy(dx-6,dy-6,"");

}
}
if(but==2)
{
setfillstyle(1,bkc);
bar(1,1,300,300);
}
if(dx>=310)
{
if(dx<=360)
{
if(dy>=10&&dy<=20)
{

if(but!=0 ) { butn_clicked(310,10,50,10," Symm");}

if(but==2)
{symx=1; symy=0; }
else if(but==3)
{symy=1; symx=0;}
else if(but==1)
{symx=symy=1;}
}
if(dy>=40&&dy<=50)
{
if(but!=0 ) { butn_clicked(310,40,50,10," Save"); }
if(but==1)
{
save();
}
}

if(dy>=55&&dy<=65)
{
if(but!=0 ) { butn_clicked(310,55,50,10," Load"); }
if(but==1)

load();
}
if(dy>=70&&dy<=80)
{
if(but!=0 ) { butn_clicked(310,70,50,10," Exit"); }
if(but==1)
{
closegraph();
exit(0);
}
}
if(dy>=85&&dy<=95)
{
if(but!=0 ) { butn_clicked(310,85,50,10," Dele"); }
if(but==1)
delete();
}
if(dy>=100&&dy<=110)
{
if(but!=0 ) { butn_clicked(310,100,50,10," List"); }
if(but==1)
list();
}
if(dy>=115&&dy<=125)
{
if(but!=0) { butn_clicked(310,115,50,10," Eras"); }
if(but==1)
{
eraseflag =1;
defa();
pixelflag=0;
}
}
if(dy>=130&&dy<=140)
{
if(but!=0) { butn_clicked(310,130,50,10," Draw"); }
if(but==1)
{
eraseflag=0;
defa();
}
}
if(dy>=145&&dy<=155)
{
if(but!=0) { butn_clicked(310,145,50,10," Line"); }
if(but==1)
{
}
}


if(dy>=25&&dy<=35)
{
if(but!=0 ) { butn_clicked(310,25,50,10," Help"); }
setcolor(10);
if(but==1)
{
rectangle(0,305,400,470);
outtextxy(10,310,"Use Mouse Click to activate buttons. ");
outtextxy(10,320,"Symm Button : Right click 8 way Symmetry");
outtextxy(10,330," : Left click 2 way
Symmetry(X-axis)");
outtextxy(10,340," : Right+left 2 way
Symmetry(Y-axis)");
outtextxy(10,350,"Color Palate: Left Click to select Fore color");
outtextxy(10,360," : Right Click to select Back ground");
outtextxy(10,370,"Exit Button : Left Click to Exit");
outtextxy(10,380,"Save Button : Left Click to Save image into
file");
outtextxy(10,390,"Load Button : Left Click to Load an image file");
outtextxy(10,400,"Del Button : Left Click to Delete a file");
outtextxy(10,420,"Click left mouse button and drag to draw an
image");
outtextxy(40,460," A program by kalyan");

}
else
{
removelayer(0,305,400,470);
}
}
}
}
if(dx>=450&&dx<=520)
{
if(but==1)
{
clk_button3d( 450,100,80,100);
setcolor(0);
line(450,120,550,120);
outtextxy(455,110,"\\\\\\\\\");
line(450,140,550,140);
outtextxy(455,130,"/////////");
line(450,160,550,160);
outtextxy(455,150-3," *");
line(450,180,550,180);
outtextxy(455,170-3," ");
outtextxy(455,190-3," .");




}
if(dy>=100&&dy<=120)
{
if(but==1)
{
defa();
pixelflag=0;
lineflag=1;
}
}

if(dy>120&&dy<=140)
{
if(but==1)
{
defa();
pixelflag=0;
lineflag=2;
}
}
if(dy>140&&dy<=160)
{
if(but==1)
{
defa();
pixelflag=0;
starflag=1;
}
}
if(dy>160&&dy<=180)
{
if(but==1)
{
defa();
pixelflag=0;
sqflag=1;
}
}
if(dy>180&&dy<=200)
defa();

}
if( dx>=370&&dx<=420)
{
switch(dy/10)
{
case 1: if(but==1) c=15; if(but==2) {bkc=15;defa(); } break;
case 2: if(but==1) c=14; if(but==2) {bkc=14;defa(); }break;
case 3: if(but==1) c=13; if(but==2) {bkc=13;defa();}break;
case 4: if(but==1) c=12; if(but==2) {bkc=12;defa(); }break;
case 5: if(but==1) c=11; if(but==2) {bkc=11;defa(); }break;
case 6: if(but==1) c=10; if(but==2) {bkc=10;defa(); }break;
case 7: if(but==1) c= 9; if(but==2) {bkc=9;defa(); }break;
case 8: if(but==1) c= 8; if(but==2) {bkc=8;defa(); }break;
case 9: if(but==1) c= 7; if(but==2) {bkc=7;defa(); }break;
case 10: if(but==1) c=6; if(but==2) {bkc=6;defa(); }break;
case 11: if(but==1) c=5; if(but==2) {bkc=5;defa(); }break;
case 12: if(but==1) c=4; if(but==2) {bkc=4;defa(); }break;
case 13: if(but==1) c=3; if(but==2) { bkc=3;defa(); }break;
case 14: if(but==1) c=2; if(but==2) { bkc=2;defa(); }break;
case 15: if(but==1) c=1; if(but==2) { bkc=1;defa(); }break;
case 16: if(but==1) c=0; if(but==2) { bkc=0;defa(); }break;
}
setfillstyle(1,bkc);
bar(310,250,330,270);
setfillstyle(1,c);
bar(330,270,350,290);

}
get_m_button(&but,&dx,&dy);
if(dx<=600&&dy<=400)
{
sprintf(str,"%4d,%4d,%2d",dx,dy,but);
setcolor(4);
outtextxy(500,460,str);
delay(1000);
}
}
}



button3d(int x,int y,int l,int w,int cl)
{
setcolor(LIGHTGRAY);
setfillstyle(1,cl);

bar(x,y,x+l,y+w);

setcolor(WHITE);
line(x,y,x+l,y);
line(x,y,x,y+w);

setcolor(DARKGRAY);
line(x+l+1,y,x+l+1,y+w+1);
line(x,y+w+1,x+l+1,y+w+1);
}


letter(int x,int y,int l,int w,char *ch,int c)
{
char s[5];
setcolor(c);
sprintf(s,"%s",ch);
outtextxy(x+1+l-l,y+2+w-w, s);
}
save()
{
char fname[30];
int out, area, retvalue ;
gette(fname);
removelayer(100,380,560,400);
out = open ( fname, O_BINARY | O_CREAT | O_RDWR, S_IWRITE ) ;

/* if unable to open file */
if ( out == -1 )
{
setcolor(4);
outtextxy (320,390,"Unable to Save ! Hit a Key" ) ;
getch();
removelayer(100,380,550,400);
return ;
}
else
{

/* store the screen contents into allocated memory */
getimage ( 0, 0, 300, 300, p ) ;

/* find area occupied by screen image in memory */
area = imagesize ( 0, 0, 300, 300 ) ;

/* copy the stored contents into the file */
write ( out, p, area ) ;

/* close the file */
close ( out ) ;

setcolor(4);
outtextxy (220,390,"File Successfully Saved ! Hit a Key" ) ;
getch();
removelayer(100,380,560,400);

return;
}
}

/* loads a drawing from file into memory */
load()
{
char fname[30] ;
int area, in, retvalue ;
gette(fname);
removelayer(100,380,560,400);

/* open the file */
in = open ( fname, O_BINARY | O_RDONLY ) ;

/* if unable to open file */
if ( in == -1 )
{
setcolor(4);
outtextxy (320,390,"File not Found... ! Hit a Key" ) ;
getch();
removelayer(100,380,560,400);
return ;
}
else
{



/* find area required to accomodate file contents in memory */
area = imagesize ( 0, 0, 300, 300 ) ;


/* read the file contents into allocated memory */
read ( in, p, area ) ;

/* close the file */
close ( in ) ;

/* display the contents of allocated memory on the screen */
putimage ( 0, 0, p, COPY_PUT ) ;

setcolor(4);
outtextxy (220,390,"File Successfully Loaded! Hit a Key" ) ;
getch();
removelayer(100,380,560,400);
return;
}


}

/* gets a string from keyboard */
getstring ( char *str, int col )
{
int i = 0 ;
char ch ;

/* receive text */
while ( 1 )
{
/* receive key */
fflush ( stdin ) ;

/* if special key like arrow keys etc. are hit, ignore them */
if ( ( ch = getch() ) == 0 )
{
getch() ;
continue ;
}

/* if Enter key is hit, terminate string */
if ( ch == 13 )
{
str[i] = '
 

 

 

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