// Programa con un contador binario en modo grafico y el Ojo de kit

#include<graphics.h>
#include<dos.h>
#include<stdio.h>
#include<conio.h>
#include<bios.h>
#include<math.h>

void menu(int op)
{
settextstyle(2,0,4);
if (op==0){setfillstyle(1,1);setcolor(15);}
else{setfillstyle(1,3);setcolor(10);}

if (op==0|op==1){bar(250,175,360,199);
outtextxy(260,185,"CONTADOR BINARIO");}

if (op==0|op==2){bar(250,200,360,225);
outtextxy(260,210,"OJO DE KIT");}

if (op==0|op==3){bar(250,225,360,249);
outtextxy(260,235,"ERROR FATAL");}

if (op==0|op==4){bar(250,250,360,274);
outtextxy(260,260,"FREE SEX");}

if (op==0|op==5){bar(250,275,360,299);
outtextxy(260,285,"SALIR");}
}


void contador()
{
char msg[5];
int b[9];
char residuo;
unsigned char numero;
int a,v,c,d;
cleardevice();
for (unsigned char cont=1;!kbhit();cont++)
{
cleardevice();
setcolor(1);
rectangle(0,0,629,469);
rectangle(1,1,628,468);
setcolor(6);
rectangle(90,130,530,370);
setcolor(15);
for (a=130,v=300,c=20,d=20;a<=480;a+=50)
{
setfillstyle(0,1);
fillellipse(a,v,c,d);
}
setcolor(11);
settextstyle(7,0,4);
sprintf(msg,"%d",cont);
outtextxy(280,150,msg);
b[1] = cont%2;
b[2] = cont%4;
if (b[2]==1 ) b[2]=0; if (b[2]==2|b[2]==3) b[2]=1;
b[3] = cont%8;
if (b[3]>=1&b[3]<4 ) b[3]=0; if (b[3]>=4&b[3]<8) b[3]=1;
b[4] = cont%16;
if (b[4]>=1&b[4]<8 ) b[4]=0; if (b[4]>=8&b[4]<16) b[4]=1;
b[5] = cont%32;
if (b[5]>=1 &b[5]<16 ) b[5]=0; if (b[5]>=16&b[5]<32) b[5]=1;
b[6] = cont%64;
if (b[6]>=1 &b[6]<32 ) b[6]=0; if (b[6]>=32&b[6]<64) b[6]=1;
b[7] = cont%128;
if (b[7]>=1&b[7]<64 ) b[7]=0; if (b[7]>=64&b[7]<128) b[7]=1;
b[8] = cont%256;
if (b[8]>=1&b[8]<128 ) b[8]=0; if (b[8]>=128&b[8]<256) b[8]=1;
for (int i=130,j=8;i<=480,j>=1;i+=50,j--)
{
setcolor(14);
settextstyle(9,0,1);
sprintf(msg,"%d",b[j]);
outtextxy(i,200,msg);
}
setcolor(15);
for(int z=130,y=8;z<=480,y>=1;z+=50,y--)
{
if (b[y] == 1){setfillstyle(1,4);fillellipse(z,300,20,20);}
}
delay(200);
if (cont == 255)break;
}
getch();
}

void ojo()
{
cleardevice();
char msg[80];
int b[15];
int a,v,c,d;
for (unsigned char cont=0;!kbhit();cont++)
{
if (cont==15)cont=1;
cleardevice();
for (int e=1;e<=14;e++)
{if (cont==e) b[e]=1; else b[e]=0;}
for (a=130,v=300,c=20,d=20;a<=480;a+=50)
{
setfillstyle(0,1);
fillellipse(a,v,c,d);
}
for (int p=1,m=130;p<=8,m<=480;p++,m+=50)
{if (b[p]==1){setfillstyle(1,4);fillellipse(m,300,20,20);}}
for (int q=9,n=430;q<=14,n>=180;q++,n-=50)
{if (b[q]==1){setfillstyle(1,4);fillellipse(n,300,20,20);}}
delay(50);
}getch();
}

presentacion()
{
setfillstyle(9,YELLOW);
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 # 1");
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(185,400,"MIGUEL TADEO");
getch();
return 0;
}


int mx,my;
int z,op=1;
unsigned int clic;

void main()
{
int gd = DETECT, gm;
initgraph (&gd,&gm,"c:/tc/bgi");
presentacion();
do
{
cleardevice();
setfillstyle(1,7);
bar(2,2,628,468);
setcolor(1);
rectangle(1,1,629,469);
rectangle(2,2,628,468);
setcolor(14);
rectangle(249,174,361,300);
menu(0); menu(op);
z=bioskey(0);
if(z==18432)op--;
if(z==20480)op++;
if(op==0) op=5;
if(op==6) op=1;
if(z==18432|z==20480)
{menu(0); menu(op);}
if(z==7181)
{
if (op==1){contador();}
if (op==2){ojo();}
if (op==3){while(1)
{outtextxy(180,150,"ERROR trata de usar otro pinchi boton wey");outtextxy(180,160,"ERROR 192997_MAL FUNCION ya valio te la chingaste --- Presiona Ctrl + Pausa para salir");}}
if (op==4){contador();ojo();outtextxy(180,150,"QUE? te gusto!?");getch();}
if (op==5)break;
}
}while(1);
}