Download Paint Brush Full Source Code
Paint brush using graphics.h library
Below is an easy syntax code of paint brush tested on codeBlocks.
Paint brush has following drawing functionality.
- Drawing circle.
- Drawing rectangle.
- Drawing ellipse.
- Drawing Line
You can draw any shape in any color.
#include <iostream>
#include<graphics.h> #include<Image.h> #include<math.h> //#include<Image.h> using namespace std; int main() { int gd=DETECT; int gm; initgraph(&gd,&gm,"C:\\TC\\BGI"); int midx=getmaxx()/2; int midy=getmaxy()/2; initwindow(1000,600); int x,y,x1,y1,xt,yt,cx,cy,cx1,cy1,option=0; int shape_color; setbkcolor(15); while(1){ if(ismouseclick(WM_LBUTTONDOWN)){ getmouseclick(WM_LBUTTONDOWN,cx,cy); getmouseclick(WM_LBUTTONUP,cx1,cy1); if(cx>=30&&cx1<=70&&cy>=40&&cy1<=80){ option=1; } if(cx>=97&&cx1<=143&&cy>=37&&cy1<=83){ option=2; //circle(120,60,20+i-2); } if(cx>=160&&cx1<=220&&cy>=45&&cy1<=85){ option=3; //line(160,40+i,220,80+i); } if(cx>=350&&cx1<=290&&cy>=40&&cy1<=80){ // ellipse(370,60,0,360,20,30); option=4; } //COLORS if(cx>=500&&cx1<=520&&cy>=40&&cy1<=60){ option=11; } if(cx>=525&&cx1<=545&&cy>=40&&cy1<=60){ option=12; } if(cx>=550&&cx1<=570&&cy>=40&&cy1<=60){ option=13; } if(cx>=575&&cx1<=595&&cy>=40&&cy1<=60){ option=14; } if(cx>=600&&cx1<=620&&cy>=40&&cy1<=60){ option=15; } if(cx>=625&&cx1<=645&&cy>=40&&cy1<=85){ option=16; } if(cx>=650&&cx1<=670&&cy>=40&&cy1<=85){ option=17; } if(cx>=500&&cx1<=520&&cy>=65&&cy1<=85){ option=18; } if(cx>=525&&cx1<=545&&cy>=65&&cy1<=85){ option=19; } if(cx>=550&&cx1<=570&&cy>=65&&cy1<=85){ option=20; } if(cx>=575&&cx1<=595&&cy>=65&&cy1<=85){ option=21; } if(cx>=600&&cx1<=620&&cy>=65&&cy1<=85){ option=22; } if(cx>=625&&cx1<=645&&cy>=65&&cy1<=85){ option=23; } if(cx>=650&&cx1<=670&&cy>=65&&cy1<=85){ option=24; } } //PAINT-PAGE-Setting for(int i=1;i<=2;i++){ line(i,10+i,990+i,10+i); line(i,100+i,990+i,100+i); line(i,110+i,990+i,110+i); rectangle(480,30,700,90); rectangle(470,25,710,95); } //COLOR BOXES setfillstyle(SOLID_FILL,1); bar(500,40,520,60);//RED setfillstyle(SOLID_FILL,2); bar(525,40,545,60); setfillstyle(SOLID_FILL,3); bar(550,40,570,60); setfillstyle(SOLID_FILL,4); bar(575,40,595,60); setfillstyle(SOLID_FILL,5); bar(600,40,620,60); setfillstyle(SOLID_FILL,6); bar(625,40,645,60); setfillstyle(SOLID_FILL,7); bar(650,40,670,60); setfillstyle(SOLID_FILL,8); bar(500,65,520,85);//RED setfillstyle(SOLID_FILL,9); bar(525,65,545,85); setfillstyle(SOLID_FILL,10); bar(550,65,570,85); setfillstyle(SOLID_FILL,11); bar(575,65,595,85); setfillstyle(SOLID_FILL,12); bar(600,65,620,85); setfillstyle(SOLID_FILL,13); bar(625,65,645,85); setfillstyle(SOLID_FILL,14); bar(650,85,670,85); line(160,40,220,80); circle(120,60,20-2); rectangle(30,40,70,80); ellipse(370,60,0,360,20,30); if(ismouseclick(WM_LBUTTONDOWN)) { getmouseclick(WM_LBUTTONDOWN,x,y); delay(1000); getmouseclick(WM_LBUTTONUP,x1,y1); //COLOR BAR CODE if(option==11){ shape_color=1;} if(option==12){ shape_color=2; } if(option==13){ shape_color=3; } if(option==14){ shape_color=4; } if(option==15){ shape_color=5; } if(option==16){ shape_color=6; } if(option==17){ shape_color=7; } if(option==18){ shape_color=8; } if(option==19){ shape_color=9; } if(option==20){ shape_color=10; } if(option==21){ shape_color=11; } if(option==22){ shape_color=12; } if(option==23){ shape_color=13; } if(option==24){ shape_color=14; } //SHAPES if(option==1){ setcolor(shape_color); rectangle(x,y,x1,y1); } if(option==2){ int r=sqrt((x1-x)*(x1-x)+(y1-y)*(y1-y)); setcolor(shape_color); circle((x1+x)/2,(y1+y)/2,r/2); } if(option==3){ setcolor(shape_color); line(x,y,x1,y1); } } if(option==4){ int xr=sqrt((x1-x)*(x1-x)); int yr=sqrt((y1-y)*(y1-y)); setcolor(shape_color); ellipse((x1+x)/2,(y1+y)/2,0,360,xr/2,yr/2); } } getch(); closegraph(); } |