// Simulacion de un Osciloscopio PRACTICA #1

#include<mouse.h>
#include<graphics.h>
#include<conio.h>
#include<math.h>
#include<stdio.h>

presentacion()
{
setfillstyle(9,15);
bar(2,2,628,468);
setcolor(1);
rectangle(1,1,629,469);
rectangle(2,2,628,468);
settextstyle(4,0,4);
setcolor(6);
outtextxy(190,50, "PRACTICA # 2");
outtextxy(160,100,"ELECTRONICA IV B");
outtextxy(180,150,"QUE PRESENTAN:");
outtextxy(50,250,"RODRIGUEZ ESQUER ALEJANDRO");
outtextxy(110,300,"PEREZ MENDOZA SERGIO");
outtextxy(50,350,"ZATARAIN MAZARIEGO KIAVIK");
outtextxy(48,400,"LOPEZ CASTOILLO MIGUEL TADEO");
getch();
return 0;
}

int j,k,l,m,n,o,p,q,mx,my,limite;
unsigned int clic;
float x,x1,y,y1;

void grafica()
{
setfillstyle(7,1);
bar(0,0,629,479);
setfillstyle(7,0);
bar (20,95,422,405);
setcolor(14);
rectangle (19,94,423,406);
rectangle (18,93,424,407);
setcolor(7);
line(20,250,410,250);
line(50,100,50,400);
int a = 100;
char numeros[10];
int cont = 5;
settextstyle(2,0,2);
while(a<=400)
{
setcolor(10);
line(47,a,53,a);
sprintf(numeros,"%d",cont);
outtextxy (35,a-5,numeros);
cont --;
a+=30;
}
int b = 50;
cont = 0;
while(b<=410)
{
line(b,247,b,253);
sprintf(numeros,"%d",cont);
outtextxy (b,255,numeros);
cont++;
b+=30;
}
for (j = 50,k = 10,l = 150,m = 60; j <= 500, l <= 650; j+=150, l+=150)
{setfillstyle(1,7);bar(j,k,l,m);}

for (n = 550, o = 200, p = 600, q = 225; o <= 350, q <= 375; o+=50,q+=50)
{setfillstyle(1,7);bar(n,o,p,q);}
settextstyle(8,0,1);
setcolor(0);
outtextxy(60,15,"seno");
outtextxy(210,15,"coseno");
outtextxy(360,15,"tangente");
outtextxy(510,15,"salir");
outtextxy(570,200,"+");
outtextxy(570,250,"-");
outtextxy(570,300,"+");
outtextxy(570,350,"-");
}

void main()
{
int gd = DETECT, gm;
initgraph (&gd,&gm,"c:/tc/bgi");
presentacion();
cleardevice();
grafica();
mousesetup (graphics);
limite = 12;
float frecuencia = 30;
float voltaje = 30;
if (mx>=550 &my>=200 &mx<=600 &my<=225)
{voltaje += 10;}
if (mx>=550 &my>=250 &mx<=600 &my<=275)
{voltaje -= 10;}
while(1)
{
clic = mouseevent (&mx, &my);
if (clic == 65284)
{
if (mx>=50 &my>=10 &mx<=150 &my<=60)
{
grafica();
for (x = 0.0, x1 = 0.03333; x1 <= limite; x+= 0.03333, x1+=0.03333)
{
y = sin(x );
y1 = sin(x1);
setcolor(4);
line (50+(x*frecuencia), 250-(y*voltaje), 50+(x1*frecuencia), 250-(y1*voltaje));
delay(1);
}
}


if (mx>=200 &my>=10 &mx<=300 &my<=60)
{
grafica();
for (x = 0.0, x1 = 0.03333; x1 <= limite; x+= 0.033333, x1+=0.033333 )
{
y = cos(x );
y1 = cos(x1);
setcolor(4);
line (50+(x*frecuencia), 250-(y*voltaje), 50+(x1*frecuencia), 250-(y1*voltaje));
delay(1);
}
}

if (mx>=350 &my>=10 &mx<=450 &my<=60)
{
grafica();
for (x = 0.0, x1 = 0.03333; x1 <= limite; x+= 0.033333, x1+=0.033333 )
{
y = tan(x );
y1 = tan(x1);
setcolor(4);
line (50+(x*frecuencia), 250-(y*voltaje), 50+(x1*frecuencia), 250-(y1*voltaje));
delay(1);
}
}

if (mx>=500 &my>=10 &mx<=600 &my<=60)break;
}
}
}