Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1//
- #include<stdio.h>
- #include<graphics.h>
- #include<conio.h>
- int main(){
- char ch;
- int gd = DETECT,gm; //gdriver,gmode
- int i,x,y,xrad=200,yrad=100;
- initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
- /* Initialize center of circle with center of screen */
- x = getmaxx()/2;
- y = getmaxy()/2;
- outtextxy(x-100, 50, "Ellipse Using Graphics in C");
- line(x-220,y,x+220,y);
- line(x,y-120,x,y+120);
- ellipse(x,y,0,360,xrad,yrad);
- for(i=EMPTY_FILL;i<USER_FILL;i++)
- {
- setfillstyle(i,RED); //getmaxcolor()
- fillellipse(x,y,xrad,yrad);
- getch();
- }
- closegraph();
- return 0;
- }
- 2//
- #include<stdio.h>
- #include<graphics.h>
- #include<conio.h>
- int main(){
- char ch;
- int gd = DETECT,gm;
- int x,y,x1,y1,radius=50,dir=0,speed=2;
- initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
- /* Initialize center of circle with center of screen */
- x1 = getmaxx()/2-100;
- y1 = getmaxy()/2;
- x=x1;
- y=y1;
- while(1)
- {
- outtextxy(x1-50, 50, "CIRCLE Rolling Using Graphics in C");
- line(x1,y1+radius,x1+200,y1+radius);
- circle(x, y, radius);
- if(dir==2) break;
- if(dir==0) //UP
- {
- x+=speed;
- if(x>x1+200) {dir=1;x-=speed;y+=(2*radius);}
- }
- else //DOWN
- {
- x-=speed;
- if(x<x1) {dir=2;x+=speed;y-=(2*radius);}
- }
- delay(30);
- cleardevice();
- }
- getch();
- closegraph();
- return 0;
- }
- 3//
- #include<stdio.h>
- #include<graphics.h>
- #include<conio.h>
- int main(){
- char ch;
- int gd = DETECT,gm;
- int x,y,x1,y1,radius=50,dir=0,speed=2;
- initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
- /* Initialize center of circle with center of screen */
- x1 = getmaxx()/2-100;
- y1 = getmaxy()/2;
- x=x1;
- y=y1;
- while(1)
- {
- outtextxy(x1-50, 50, "CIRCLE Rolling Using Graphics in C");
- line(x1,y1+radius,x1+200,y1+radius);
- circle(x, y, radius);
- ch=getch();
- if(ch==27) exit(0);
- if(ch==0)
- {
- ch=getch();
- if(ch==77) //D,Right,Clockwise
- {
- if(dir==0) //UP
- {
- x+=speed;
- if(x>x1+200) {dir=1;x-=speed;y+=(2*radius);}
- }
- else //DOWN
- {
- x-=speed;
- if(x<x1) {dir=0;x+=speed;y-=(2*radius);}
- }
- }
- else if(ch==75) //A,Left,Anticlockwise
- {
- if(dir==0) //UP
- {
- x-=speed;
- if(x<x1) {dir=1;x+=speed;y+=(2*radius);}
- }
- else //DOWN
- {
- x+=speed;
- if(x>x1+200) {dir=0;x-=speed;y-=(2*radius);}
- }
- }
- }
- cleardevice();
- delay(1);
- }
- //closegraph();
- //return 0;
- }
- 4//
- #include<stdio.h>
- #include<graphics.h>
- #include<conio.h>
- int main(){
- char ch;
- int gd = DETECT,gm;
- int x,y,radius=50;
- initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
- /* Initialize center of circle with center of screen */
- x = getmaxx()/2;
- y = getmaxy()/2;
- while(1)
- {
- outtextxy(x-170, 50, "CIRCLE Zoom in-Zoom out Using Graphics.h in C");
- circle(x, y, radius);
- ch=getch();
- if(ch==27) exit(0);
- if(ch=='a') {radius+=1;}
- if(ch=='z') {radius-=1;}
- cleardevice();
- delay(1);
- }
- }
- 5//
- #include<stdio.h>
- #include<graphics.h>
- #include<conio.h>
- int main(){
- char ch;
- int gd = DETECT,gm; //gdriver,gmode
- int i,j,x,y,max,x1,sx,ex,l,dx;
- initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
- /* Initialize center of circle with center of screen */
- x = getmaxx()/2;
- y = getmaxy()/2;
- max=getmaxcolor();
- sx=x-200,ex=x+200,l=5,dx=2;
- for(i=0;i<max;i++)
- {
- setcolor(WHITE);
- outtextxy(x-120, 50, "Dashed Line Using Graphics in C");
- setcolor(i+1);
- for(x1=sx;x1<=ex;x1+=(l+dx)) line(x1,y,x1+l,y);
- //setcolor((i+2)%max+1);
- //for(x1=sx;x1<=ex;x1+=(l+dx)) line(x1,y+20,x1+l,y+20);
- //setcolor((i+3)%max+1);
- //for(x1=sx;x1<=ex;x1+=(l+dx)) line(x1,y+40,x1+l,y+40);
- getch();
- }
- closegraph();
- return 0;
- }
- 6//
- #include<stdio.h>
- #include<graphics.h>
- #include<conio.h>
- int main(){
- char ch;
- int gd = DETECT,gm; //gdriver,gmode
- int i,x,y,dx=50,dy=20;
- initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
- /* Initialize center of circle with center of screen */
- x = getmaxx()/2;
- y = getmaxy()/2;
- outtextxy(x-70, 50, "Ghus Jao Andar :P");
- rectangle(x-dx,y-dy,x+dx,y+dy);
- for(i=0;i<2;i++)
- {
- dx*=2;dy*=2;
- line(x-dx,y,x,y-dy);
- line(x,y-dy,x+dx,y);
- line(x+dx,y,x,y+dy);
- line(x,y+dy,x-dx,y);
- rectangle(x-dx,y-dy,x+dx,y+dy);
- }
- getch();
- closegraph();
- return 0;
- }
- 7//
- #include<stdio.h>
- #include<graphics.h>
- #include<conio.h>
- #include<math.h>
- int main(){
- char ch;
- int gd = DETECT,gm; //gdriver,gmode
- int i,x,y,x1,y1,x2,y2,rad=100;
- float alpha=0.0;
- initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
- /* Initialize center of circle with center of screen */
- x = getmaxx()/2;
- y = getmaxy()/2;
- x1=x,y1=y,x2=x+rad*cos(alpha),y2=y+rad*sin(alpha);
- while(1)
- {
- outtextxy(x-50, 50, "De Ghumake :P");
- circle(x,y,rad);
- line(x1,y1,x2,y2);
- ch=getch();
- if(ch==27) exit(0);
- if(ch==0)
- {
- ch=getch();
- if(ch==77) //Right Key
- {
- alpha+=0.05;
- x2=x+rad*cos(alpha);
- y2=y+rad*sin(alpha);
- }
- if(ch==75) //Left Key
- {
- alpha-=0.05;
- x2=x+rad*cos(alpha);
- y2=y+rad*sin(alpha);
- }
- }
- delay(1);
- cleardevice();
- }
- }
- 8//
- #include <graphics.h>
- #include <dos.h>
- union REGS i,o;
- void detect_mouse ()
- {
- i.x.ax = 0;
- int86 (0X33,&i,&o); //invoke interrupt
- if (o.x.ax == 0)
- printf ("\nMouse Failed To Initialize");
- else
- printf ("\nMouse was Succesfully Initialized");
- }
- show_mouse()
- {
- i.x.ax=1;
- int86(0x33,&i,&o);
- }
- hide_mouse()
- {
- i.x.ax=2;
- int86(0x33,&i,&o);
- }
- get_mouse_pos(int *x,int *y,int *button)
- {
- i.x.ax=3;
- int86(0x33,&i,&o);
- *x=o.x.cx;
- *y=o.x.dx;
- *button=o.x.bx&1;
- }
- main()
- {
- int gdriver = DETECT, gmode, errorcode,button,x1,y1,x2,y2;
- initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
- detect_mouse ();
- outtextxy(230,400,"Press any key to exit....");
- while(!kbhit())
- {
- show_mouse();
- get_mouse_pos(&x1,&y1,&button);
- x2=x1;
- y2=y1;
- while(button==1)
- {
- hide_mouse();
- line(x1,y1,x2,y2) ;
- x1=x2;
- y1=y2;
- get_mouse_pos(&x2,&y2,&button);
- }
- }
- }
- 9//
- #include <graphics.h>
- #include <dos.h>
- union REGS i,o;
- void detect_mouse ()
- {
- i.x.ax = 0;
- int86 (0X33,&i,&o); //invoke interrupt
- printf(" ");
- //if (o.x.ax == 0) printf ("\nMouse Failed To Initialize");
- //else printf ("\nMouse was Succesfully Initialized");
- }
- show_mouse()
- {
- i.x.ax=1;
- int86(0x33,&i,&o);
- }
- hide_mouse()
- {
- i.x.ax=2;
- int86(0x33,&i,&o);
- }
- get_mouse_pos(int *x,int *y,int *button)
- {
- i.x.ax=3;
- int86(0x33,&i,&o);
- *x=o.x.cx;
- *y=o.x.dx;
- *button=o.x.bx&7;
- }
- main()
- {
- int gdriver = DETECT, gmode, errorcode,button,x1,y1,x2,y2;
- initgraph(&gdriver, &gmode, "C:\\TC\\BGI");
- detect_mouse();
- //outtextxy(175,50,"Engineering chodo, Painting Karo :P ");
- while(!kbhit())
- {
- show_mouse();
- get_mouse_pos(&x1,&y1,&button);
- x2=x1;
- y2=y1;
- if(button>0)
- {
- while(button==1)
- {
- setcolor(WHITE);
- hide_mouse();
- line(x1,y1,x2,y2) ;
- x1=x2;
- y1=y2;
- get_mouse_pos(&x2,&y2,&button);
- }
- if(button==2) {cleardevice();}
- }
- }
- }
- 10//
- #include <graphics.h>
- #include <dos.h>
- union REGS i,o;
- void detect_mouse ()
- {
- i.x.ax = 0;
- int86 (0X33,&i,&o); //invoke interrupt
- if (o.x.ax == 0) printf ("\nMouse Failed To Initialize");
- else printf ("\nMouse was Succesfully Initialized");
- }
- show_mouse()
- {
- i.x.ax=1;
- int86(0x33,&i,&o);
- }
- hide_mouse()
- {
- i.x.ax=2;
- int86(0x33,&i,&o);
- }
- get_mouse_pos(int *x,int *y,int *button)
- {
- i.x.ax=3;
- int86(0x33,&i,&o);
- *x=o.x.cx;
- *y=o.x.dx;
- *button=o.x.bx&1;
- }
- main()
- {
- int gdriver = DETECT, gmode, errorcode,button,x1,y1,x2,y2;
- initgraph(&gdriver, &gmode, "C:\\TC\\BGI");
- detect_mouse();
- outtextxy(175,50,"Engineering chodo, Painting Karo :P ");
- setfillstyle(SOLID_FILL,RED);
- rectangle(270,400,300,430);
- floodfill(285,415,WHITE);
- setfillstyle(SOLID_FILL,GREEN);
- rectangle(300,400,330,430);
- floodfill(315,415,WHITE);
- setfillstyle(SOLID_FILL,BLUE);
- rectangle(330,400,360,430);
- floodfill(345,415,WHITE);
- while(!kbhit())
- {
- show_mouse();
- get_mouse_pos(&x1,&y1,&button);
- x2=x1;
- y2=y1;
- while(button==1)
- {
- if(x1>270 &&x1<300 && y1>400 && y1<430) {setcolor(RED);}
- if(x1>300 &&x1<330 && y1>400 && y1<430) {setcolor(GREEN);}
- if(x1>330 &&x1<360 && y1>400 && y1<430) {setcolor(BLUE);}
- hide_mouse();
- line(x1,y1,x2,y2) ;
- x1=x2;
- y1=y2;
- get_mouse_pos(&x2,&y2,&button);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement