Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- C code to animate benzene ring
- Sandipan Dey
- BCSE, JU, Kolkata
- 2003
- */
- #include "stdio.h"
- #include "conio.h"
- #include "graphics.h"
- #include "dos.h"
- #include "malloc.h"
- #include "math.h"
- #define PI 3.14159
- void arrow(int x,int y,int sa,int ea,int r,int b1,int b2) {
- int y1,x1;
- arc(x,y,sa,ea,r);
- x1=x+r*cos(PI*ea/180);
- y1=y-r*sin(PI*ea/180);
- line(x1,y1,x1-b1*10,y1);
- line(x1,y1,x1,y1+b2*10);
- }
- void jumpelectron(int i,int j,int* poly,int c,int x,int y,int z,int w) {
- setcolor(c);
- line(poly[2*i-2]+x,poly[2*i-1]+y,poly[2*j-2]+z,poly[2*j-1]+w);
- setcolor(getmaxcolor());
- }
- void main() {
- int gd=DETECT,gm,poly[14],size;
- void* bmp1,*bmp2;
- initgraph(&gd,&gm,"");
- poly[0]=poly[1]=100;
- poly[2]=50;poly[3]=150;
- poly[4]=50;poly[5]=221;
- poly[6]=100;poly[7]=271;
- poly[8]=150;poly[9]=221;
- poly[10]=poly[11]=150;
- poly[12]=poly[13]=poly[0];
- drawpoly(7,poly);
- line(60,150,100,110);
- line(60,221,100,261);
- line(140,150,140,221);
- line(100,85,100,100);
- settextstyle(DEFAULT_FONT,HORIZ_DIR,2);
- outtextxy(80,70,":O-H");
- outtextxy(90,50,".");
- outtextxy(98,50,".");
- size=imagesize(85,51,110,65);
- bmp2=malloc(size);
- getimage(85,51,110,65,bmp2);
- outtextxy(250,250,"To Start :Press Ctrl-S");
- while(getch()!=19){fflush(stdin);}
- ellipse(87,79,0,360,7,12);
- size=imagesize(80,67,94,91);
- bmp1=malloc(size);
- getimage(80,67,94,91,bmp1);
- delay(2000);
- arrow(85,87,110,320,12,1,1);
- arrow(35,140,20,270,15,1,-1);
- delay(2000);
- putimage(80,67,bmp1,XOR_PUT);
- putimage(30,140,bmp1,COPY_PUT);
- setcolor(0);
- arrow(85,87,110,320,12,1,1);
- arrow(35,140,20,270,15,1,-1);
- setcolor(getmaxcolor());
- line(105,85,105,100);
- jumpelectron(1,2,poly,0,10,0,0,10);
- delay(2000);
- arrow(30,160,90,340,15,1,1);
- arrow(75,265,120,340,15,1,1);
- delay(2000);
- putimage(30,140,bmp1,XOR_PUT);
- jumpelectron(2,3,poly,getmaxcolor(),10,0,10,0);
- jumpelectron(3,4,poly,0,10,0,0,-10);
- setcolor(0);
- arrow(30,160,90,340,15,1,1);
- arrow(75,265,120,340,15,1,1);
- setcolor(getmaxcolor());
- putimage(82,275,bmp2,COPY_PUT);
- ellipse(100,283,0,360,12,7);
- free(bmp2);
- size=imagesize(300,300,335,325);
- bmp2=malloc(size);
- getimage(300,300,335,325,bmp2);
- delay(2000);
- arrow(120,265,250,60,15,-1,1);
- arrow(170,160,210,150,15,-1,-1);
- delay(2000);
- putimage(82,275,bmp2,COPY_PUT);
- jumpelectron(5,6,poly,0,-10,0,-10,0);
- jumpelectron(4,5,poly,getmaxcolor(),0,-10,-10,0);
- putimage(160,140,bmp1,COPY_PUT);
- setcolor(0);
- arrow(120,265,250,60,15,-1,1);
- arrow(170,160,210,150,15,-1,-1);
- setcolor(getmaxcolor());
- delay(2000);
- arrow(160,125,320,180,20,-1,-1);
- arrow(115,65,260,210,32,1,-1);
- delay(2000);
- putimage(160,140,bmp2,COPY_PUT);
- jumpelectron(6,1,poly,getmaxcolor(),-10,0,0,10);
- settextstyle(DEFAULT_FONT,HORIZ_DIR,2);
- outtextxy(80,70,":");
- setcolor(0);
- line(105,85,105,100);
- arrow(160,125,320,180,20,-1,-1);
- arrow(115,65,260,210,32,1,-1);
- setcolor(getmaxcolor());
- delay(2000);
- jumpelectron(2,3,poly,0,10,0,10,0);
- jumpelectron(4,5,poly,0,0,-10,-10,0);
- jumpelectron(6,1,poly,0,-10,0,0,10);
- ellipse(100,185,0,360,40,55);
- delay(2000);
- free(bmp1);
- free(bmp2);
- getch();
- closegraph();
- }
Add Comment
Please, Sign In to add comment