Add to Favorites    Make Home Page 14418 Online  
 Language Categories  
 Our Services  

Home » C Home » Games and Graphics Home » Graphics editor in C

A D V E R T I S E M E N T

Search Projects & Source Codes:

Title Graphics editor in C
Author Siddu V.Rampur
Author Email siddurampur [at] hotmail.com
Description This is paint editor developed under 'C'. It's implements some
of the features of the Paint(as in windows paint) special features are
transformation,rotation,clipping and scaling.
Category C » Games and Graphics
Hits 383439
Code Select and Copy the Code
/* IMPLEMENTATION OF GRAPHICS EDITOR IN 'C' */ /*developed by Siddu Rampur #include<stdio.h> #include<graphics.h> #include<stdlib.h> #include<conio.h> #include<math.h> #include<dos.h> #include<string.h> #define PI 3.14159/180.0 #include"C: cexam.h" //Global declarations FILE *fp; union REGS regs; int count=0,k=50,clr=0,sx,sy,sx1,sy1; float r,minorles; //Structure to store end points of all the icons struct bpos { int x,y,tx,ty; }; const struct bpos bps[]={{616,2,637,16}, //exit 0 {2,50,22,75}, //for line 1 {27,50,47,75}, //for rectangle 2 {2,80,22,105}, //for circle 3 {27,80,47,105}, //for ellipse 4 {2,110,22,135}, //for spiral 5 {27,110,47,135}, // rotating circle 6 {2,140,22,165},//pencil 7 {27,140,47,165},//line around a circle 8 {2,170,22,195},//rubber 9 {27,170,47,195},//cohen 10 {2,200,22,225},//scaling 11 {2,230,47,250},//trans 12 {2,255,47,275},//rotation 13 {2,280,47,300}, //select 14 {2,305,47,325}, //clip 15 {27,200,47,225}, //text 16 {2,330,47,350}, // segmentation17 {2,355,47,375}, //flood fill 18 {0,21,34,40}, //new 19 {35,21,67,40},//save 20 {68,21,100,40},//load 21 {101,21,133,40},//help 22 {134,21,166,40},//clear 23 }; void put_pixel1(int x,int y,int col) { if(53<=x&&x<=getmaxx()-3&&43<=y&&y<=437) putpixel(x,y,col); else if(count==1) putpixel(x,y,col); } void put_pixel(int x,int y,int col) { int i; unsigned char col1=col; if(53<=x&&x<=getmaxx()-3&&43<=y&&y<=437) { col1=~(col1); asm mov ah,0xc asm mov al,col1 asm or al,0x80 asm mov bh,00 asm mov cx,x asm mov dx,y asm int 0x10 } } void exchange(int *v1,int *v2) { int temp; temp=*v1; *v1=*v2; *v2=temp; } void setpixel(int x,int y,int slp,int c,int select) { int temp; if(slp) exchange(&x,&y); if(select==1) put_pixel(x,y,c); else put_pixel1(x,y,c); } void b_line(int x1,int y1,int x2,int y2,int c,int select) { int dx,dy,c1,c2,sty,sgt; long int p; dx=abs(x2-x1); dy=abs(y2-y1); sgt=(dy>dx); if(sgt) { exchange(&x1,&y1); exchange(&x2,&y2); exchange(&dx,&dy); } c1=2*dy; c2=2*(dy-dx); p=c1-dx; if(x2<x1) { exchange(&x1,&x2); exchange(&y1,&y2); } if(y2>y1) sty=1; else sty=-1; setpixel(x1,y1,sgt,c,select); while(x1<x2) { ++x1; if(p<0) p+=c1; else { p+=c2; y1+=sty; } setpixel(x1,y1,sgt,c,select); } } void condputcirclepoints(int h,int k,int x,int y,int count,int c) { if(count) { put_pixel1(h+x,y+k,c); put_pixel1(h+y,k+x,c); put_pixel1(h-x,k+y,c); put_pixel1(h-y,k+x,c); } else { put_pixel1(h-y,k-x,c); put_pixel1(h-x,k-y,c); put_pixel1(h+x,k-y,c); put_pixel1(h+y,k-x,c); } } void half(int h,int k, int radius,int count,int color) { int x=0; int y=radius; int d=1-radius; condputcirclepoints(h,k,x,y,count,color); while(y>x) { if(d<0) d+=2*x+3; else { d+=2*(x-y)+5; y--; } x++; condputcirclepoints(h,k,x,y,count,color); } } void dspiral(int h,int k,int radius,int r,int color) { int i; for(i=0;i<=radius;i+=r) { if(i%(2*r)==0) half(h,k,i,1,color); else half(h+r,k,i,0,color); } } void icon_wheel() { float p=M_PI/4,q=0; int j; circle(37,122,8); circle(37,122,5); for(j=0;j<4;j++) { line(37-5*cos(q),122-5*sin(q),37+5*cos(q),122+5*sin(q)); q+=p; } } void initial_settings(void) { int i,j,color; //setting background of the screen with darkgray colour setbkcolor(DARKGRAY); setcolor(1); rectangle(0,0,getmaxx(),getmaxy()); setfillstyle(SOLID_FILL,9); bar(0,0,getmaxx(),18);//blue bar at the top of the screen setfillstyle(SOLID_FILL,7); bar(0,21,getmaxx()-1,40);//light gray bar below the blue bar setcolor(0); line(0,41,50,41);//line separating the tool bar with paint bar bar(0,42,50,getmaxy());//vertical paint bar bar(50,440,getmaxx(),getmaxy());//bar showing colour options line(0,439,50,439);//line separating paint bar with colour option bar setfillstyle(SOLID_FILL,15); bar(53,43,getmaxx()-3,437);//white bar for displaying bar(201,21,499,39); settextstyle(4,0,3); setcolor(1); rectangle(200,20,500,40); setcolor(15); settextstyle(0,0,1); outtextxy(15,5,"Untitled-paint"); setfillstyle(SOLID_FILL,15); bar(5,getmaxy()-34,35,getmaxy()-8);//colour option displaying main box bar(getmaxx()-80,getmaxy()-18,getmaxx()-12,getmaxy()-1); setcolor(0); settextstyle(2,0,0); outtextxy(getmaxx()-48,getmaxy()-14,","); setcolor(0); rectangle(getmaxx()-81,getmaxy()-19,getmaxx()-11,getmaxy());//boxes showing pixel positions setfillstyle(SOLID_FILL,7); bar(15,getmaxy()-28,30,getmaxy()-13);//for shadow setfillstyle(SOLID_FILL,8); bar(11,getmaxy()-31,25,getmaxy()-19);//actual box displaying colour box //bars displaying all possible colours in two rows for(i=39,color=0;color<=7;color++) { setfillstyle(SOLID_FILL,color); bar(i,getmaxy()-34,i+10,getmaxy()-23); i=i+13; } for(i=39,color=8;color<=15;color++) { setfillstyle(SOLID_FILL,color); bar(i,getmaxy()-19,i+10,getmaxy()-8); i=i+13; } setcolor(15); for(i=1,j=38;i<=8;i++) { rectangle(j,getmaxy()-35,j+11,getmaxy()-22); rectangle(j,getmaxy()-20,j+11,getmaxy()-7); j=j+13; } setfillstyle(SOLID_FILL,7); bar(getmaxx()-22,2,getmaxx()-2,17);//for close window option setcolor(0); rectangle(10,getmaxy()-32,26,getmaxy()-18); rectangle(getmaxx()-23,1,getmaxx()-1,17); line(getmaxx()-4,5,getmaxx()-20,13); line(getmaxx()-4,6,getmaxx()-20,14); line(getmaxx()-20,5,getmaxx()-4,13); line(getmaxx()-20,6,getmaxx()-4,14); setcolor(15); //boxes displaying options to draw for(i=50;i<=200;i=i+30) for(j=2;j<=27;j=j+25) line(j,i,j+20,i); for(i=2;i<=27;i=i+25) for(j=50;j<=200;j=j+30) line(i,j,i,j+25); setcolor(0); for(i=75;i<=240;i=i+30) //boxes showing possible optins to draw for(j=2;j<=27;j=j+25) { line(j,i,j+20,i); //window() } for(i=22;i<=47;i=i+25) for(j=50;j<=200;j=j+30) { line(i,j,i,j+25); } setcolor(0); for(i=250;i<=350+25;i=i+25)//for displaying long boxes line(2,i,47,i); for(i=230;i<=330+25;i=i+25) line(47,i,47,i+20); setcolor(15); for(i=230;i<=330+25;i=i+25) line(2,i,47,i); for(i=230;i<=330+25;i=i+25) line(2,i,2,i+20); setcolor(0); line(5,54,19,71); rectangle(31,53,43,72); circle(10,208,5); setlinestyle(0,1,3); setcolor(1); line(14,212,18,216); line(15,213,20,218); setlinestyle(0,1,1); setcolor(0); circle(12,92,7); ellipse(37,92,2,362,8,3); count=1; dspiral(12,122,8,1,0); count=0; icon_wheel(); setcolor(0); setfillstyle(SOLID_FILL,14); bar(4,179,17,188); setfillstyle(SOLID_FILL,4); bar(10,143,15,158); rectangle(10,143,16,158); line(10,158,13,161); line(16,158,13,161); line_st(); putpixel(13,159,0); putpixel(13,160,0); line(4,179,7,176); line(17,179,20,176); line(7,176,20,176); line(7,178,20,178); line(18,188,20,185); line(18,185,18,176); line(20,185,20,176); line(31,174,45,188); setlinestyle(1,1,1); rectangle(31,176,43,188); setcolor(4); setlinestyle(0,0,1); settextstyle(2,0,0); outtextxy(10,235,"TRANS"); outtextxy(10,260,"ROTATE"); outtextxy(10,285,"SELECT"); outtextxy(14,310,"CLIP"); outtextxy(6,335,"SEGMENT"); outtextxy(14,360,"FILL"); setcolor(15); settextstyle(1,0,2); setcolor(1); outtextxy(31,199,"A"); setcolor(15); settextstyle(2,0,0); outtextxy(6,26,"New"); outtextxy(38,26,"Save"); outtextxy(72,26,"Load"); outtextxy(105,26,"About"); outtextxy(137,26,"Clear"); setcolor(7); for(i=0;i<=155;i=i+34) line(i,21,i,40);//line separating tool bars } void set_color(int x,int y) { int i,color,set=0; for(i=39,color=0;color<=7;color++) { if((i<=x&&x<=i+10)&&(getmaxy()-34<=y&&y<=getmaxy()-23)) set=color; i=i+13; } for(i=39,color=8;color<=15;color++) { if((i<=x&&x<=i+10)&&(getmaxy()-19<=y&&y<=getmaxy()-8)) set=color; i=i+13; } setfillstyle(SOLID_FILL,set); //actual box displaying colour box bar(11,getmaxy()-31,25,getmaxy()-19); } void hide_mouse() { regs.x.ax=2; int86(0x33,®s,®s); } void swap(int x,int y,int tx,int ty) { setcolor(15); line(x,y,tx,y); line(x,y,x,ty); setcolor(0); line(x,ty,tx,ty); line(tx,ty,tx,y); } void r_swap(int x,int y,int tx,int ty) { setcolor(0); line(x,y,tx,y); line(x,y,x,ty); setcolor(15); line(x,ty,tx,ty); line(tx,ty,tx,y); } void get_mouse() { regs.x.ax=0; int86(0x33,®s,®s); } void showmouse() { regs.x.ax=1; int86(0x33,®s,®s); } void in_mouse() { regs.x.ax=4; regs.x.cx=330; regs.x.dx=240; int86(0x33,®s,®s); } void restrict_mouse() { regs.x.ax=7; regs.x.cx=0; regs.x.dx=getmaxx()-5; int86(0x33,®s,®s); regs.x.ax=8; regs.x.cx=0; regs.x.dx=getmaxy()-5; int86(0x33,®s,®s); } getmouse_cur(int *xp,int *yp,int *bp) { int xm,ym,x,y; char xco[5],yco[5]; xm=getmaxx(); ym=getmaxy(); x=*xp; y=*yp; regs.x.ax=3; int86(0x33,®s,®s); *bp=regs.x.bx; *xp=regs.x.cx; *yp=regs.x.dx; if(x!=*xp||y!=*yp) { setcolor(0); setfillstyle(SOLID_FILL,15); settextstyle(0,0,0); bar(xm-80,ym-18,xm-12,ym-1); outtextxy(getmaxx()-48,getmaxy()-14,","); sprintf(xco,"%d",*xp); sprintf(yco,"%d",*yp); outtextxy(xm-70,ym-14,xco); outtextxy(xm-40,ym-14,yco); } return; } void line_draw() { int x,y,bp,i,x2,y2,x1,y1; getmouse_cur(&x,&y,&bp); if((bp&1)&&(53<=x&&x<=getmaxx()-3&&43<=y&&y<=437)) { i=getpixel(17,453); putpixel(x,y,i); x1=x; y1=y; while(bp&1) { delay(30); i=getpixel(17,453); getmouse_cur(&x2,&y2,&bp); if(x1!=x2||y1!=y2) { hide_mouse(); b_line(x,y,x1,y1,i,1); b_line(x,y,x2,y2,i,1); showmouse(); } x1=x2; y1=y2; } hide_mouse(); b_line(x,y,x2,y2,i,0); showmouse(); } } void free_hand() { int i,x,y,pvaluex,bp,pvaluey; getmouse_cur(&x,&y,&bp); if(bp&1) { hide_mouse(); pvaluex=x; pvaluey=y; while(bp&1) { delay(32); i=getpixel(17,453); getmouse_cur(&x,&y,&bp); b_line(pvaluex,pvaluey,x,y,i,0); pvaluex=x; pvaluey=y; } showmouse(); } } void eraser() { int x,y,bp,x1,y1; getmouse_cur(&x1,&y1,&bp); if((bp&1)==1) { hide_mouse(); while((bp&1)&&(64<=x1&&x1<=getmaxx()-6&&54<=y1&&y1<=434)) { setcolor(0); x=x1; y=y1; rectangle(x-10,y-10,x,y); delay(20); getmouse_cur(&x1,&y1,&bp); setlinestyle(0,0,3); setcolor(15); rectangle(x-10,y-10,x,y); } } showmouse(); setlinestyle(0,0,0); setcolor(0); } void dra_rect() { int x,y,x1,y1,bp,i,x2,y2; getmouse_cur(&x,&y,&bp); if((bp&1)&&(53<=x&&x<=getmaxx()-3&&43<=y&&y<=437)) { i=getpixel(17,453); putpixel(x,y,i); x2=x; y2=y; while(bp&1) { delay(24); i=getpixel(17,453); getmouse_cur(&x1,&y1,&bp); if(x1!=x2||y1!=y2) { hide_mouse(); b_line(x,y,x,y2,i,1); b_line(x,y,x2,y,i,1); b_line(x2,y2,x2,y,i,1); b_line(x2,y2,x,y2,i,1); showmouse(); hide_mouse(); b_line(x,y,x,y1,i,1); b_line(x,y,x1,y,i,1); b_line(x1,y1,x1,y,i,1); b_line(x1,y1,x,y1,i,1); showmouse(); } x2=x1; y2=y1; } hide_mouse(); b_line(x,y,x,y1,i,0); b_line(x,y,x1,y,i,0); b_line(x1,y1,x1,y,i,0); b_line(x1,y1,x,y1,i,0); showmouse(); } } void putcirclepoints(int h,int k,int x,int y,int c,int select) { if(select==1) { put_pixel(h+x,y+k,c); put_pixel(h+y,k+x,c); put_pixel(h-x,k+y,c); put_pixel(h-y,k+x,c); put_pixel(h-y,k-x,c); put_pixel(h-x,k-y,c); put_pixel(h+x,k-y,c); put_pixel(h+y,k-x,c); } else { put_pixel1(h+x,y+k,c); put_pixel1(h+y,k+x,c); put_pixel1(h-x,k+y,c); put_pixel1(h-y,k+x,c); put_pixel1(h-y,k-x,c); put_pixel1(h-x,k-y,c); put_pixel1(h+x,k-y,c); put_pixel1(h+y,k-x,c); } } void dcircle(int h,int k, int radius,int c,int select) { int x=0; int y=radius; int d=1-radius; putcirclepoints(h,k,x,y,c,select); while(y>x) { if(d<0) d+=2*x+3; else { d+=2*(x-y)+5; y--; } x++; putcirclepoints(h,k,x,y,c,select); } } void dra_circle() { int x,y1,y,x1,bp,i,v,x2,y2; getmouse_cur(&x,&y,&bp); if((bp&1)&&(53<=x&&x<=getmaxx()-3&&43<=y&&y<=437)) { i=getpixel(17,453); putpixel(x,y,i); x2=x; y2=y; while(bp&1) { i=getpixel(17,453); getmouse_cur(&x1,&y1,&bp); if(x1!=x2||y1!=y2) { v=(float)sqrt(((float)(x-x2)*(float)(x-x2))+((float)(y-y2)*(float)(y-y2))) ; hide_mouse(); dcircle(x,y,v,i,1); v=(float)sqrt(((float)(x-x1)*(float)(x-x1))+((float)(y-y1)*(float)(y-y1))) ; dcircle(x,y,v,i,1); delay(10); showmouse(); } x2=x1; y2=y1; delay(10); } hide_mouse(); dcircle(x,y,v,i,0); showmouse(); } } void dra_spiral() { int x,y1,y,x1,bp,i; float v; getmouse_cur(&x,&y,&bp); x=regs.x.cx; y=regs.x.dx; bp=regs.x.bx; if(bp&1) { x1=x; y1=y; while(bp&1) { hide_mouse(); delay(30); i=getpixel(17,453); b_line(x,y,x1,y1,i,1); getmouse_cur(&x1,&y1,&bp); showmouse(); hide_mouse(); b_line(x,y,x1,y1,i,1); showmouse(); } hide_mouse(); b_line(x,y,x1,y1,i,1); v=(float)sqrt(((float)(x-x1)*(float)(x-x1))+((float)(y-y1)*(float)(y-y1))) ; dspiral(x,y,v,1+0.040*v,i); showmouse(); } } void dra_rotate() { int l=0,x,y,bp,i1,i,xc,yc=200,x1,y1,x2,y2; double rad=20,rad1=45,theta,val; val=M_PI/4; while(l==0) { xc=105; for(theta=0;theta<2*M_PI;theta+=.13) { getmouse_cur(&x,&y,&bp); if(bp&1) { l=1; break; } i1=getpixel(17,453); setcolor(i1); hide_mouse(); circle(xc,yc,rad); circle(xc,yc,rad1); for(i=0;i<8;i++) { x1=xc+rad*cos(theta+i*val); x2=xc+rad1*cos(theta+i*val); y1=yc+rad*sin(theta+i*val); y2=yc+rad1*sin(theta+i*val); line(x1,y1,x2,y2); } showmouse(); delay(150); hide_mouse(); setcolor(15); circle(xc,yc,rad); circle(xc,yc,rad1); for(i=0;i<8;i++) { x1=xc+rad*cos(theta+i*val); x2=xc+rad1*cos(theta+i*val); y1=yc+rad*sin(theta+i*val); y2=yc+rad1*sin(theta+i*val); line(x1,y1,x2,y2); } xc+=10; showmouse(); } if(l==1) break; } } void putellpoints(int x,int y,int h,int k,int c,int m) { if(m) { put_pixel(x+h,y+k,c); put_pixel(h-x,k+y,c); put_pixel(x+h,-y+k,c); put_pixel(h-x,k-y,c); } else { put_pixel1(x+h,y+k,c); put_pixel1(h-x,k+y,c); put_pixel1(x+h,-y+k,c); put_pixel1(h-x,k-y,c); } } void dell(int h,int k,float a,float b,int c,int m) { float p1,p2; float x,y; x=0.0; y=b; p1=2*b*b-2*a*a*b+a*a; while(a*a*(y-0.5)>b*b*(x+1)) { putellpoints(x,y,h,k,c,m); if(p1<0) p1+=(2*x+3)*b*b; else { p1+=(2*x+3)*b*b+a*a*(2-2*y); y--; } x++; } putellpoints(x,y,h,k,c,m); p2=b*b*(x+0.5)*(x+0.5)+a*a*(y-1)*(y-1)-a*a*b*b; while(y>0) { if(p2<0) { p2+=b*b*(2*x+2)+a*a*(-2*y+3); x++; } else p2+=a*a*(-2*y+3); y--; putellpoints(x,y,h,k,c,m); } } void draw_ellipse() { int i,x,y,x1,y1,bp,x2,y2; getmouse_cur(&x,&y,&bp); if(bp& 1) { x2=x; y2=y; while(bp&1) { delay(30); i=getpixel(17,453); getmouse_cur(&x1,&y1,&bp); if(x1!=x2||y1!=y2) { hide_mouse(); dell(x,y,abs(((float)x-(float)x2))+1,abs(((float)y-(float)y2))+1,i,1); dell(x,y,abs(((float)x-(float)x1))+1,abs(((float)y-(float)y1))+1,i,1); showmouse(); x2=x1; y2=y1; } } hide_mouse(); dell(x,y,abs(((float)x-(float)x1))+1,abs(((float)y-(float)y1))+1,i,0); showmouse(); }} void file_open(char *str) { int m,i,j; fp=fopen(str,"r"); if(fp) while(1) { if(fscanf(fp,"%d%d%d",&i,&j,&m)) putpixel(i,j,m); else break; } fclose(fp); } void file_save(char *string,int x,int y,int x1,int y1) { int i,j,m; fp=fopen(string,"w"); for(i=x;i<=x1;i++) { for(j=y;j<=y1;j++) { m=getpixel(i,j); if(m!=15) fprintf(fp,"%d %d %d ",i,j,m); } } fputc(EOF,fp); fclose(fp); } void f_save() { int i=0,j,m; char ch,string[30],*buf; long int a; hide_mouse(); a=imagesize(213,123,420,278); buf=(char *)malloc(a); getimage(213,123,420,278,buf); setfillstyle(SOLID_FILL,7); bar(215,125,418,275); rectangle(214,124,419,276); r_swap(230,200,403,220); setfillstyle(SOLID_FILL,9); settextstyle(1,0,4); outtextxy(270,130,"save"); settextstyle(4,0,1); bar(215,125,418,140); setcolor(0); outtextxy(234,165,"no extension required"); setfillstyle(SOLID_FILL,15); bar(231,201,402,219); while((ch=getch())!=0xd &&ch!=0x20&&i<=9) { bar(231,201,402,219); string[i]=ch; if(ch==0x8&&i==0) continue; if(ch==0x8) i--; else i++; string[i]='

Related Source Codes

Script Name Author
The Game Opposite as seen on Nokia 2300 Mobile Manikanta
RECURSIVE BALANCED QUICK SORT ashish
Radix Sort ashish
Change your mouse pointer Ashim
The blinking star Shashank
Data Validation Crylittlebaby
To search a file by giving file type like mp3 or mpeg or doc Prashanth SR
Menus Demonstration B.Chidhambaram
Employee Database Project Using C. Reenku Raman Nayak
Creating a Lexical Analyzer in c fahad bader al-buhairi �դ ?�� ��??���
Calendar Program Omkar & Devendra
Stop double Process for start in C Cedrik Jurak
Stop double Process for start in C Cedrik Jurak
Time Scheduler Atiq Anwar
A timepass game between atmost two players Rahul Roy

A D V E R T I S E M E N T




Google Groups Subscribe to SourceCodesWorld - Techies Talk
Email:

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

New! Click here to Add your Code!


ASP Home | C Home | C++ Home | COBOL Home | Java Home | Pascal Home
Source Codes Home Page

 Advertisements  

Google Search

Google

Source Codes World.com is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions | Important Websites
Copyright ©2003-2024 SourceCodesWorld.com, All Rights Reserved.
Page URL: http://www.sourcecodesworld.com/source/show.asp?ScriptID=591


Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review