Animation showing dispersion of light in C++.

#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>

void main()
{
int gd=DETECT,gm,i=0;
int x1=10,y1=140,x2=70,y2=140;
initgraph(&gd,&gm,”C:\\TC\\BGI”);
setbkcolor(7);
settextstyle(0,0,2);
for (int angle=0;i<200;angle++,i++)
{
setcolor(14);
ellipse(320,240,angle,angle+20,300,150);
ellipse(320,240,angle+180,angle+200,300,150);
outtextxy(140,200,”****** CG Project ******”);
outtextxy(140,250,” * Press any Key * “);
delay(9);
setcolor(8);
ellipse(320,240,angle-1,angle+19,300,150);
ellipse(320,240,angle-1+180,angle+199,300,150);
}

getch();
cleardevice();

setcolor(15);
settextstyle(0,0,0);
line(30,140,200,140);
rectangle(200,100,220,260);

outtextxy(250,100,”Splitting of Light”);
outtextxy(330,120,”into 7 different rays”);
outtextxy(190,50,”Prism”);
outtextxy(60,90,”Ray of Light”);
setcolor(1);
line(220,145,300,165); // V
setcolor(9);
line(220,155,300,175); // I
setcolor(8);
line(220,165,300,185); // B
setcolor(2);
line(220,175,300,195); // g
setcolor(14);
line(220,185,300,205); // Y
setcolor(12);
line(220,195,300,215); // O
setcolor(4);
line(220,205,300,225); // R
setcolor(15);

settextstyle(0,0,2);
outtextxy(10,300,”Ray of Light is made incident on Prism “);
outtextxy(10,330,”Due to Refraction,”);
outtextxy(20,350,”ray of light gets splitted.”);
outtextxy(20,420,” Press any key …..”);
settextstyle(0,0,0);
getch();
cleardevice();
settextstyle(0,0,0);
rectangle(200,100,220,260);

for(int j=0;j<3;j++)
{
for(i=0;i<=150;i++)
{

outtextxy(250,100,”Splitting of Light”);
outtextxy(330,120,”into 7 different rays”);
outtextxy(190,50,”Prism”);
rectangle(200,100,220,260);
outtextxy(60,90,”Ray of Light”);
// line(30,140,200,140);
delay(30);
line(x1+i,y1,x2+i,y2);
delay(10);
cleardevice();
if((x2+i)==220)
{
outtextxy(250,100,”Splitting of Light”);
outtextxy(330,120,”into 7 different rays”);
outtextxy(190,50,”Prism”);
rectangle(200,100,220,260);
outtextxy(60,90,”Ray of Light”);

setcolor(1);
line(220,145,300,165); // v
setcolor(9);
line(220,155,300,175); // I
setcolor(8);
line(220,165,300,185); // B
setcolor(2);
line(220,175,300,195); // g
setcolor(14);
line(220,185,300,205); // Y
setcolor(12);
line(220,195,300,215); // O */
setcolor(15);
line(220,205,300,225); // R

rectangle(200,100,220,260);
outtextxy(250,100,”Splitting of Light”);
outtextxy(330,120,”into 7 different rays”);
outtextxy(190,50,”Prism”);
outtextxy(60,90,”Ray of Light”);
// getch(); */
delay(500);
// cleardevice();
}
}

}
line(30,140,200,140);
rectangle(200,100,220,260);

outtextxy(250,100,”Splitting of Light”);
outtextxy(330,120,”into 7 different rays”);
outtextxy(190,50,”Prism”);
outtextxy(60,90,”Ray of Light”);
setcolor(1);
line(220,145,300,165); // V
setcolor(9);
line(220,155,300,175); // I
setcolor(8);
line(220,165,300,185); // B
setcolor(2);
line(220,175,300,195); // g
setcolor(14);
line(220,185,300,205); // Y
setcolor(12);
line(220,195,300,215); // O
setcolor(4);
line(220,205,300,225); // R
setcolor(15);

getch();
closegraph();
}

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

©2023 MYBSCIT.com. An initiative by some failures to make student scholars.

or

Log in with your credentials

Forgot your details?