FREC/FREC.CPP
2021-09-08 21:11:45 +02:00

342 lines
9.6 KiB
C++
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <math.h> // Para getch();
#include <dos.h> // Para getch();
#include <stdio.h> // Para getch();
#include <conio.h> // Para getch();
#include <graphics.h> // Para outtextxy(...); y cleardevice(...);
#include "..\libs\make_bot\make_bot.h" // Fuciones de MAKE_BOTON
#define LINEFREC 2
#define MatrizPoint 56
#define BackGRID 0
/*
#define GRID_Y 6
#define GRID_X 6
*/
#define GRID_Y 4
#define GRID_X 4
#define PriGRID_Y 247
#define PriGRID_X 11
typedef struct
{
int x, y;
char ndigitos;
char AX, AY;
char C1, C2, C3;
} p_graphics;
extern void Carga_Puntero(void);
extern int Numero_Digital( long numero, p_graphics *ND );
extern void Fuente_Amplia( char *Frase, p_graphics *FA );
int Espera_TeclaRatonFrec(void);
//((( x_raton - ( PriGRID_X - 1 ) )/GRID_X)+1), ( y_raton - ( PriGRID_Y - 8 ) )/GRID_Y )
int PerfilX[4096];
int oldPerfilX, oldPerfilY;
void TrazaPerfiles(void);
void TrazaGrafica(void);
char cruz = 1;
int main(void){
p_graphics Numeros = { 20, 20, 6, 3, 3, EGA_RED, EGA_BLACK, EGA_DARKGRAY };
p_graphics Letras = { 15, 102, 14, 1, 1, EGA_BLACK, EGA_RED, EGA_DARKGRAY };
char Buffer[80];
int numero=0;
float num = 0;
for ( numero=0; numero < 640; numero++ )
{
num += 0.5;
PerfilX[ numero ] = 15 + 10*sin( num );
}
Initialize( 9, 2 ); // Inicializa el Modo Gr fico
// carga_botones("Frec.img"); // Carga botones del fichero "Frec.img"
Imprime_Estaticos( 1, "Frec.img"); // Imprime botones estaticos 'Seccion 1'
/// Dibujamos la malla
TrazaGrafica();
PunteroRaton = 1;
inicializa_raton_grafico( 0, 0, 640, 480 );
float vez=1, numerof=0;
while( 1 )
{
Espera_TeclaRatonFrec();
if ( cruz == 0 ) Anclar_Raton();
// if ( y_raton >= (PriGRID_Y - 8) ) numero = 10101;
Numero_Digital( numerof, &Numeros );
/*********************************************************************************************************\
|***/ oldPerfilX = PerfilX[ ((( x_raton - ( PriGRID_X - 1 ) )/GRID_X)+1) ]; /*|
|**/ oldPerfilY = ((( x_raton - ( PriGRID_X - 1 ) )/GRID_X)+1); /**|
|*/ PerfilX[ ((( x_raton - ( PriGRID_X - 1 ) )/GRID_X)+1) ] = ( y_raton - ( PriGRID_Y - 8 ) )/GRID_Y; /***|
\*********************************************************************************************************/
TrazaPerfiles();
switch ((int)(vez))
{
case 1:
sprintf( Buffer, "X: %2d, Y: %2d |", ((( x_raton - ( PriGRID_X - 1 ) )/GRID_X)+1), ( y_raton - ( PriGRID_Y - 8 ) )/GRID_Y );
break;
case 2:
sprintf( Buffer, "X: %2d, Y: %2d |", ((( x_raton - ( PriGRID_X - 1 ) )/GRID_X)+1), ( y_raton - ( PriGRID_Y - 8 ) )/GRID_Y );
break;
case 3:
sprintf( Buffer, "X: %2d, Y: %2d |", ((( x_raton - ( PriGRID_X - 1 ) )/GRID_X)+1), ( y_raton - ( PriGRID_Y - 8 ) )/GRID_Y );
break;
case 4:
sprintf( Buffer, "X: %2d, Y: %2d |", ((( x_raton - ( PriGRID_X - 1 ) )/GRID_X)+1), ( y_raton - ( PriGRID_Y - 8 ) )/GRID_Y );
vez = 1;
break;
}
if ( (int(vez*100))%100 == 0 )
Fuente_Amplia( Buffer, &Letras );
vez+=1;
if( kbhit() )
{
switch( getch() )
{
case '+':
numerof += 0.05;
break;
case '-':
numerof -= 0.05;
break;
case 27:
restorecrtmode();
return 0;
break;
}
num = 0;
for ( numero=0; numero < 640; numero++ )
{
num += numerof;
PerfilX[ numero ] = 15 + 10*sin( num );
}
TrazaGrafica();
}
}
// Imprime_Secuencia(1); // Imprime secuencia 1.
/*
while(1){ // Bucle infinito
switch( Comprueba_Secuencia( 1 ) ) { // Iniciamos comprobacion
case 0: // No se pulso ningun BOTON
while( kbhit() ) getch(); // Limpiamos posibles teclas en BUFFER
break;
case -1: // Hay una tecla especial en BUFFER
getch(); // La eliminamos
break;
case 1:
Ayuda();
cleardevice();
Imprime_Estaticos( 1, "botones.p1"); // Devolvemos el aspecto inicial
Imprime_Secuencia(1);
break;
case 2:
restorecrtmode();
return 0;
default:
break;
}
}
*/
getch();
restorecrtmode();
return 0;
}
int Espera_TeclaRatonFrec(void){
char Que;
int bot_izq, bot_der;
activa_raton();
//char cruz = 1;
do{
asm mov AX, 3
asm int 0x33
asm mov x_raton, cx
asm mov y_raton, dx
asm mov bot_izq, bx
asm mov bot_der, bx
bot_izq = bot_izq & 1;
bot_der = (bot_izq >> 1 ) & 1;
if ( y_raton >= (PriGRID_Y - 8) )
{
if ( !cruz ) {
cruz = 1;
PunteroRaton = 2;
Carga_Puntero();
if ( ( (x_raton - (PriGRID_X-1) )%GRID_X ) >= GRID_X/2 && ( ( (x_raton - PriGRID_X)%GRID_X ) != 0 ) )
x_raton += (GRID_X - ( (x_raton - (PriGRID_X-1))%GRID_X ) );
else
x_raton -= ( ( (x_raton - (PriGRID_X-1))%GRID_X ) );
y_raton = PriGRID_Y - 8;
} else {
if ( x_raton > 622 )
x_raton = 622; else
if ( ( (x_raton - (PriGRID_X-1) )%GRID_X ) >= GRID_X/2 && ( ( (x_raton - PriGRID_X)%GRID_X ) != 0 ) )
x_raton += (GRID_X - ( (x_raton - (PriGRID_X-1))%GRID_X ) );
else
x_raton -= ( ( (x_raton - (PriGRID_X-1))%GRID_X ) );
if ( y_raton > 459 )
y_raton = 459; else
if ( ( (y_raton - ( PriGRID_Y - 8 ) )%GRID_Y ) >= GRID_Y/2 && ( ( (y_raton - ( PriGRID_Y - 8 ) )%GRID_Y ) != 0 ) )
y_raton += (GRID_Y - ( (y_raton - ( PriGRID_Y - 8 ) )%GRID_Y ) );
else
y_raton -= ( ( (y_raton - ( PriGRID_Y - 8 ) )%GRID_Y ) );
}
asm mov ax, 4
asm mov cx, x_raton
asm mov dx, y_raton
asm int 0x33
} else
if ( cruz ) {
cruz = 0;
PunteroRaton = 1;
Carga_Puntero();
}
}while( bot_izq == 0 && bot_izq == 0 && !MB_TeclaPulsada() );
/////////////////////////////////////////
// RETURN Derecho Izquierdo //
// //
// 0 0 0 //
// 1 1 0 //
// 2 0 1 //
// 3 1 1 //
// //
/////////////////////////////////////////
if ( bot_der ==0 && bot_izq ==0 ) Que = 0;
if ( bot_der ==1 && bot_izq ==0 ) Que = 1;
if ( bot_der ==0 && bot_izq ==1 ) Que = 2;
if ( bot_der ==1 && bot_izq ==1 ) Que = 3;
desactiva_raton();
return Que;
}
void TrazaPerfiles(void)
{
int X = x_raton+6;//((( x_raton - ( PriGRID_X - 1 ) )/GRID_X)+1)*GRID_X + PriGRID_X;
int Y = y_raton+8;
int Desde_Y, Hasta_Y;
if ( y_raton < (PriGRID_Y - 8) ) return;
// Calculo desde donde, hasta donde tengo que borrar para hacelerar el borrado.
// ( esta nueva optimizaci¢n acelera el tiempo de retardo:
// en el mejor caso: un 98.4 %
// en el peor caso: un 0.0 %
// tiempo medio acelerado ( teu: un 6i.j %
Desde_Y = Hasta_Y = oldPerfilX;
if ( Hasta_Y < PerfilX[((( x_raton - ( PriGRID_X - 1 ) )/GRID_X)+1)+1] ) Hasta_Y = PerfilX[((( x_raton - ( PriGRID_X - 1 ) )/GRID_X)+1)+1]*GRID_Y+PriGRID_Y; else
if ( Hasta_Y < PerfilX[((( x_raton - ( PriGRID_X - 1 ) )/GRID_X)+1)-1] ) Hasta_Y = PerfilX[((( x_raton - ( PriGRID_X - 1 ) )/GRID_X)+1)-1]*GRID_Y+PriGRID_Y; else
// if ( Hasta_Y = PerfilX[((( x_raton - ( PriGRID_X - 1 ) )/GRID_X)+1)-1] )
Hasta_Y = Hasta_Y*GRID_Y+PriGRID_Y;
if ( Desde_Y > PerfilX[((( x_raton - ( PriGRID_X - 1 ) )/GRID_X)+1)+1] ) Desde_Y = PerfilX[((( x_raton - ( PriGRID_X - 1 ) )/GRID_X)+1)+1]*GRID_Y+PriGRID_Y; else
if ( Desde_Y > PerfilX[((( x_raton - ( PriGRID_X - 1 ) )/GRID_X)+1)-1] ) Desde_Y = PerfilX[((( x_raton - ( PriGRID_X - 1 ) )/GRID_X)+1)-1]*GRID_Y+PriGRID_Y; else
Desde_Y = Desde_Y*GRID_Y+PriGRID_Y;
setcolor( BackGRID );
// Borro las franjas adyacentes al punto perfilado:
if ( (((( x_raton - ( PriGRID_X - 1 ) )/GRID_X)+1)-1) >=0 ) line( X - ( GRID_X - 1 ), PerfilX[((( x_raton - ( PriGRID_X - 1 ) )/GRID_X)+1)-1]*GRID_Y+PriGRID_Y, (X+1), oldPerfilX*GRID_Y+PriGRID_Y );
line( (X+1), oldPerfilX*GRID_Y+PriGRID_Y, X + ( GRID_X + 1 ), PerfilX[((( x_raton - ( PriGRID_X - 1 ) )/GRID_X)+1)+1]*GRID_Y+PriGRID_Y );
// putpixel( X - ( GRID_X - 1 ), PerfilX[((( x_raton - ( PriGRID_X - 1 ) )/GRID_X)+1)-1]*GRID_Y+PriGRID_Y, MatrizPoint );
// putpixel( (X+1), oldPerfilX*GRID_Y+PriGRID_Y, MatrizPoint );
// putpixel( X + ( GRID_X + 1 ), PerfilX[((( x_raton - ( PriGRID_X - 1 ) )/GRID_X)+1)+1]*GRID_Y+PriGRID_Y, MatrizPoint );
// Retrazo los puntos de la matriz anulada
{
auto int x, y;
for( x= ( (((( x_raton - ( PriGRID_X - 1 ) )/GRID_X)+1)-1) >=0 ) ?
X - ( GRID_X - 1 ):
( X - 1 );
x<= (x_raton > 622) ? ( X + 1 ) :
( X + ( GRID_X + 1 ) ); x+=GRID_X)
// /*
for( y=Desde_Y; y<=Hasta_Y; y+=GRID_Y)
putpixel( x, y, MatrizPoint );
} // Destruccion de x, y
// Ahora dibujo las lineas correspondientes al perfil izq. y derch.
setcolor( LINEFREC );
if ( (((( x_raton - ( PriGRID_X - 1 ) )/GRID_X)+1)-1) >=0 ) line( X - ( GRID_X - 1 ), PerfilX[((( x_raton - ( PriGRID_X - 1 ) )/GRID_X)+1)-1]*GRID_Y+PriGRID_Y, (X+1), Y );
if ( x_raton <= 622 ) line( (X+1), Y, X + ( GRID_X + 1 ), PerfilX[((( x_raton - ( PriGRID_X - 1 ) )/GRID_X)+1)+1]*GRID_Y+PriGRID_Y );
}
void TrazaGrafica(void)
{
int x, y;
setfillstyle( SOLID_FILL, BackGRID );
bar( PriGRID_X, PriGRID_Y, 631, 467 );
/*
for( x=PriGRID_X; x<=631; x+=GRID_X)
for( y=PriGRID_Y; y<=467; y+=GRID_Y)
putpixel( x, y, MatrizPoint );
*/
//for( x=6 - ( GRID_X - 1 ); x<=631; x+=GRID_X)
for( x= ( 6 - ( 1 - PriGRID_X )%GRID_X - ( GRID_X - 1 ) ) + GRID_X; x<=631; x+=GRID_X)
for( y=PriGRID_Y; y<=467; y+=GRID_Y)
putpixel( x, y, MatrizPoint );
setcolor( LINEFREC );
for( x= ( 6 - ( 1 - PriGRID_X )%GRID_X - ( GRID_X - 1 ) ) + GRID_X; x<=631; x+=GRID_X)
if ( (x-PriGRID_X)/GRID_X >= 0 )
line( x, PerfilX[ (x-PriGRID_X)/GRID_X ]*GRID_Y+PriGRID_Y, x+GRID_X, PerfilX[ ( (x-PriGRID_X)/GRID_X ) + 1 ]*GRID_Y+PriGRID_Y);
}