sandipan

Bezene Kekule Ring Animation with C BGI graphics in MSDOS

Sep 6th, 2018
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.15 KB | None | 0 0
  1. /*
  2.  C code to animate benzene ring
  3.  Sandipan Dey
  4.  BCSE, JU, Kolkata
  5.  2003
  6. */
  7.  
  8. #include "stdio.h"
  9. #include "conio.h"
  10. #include "graphics.h"
  11. #include "dos.h"
  12. #include "malloc.h"
  13. #include "math.h"
  14.  
  15. #define PI 3.14159
  16.  
  17. void arrow(int x,int y,int sa,int ea,int r,int b1,int b2) {
  18.     int y1,x1;
  19.     arc(x,y,sa,ea,r);
  20.     x1=x+r*cos(PI*ea/180);
  21.     y1=y-r*sin(PI*ea/180);
  22.     line(x1,y1,x1-b1*10,y1);
  23.     line(x1,y1,x1,y1+b2*10);
  24. }
  25.  
  26. void jumpelectron(int i,int j,int* poly,int c,int x,int y,int z,int w) {
  27.     setcolor(c);
  28.     line(poly[2*i-2]+x,poly[2*i-1]+y,poly[2*j-2]+z,poly[2*j-1]+w);
  29.     setcolor(getmaxcolor());
  30. }
  31.  
  32. void main() {
  33.  
  34.     int gd=DETECT,gm,poly[14],size;
  35.     void* bmp1,*bmp2;
  36.     initgraph(&gd,&gm,"");
  37.     poly[0]=poly[1]=100;
  38.     poly[2]=50;poly[3]=150;
  39.     poly[4]=50;poly[5]=221;
  40.     poly[6]=100;poly[7]=271;
  41.     poly[8]=150;poly[9]=221;
  42.     poly[10]=poly[11]=150;
  43.     poly[12]=poly[13]=poly[0];
  44.     drawpoly(7,poly);
  45.     line(60,150,100,110);
  46.     line(60,221,100,261);
  47.     line(140,150,140,221);
  48.     line(100,85,100,100);
  49.     settextstyle(DEFAULT_FONT,HORIZ_DIR,2);
  50.     outtextxy(80,70,":O-H");
  51.     outtextxy(90,50,".");
  52.     outtextxy(98,50,".");
  53.     size=imagesize(85,51,110,65);
  54.     bmp2=malloc(size);
  55.     getimage(85,51,110,65,bmp2);
  56.     outtextxy(250,250,"To Start :Press Ctrl-S");
  57.     while(getch()!=19){fflush(stdin);}
  58.  
  59.     ellipse(87,79,0,360,7,12);
  60.     size=imagesize(80,67,94,91);
  61.     bmp1=malloc(size);
  62.     getimage(80,67,94,91,bmp1);
  63.  
  64.     delay(2000);
  65.     arrow(85,87,110,320,12,1,1);
  66.     arrow(35,140,20,270,15,1,-1);
  67.     delay(2000);
  68.     putimage(80,67,bmp1,XOR_PUT);
  69.     putimage(30,140,bmp1,COPY_PUT);
  70.     setcolor(0);
  71.     arrow(85,87,110,320,12,1,1);
  72.     arrow(35,140,20,270,15,1,-1);
  73.     setcolor(getmaxcolor());
  74.     line(105,85,105,100);
  75.     jumpelectron(1,2,poly,0,10,0,0,10);
  76.  
  77.     delay(2000);
  78.     arrow(30,160,90,340,15,1,1);
  79.     arrow(75,265,120,340,15,1,1);
  80.     delay(2000);
  81.     putimage(30,140,bmp1,XOR_PUT);
  82.     jumpelectron(2,3,poly,getmaxcolor(),10,0,10,0);
  83.     jumpelectron(3,4,poly,0,10,0,0,-10);
  84.     setcolor(0);
  85.     arrow(30,160,90,340,15,1,1);
  86.     arrow(75,265,120,340,15,1,1);
  87.     setcolor(getmaxcolor());
  88.     putimage(82,275,bmp2,COPY_PUT);
  89.     ellipse(100,283,0,360,12,7);
  90.     free(bmp2);
  91.     size=imagesize(300,300,335,325);
  92.     bmp2=malloc(size);
  93.     getimage(300,300,335,325,bmp2);
  94.  
  95.     delay(2000);
  96.     arrow(120,265,250,60,15,-1,1);
  97.     arrow(170,160,210,150,15,-1,-1);
  98.     delay(2000);
  99.     putimage(82,275,bmp2,COPY_PUT);
  100.     jumpelectron(5,6,poly,0,-10,0,-10,0);
  101.     jumpelectron(4,5,poly,getmaxcolor(),0,-10,-10,0);
  102.     putimage(160,140,bmp1,COPY_PUT);
  103.     setcolor(0);
  104.     arrow(120,265,250,60,15,-1,1);
  105.     arrow(170,160,210,150,15,-1,-1);
  106.     setcolor(getmaxcolor());
  107.  
  108.     delay(2000);
  109.     arrow(160,125,320,180,20,-1,-1);
  110.     arrow(115,65,260,210,32,1,-1);
  111.     delay(2000);
  112.     putimage(160,140,bmp2,COPY_PUT);
  113.     jumpelectron(6,1,poly,getmaxcolor(),-10,0,0,10);
  114.     settextstyle(DEFAULT_FONT,HORIZ_DIR,2);
  115.     outtextxy(80,70,":");
  116.     setcolor(0);
  117.     line(105,85,105,100);
  118.     arrow(160,125,320,180,20,-1,-1);
  119.     arrow(115,65,260,210,32,1,-1);
  120.     setcolor(getmaxcolor());
  121.     delay(2000);
  122.  
  123.     jumpelectron(2,3,poly,0,10,0,10,0);
  124.     jumpelectron(4,5,poly,0,0,-10,-10,0);
  125.     jumpelectron(6,1,poly,0,-10,0,0,10);
  126.     ellipse(100,185,0,360,40,55);
  127.     delay(2000);
  128.  
  129.     free(bmp1);
  130.     free(bmp2);
  131.     getch();
  132.     closegraph();
  133. }
Add Comment
Please, Sign In to add comment