Hello
I am having a C programme showing the molecular motion
of the molecules
But it is having flicker in it.
I need u r valuable suggestion to solve my problem..
Thanks for u r time and help.
ur's
sai
#include"stdio.h"
#include"alloc.h"
#include"conio.h"
#include"graphics.h"
#include"string.h"
#include"math.h"
#include"dos.h"
#include"stdlib.h"
#include "mem.h"
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"\\tc\\bgi"
char ql[5][40];
int qll[5]={0,0,0,0,0};
int qlld[5]={0,0,0,0,0};
int del=50;
float initr0=20,initr1=20;
float vbnd=0;
float st=0,ast=0;
char ky;
float initcx0=80,initcy0=100,initcx1=160,initcy1=100;
float initcx2=240,initcy2=100;
float pi=3.14159;
for(int i=0;i<5;i++)
{
strcpy(ql,"Enter a value[0-9]"
}
float cx0=initcx0;
float cx1=initcx1;
float cx2=initcx2;
float sfreq=2.01,afreq=3.52;
qll[1]=1;
void far *buf= NULL;
unsigned long size = imagesize (0,0,15,15);
buf = farmalloc(size);
if ( buf == NULL )
{
closegraph ();
perror ( "Failure" );
exit(1);
}
getimage(0,0,15,15,buf );
// setviewport(0,0,10,10,1);
while(1)
{
// Vertical Bending
vbnd=vbnd+1;
if(vbnd>28)
{
vbnd=vbnd-28;
}
float dvbnd=4*qll[3]*cos(vbnd*pi/14);
// Stretching
st=st+sfreq;
if(st>28)
{
st=st-28;
}
float dxst=2*qll[2]*cos(st*pi/14);
//Horizontal bending
float hbnd=vbnd;
float r0=initr0 + qll[4] * cos(hbnd * pi /14);
float r1=initr1 - qll[4] * cos(hbnd * pi /14);
float r2=r0;
// Assymterical stretching
ast = ast + afreq;
if(ast>28)
{
ast=ast-28;
}
float dast = 0.5 * qll[1] * cos(ast * pi/14);
//Bond attachment points
//Oxygens
float dxpt = r0 * cos(pi/8);
float dypt = r0 * sin(pi/8);
//carbons
float dxptcb = r1 * cos(pi/8);
float dyptcb = r1 * sin(pi/8);
//calculated movements adjusted for masses
float cy0 = initcy0 + 0.375 * dvbnd;
float cy2 = initcy2 + 0.375 * dvbnd;
float cy1 = initcy1 - dvbnd;
cx0 = initcx0 -dxst + dast;
cx2 = initcx2 + dxst + dast;
cx1 = initcx1 - 2.76 * dast;
//red circle left
setcolor(RED);
setfillstyle(1,RED);
moveto(35,25);
circle(cx0,cy0,r0);
floodfill(cx0,cy0,RED);
//blue circle middle
setcolor(BLUE);
setfillstyle(1,BLUE);
circle(cx1,cy1,r1);
floodfill(cx1,cy1,BLUE);
//red circle right
setcolor(RED);
setfillstyle(1,RED);
circle(cx2,cy2,r2);
floodfill(cx2,cy2,RED);
gotoxy(10,21);
printf("A = %d ",qlld[1]);
gotoxy(25,21);
printf("S = %d ",qll[2]);
gotoxy(40,21);
printf("V = %d ",qll[3]);
gotoxy(55,21);
printf("H = %d ",qll[4]);
gotoxy(18,23);
printf("Slower/Faster: < or > Q=Quit"
gotoxy(18,25);
printf("INSTRUCTION: Press A/S/V/H to feed value"
float xpt0 = cx0 + dxpt;
float ypt0 = cy0 - dypt;
float xpt1 = cx1 + dxptcb;
float ypt1 = cy1 - dyptcb;
float xpt2 = cx2 - dxpt;
float ypt2 = cy2 - dypt;
float ypt3 = cy1 + dyptcb;
float ypt4 = cy2 + dypt;
float xpt1L = cx1 - dxptcb;
float ypt5 = cy0 + dypt;
setcolor(5);
//drawing left bonds
line(xpt0,ypt0,xpt1L,ypt1);
line(xpt0,ypt0+2,xpt1L,ypt1+2);
line(xpt0,ypt5,xpt1L,ypt3);
line(xpt0,ypt5+2,xpt1L,ypt3+2);
//drawing right bonds
line(xpt1,ypt1,xpt2,ypt2);
line(xpt1,ypt1+2,xpt2,ypt2+2);
line(xpt1,ypt3,xpt2,ypt4);
line(xpt1,ypt3+2,xpt2,ypt4+2);
/* create a smaller viewport */
if(kbhit())
{
int temp;
int m;
ky=getch();
if(ky=='a'|| ky=='A')
{
gotoxy(20,10);
strcpy(ql[1],"Enter a New Value[0-9]"
m=1;
}
if(ky=='s' || ky=='S')
{
gotoxy(20,12);
strcpy(ql[2],"Enter a New Value[0-9]"
m=2;
}
if(ky=='v' || ky=='V')
{
gotoxy(20,14);
strcpy(ql[3],"Enter a New Value[0-9]"
m=3;
}
if(ky=='h' || ky=='H')
{
gotoxy(20,16);
strcpy(ql[4],"Enter a New Value[0-9]"
m=4;
}
if(ky=='q' || ky=='Q')
{
gotoxy(20,24);
printf("Press Any Key to Exit"
getch();
closegraph();
}
if(ky==46)
{
del=del-10;
}
if(ky==44)
{
del=del+10;
}
if(del<10)
{
gotoxy(10,20);
printf(" Least delay value "
getch();
del=50;
}
if(del>100)
{
gotoxy(10,20);
printf(" Maximum delay value "
getch();
del=50;
}
if(ky>47 && ky<58)
{
if(ky==48)
{
qll[1]=1;
qll[2]=0;
qll[3]=0;
qll[4]=0;
qlld[1]=0;
}
else
{
if(ky==49) qll[m]=1;
if(ky==50) qll[m]=2;
if(ky==51) qll[m]=3;
if(ky==52) qll[m]=4;
if(ky==53) qll[m]=5;
if(ky==54) qll[m]=6;
if(ky==55) qll[m]=7;
if(ky==56) qll[m]=8;
if(ky==57) qll[m]=9;
qlld[1]=qll[1];
}
strcpy(ql[m],""
}
}
/*free memory */
farfree(buf);
delay(del);
//clears graphics screen
// clearviewport();
putimage (0,0,buf,COPY_PUT);
}
}
I am having a C programme showing the molecular motion
of the molecules
But it is having flicker in it.
I need u r valuable suggestion to solve my problem..
Thanks for u r time and help.
ur's
sai
#include"stdio.h"
#include"alloc.h"
#include"conio.h"
#include"graphics.h"
#include"string.h"
#include"math.h"
#include"dos.h"
#include"stdlib.h"
#include "mem.h"
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"\\tc\\bgi"
char ql[5][40];
int qll[5]={0,0,0,0,0};
int qlld[5]={0,0,0,0,0};
int del=50;
float initr0=20,initr1=20;
float vbnd=0;
float st=0,ast=0;
char ky;
float initcx0=80,initcy0=100,initcx1=160,initcy1=100;
float initcx2=240,initcy2=100;
float pi=3.14159;
for(int i=0;i<5;i++)
{
strcpy(ql,"Enter a value[0-9]"
}
float cx0=initcx0;
float cx1=initcx1;
float cx2=initcx2;
float sfreq=2.01,afreq=3.52;
qll[1]=1;
void far *buf= NULL;
unsigned long size = imagesize (0,0,15,15);
buf = farmalloc(size);
if ( buf == NULL )
{
closegraph ();
perror ( "Failure" );
exit(1);
}
getimage(0,0,15,15,buf );
// setviewport(0,0,10,10,1);
while(1)
{
// Vertical Bending
vbnd=vbnd+1;
if(vbnd>28)
{
vbnd=vbnd-28;
}
float dvbnd=4*qll[3]*cos(vbnd*pi/14);
// Stretching
st=st+sfreq;
if(st>28)
{
st=st-28;
}
float dxst=2*qll[2]*cos(st*pi/14);
//Horizontal bending
float hbnd=vbnd;
float r0=initr0 + qll[4] * cos(hbnd * pi /14);
float r1=initr1 - qll[4] * cos(hbnd * pi /14);
float r2=r0;
// Assymterical stretching
ast = ast + afreq;
if(ast>28)
{
ast=ast-28;
}
float dast = 0.5 * qll[1] * cos(ast * pi/14);
//Bond attachment points
//Oxygens
float dxpt = r0 * cos(pi/8);
float dypt = r0 * sin(pi/8);
//carbons
float dxptcb = r1 * cos(pi/8);
float dyptcb = r1 * sin(pi/8);
//calculated movements adjusted for masses
float cy0 = initcy0 + 0.375 * dvbnd;
float cy2 = initcy2 + 0.375 * dvbnd;
float cy1 = initcy1 - dvbnd;
cx0 = initcx0 -dxst + dast;
cx2 = initcx2 + dxst + dast;
cx1 = initcx1 - 2.76 * dast;
//red circle left
setcolor(RED);
setfillstyle(1,RED);
moveto(35,25);
circle(cx0,cy0,r0);
floodfill(cx0,cy0,RED);
//blue circle middle
setcolor(BLUE);
setfillstyle(1,BLUE);
circle(cx1,cy1,r1);
floodfill(cx1,cy1,BLUE);
//red circle right
setcolor(RED);
setfillstyle(1,RED);
circle(cx2,cy2,r2);
floodfill(cx2,cy2,RED);
gotoxy(10,21);
printf("A = %d ",qlld[1]);
gotoxy(25,21);
printf("S = %d ",qll[2]);
gotoxy(40,21);
printf("V = %d ",qll[3]);
gotoxy(55,21);
printf("H = %d ",qll[4]);
gotoxy(18,23);
printf("Slower/Faster: < or > Q=Quit"
gotoxy(18,25);
printf("INSTRUCTION: Press A/S/V/H to feed value"
float xpt0 = cx0 + dxpt;
float ypt0 = cy0 - dypt;
float xpt1 = cx1 + dxptcb;
float ypt1 = cy1 - dyptcb;
float xpt2 = cx2 - dxpt;
float ypt2 = cy2 - dypt;
float ypt3 = cy1 + dyptcb;
float ypt4 = cy2 + dypt;
float xpt1L = cx1 - dxptcb;
float ypt5 = cy0 + dypt;
setcolor(5);
//drawing left bonds
line(xpt0,ypt0,xpt1L,ypt1);
line(xpt0,ypt0+2,xpt1L,ypt1+2);
line(xpt0,ypt5,xpt1L,ypt3);
line(xpt0,ypt5+2,xpt1L,ypt3+2);
//drawing right bonds
line(xpt1,ypt1,xpt2,ypt2);
line(xpt1,ypt1+2,xpt2,ypt2+2);
line(xpt1,ypt3,xpt2,ypt4);
line(xpt1,ypt3+2,xpt2,ypt4+2);
/* create a smaller viewport */
if(kbhit())
{
int temp;
int m;
ky=getch();
if(ky=='a'|| ky=='A')
{
gotoxy(20,10);
strcpy(ql[1],"Enter a New Value[0-9]"
m=1;
}
if(ky=='s' || ky=='S')
{
gotoxy(20,12);
strcpy(ql[2],"Enter a New Value[0-9]"
m=2;
}
if(ky=='v' || ky=='V')
{
gotoxy(20,14);
strcpy(ql[3],"Enter a New Value[0-9]"
m=3;
}
if(ky=='h' || ky=='H')
{
gotoxy(20,16);
strcpy(ql[4],"Enter a New Value[0-9]"
m=4;
}
if(ky=='q' || ky=='Q')
{
gotoxy(20,24);
printf("Press Any Key to Exit"
getch();
closegraph();
}
if(ky==46)
{
del=del-10;
}
if(ky==44)
{
del=del+10;
}
if(del<10)
{
gotoxy(10,20);
printf(" Least delay value "
getch();
del=50;
}
if(del>100)
{
gotoxy(10,20);
printf(" Maximum delay value "
getch();
del=50;
}
if(ky>47 && ky<58)
{
if(ky==48)
{
qll[1]=1;
qll[2]=0;
qll[3]=0;
qll[4]=0;
qlld[1]=0;
}
else
{
if(ky==49) qll[m]=1;
if(ky==50) qll[m]=2;
if(ky==51) qll[m]=3;
if(ky==52) qll[m]=4;
if(ky==53) qll[m]=5;
if(ky==54) qll[m]=6;
if(ky==55) qll[m]=7;
if(ky==56) qll[m]=8;
if(ky==57) qll[m]=9;
qlld[1]=qll[1];
}
strcpy(ql[m],""
}
}
/*free memory */
farfree(buf);
delay(del);
//clears graphics screen
// clearviewport();
putimage (0,0,buf,COPY_PUT);
}
}