Simulation d'ecran boursier turboc++ mode graphique

Description

generation de chiffres dans un tableau avec des graphiques

Source / Exemple :


/*  PROGRAMME EN C SOUS DOS TURBO C++2 BORLAND
	ecrit le 01-02-2003 par cmarsc
	ECRAN DE COTATIONS BOURSIERES : MODE GRAPHIQUE */

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <time.h>
#include <dos.h>

#define NBRE_LIGNES_MAXI 15
#define NBRE_COLONNES_MAXI 30

#define COUL_ECRAN         LIGHTBLUE
#define COUL_CHIFFRES      LIGHTGREEN
#define COUL_CHIFFRES_FOND LIGHTBLUE
#define COUL_CURSEUR       BLUE
#define COUL_TEXTES_FOND   RED
#define COUL_BARRE         CYAN
#define COUL_COURBE        LIGHTRED

void bouton_3D(int x1, int y1, int x2, int y2, int coul,int relief,int clic);
void box(int x1, int y1, int x2, int y2, int coul_box,int coul_fond,int effet);
void generer_afficher_chiffres(void);

enum etats_boutons { NON_CLIQUE, CLIQUE };
enum effets_cadre { PAS_D_OMBRE, OMBRE };

int main(void)
{
	 int i1,milieu_y;

	 // teste pour passer en mode graphique
	 int gdriver = DETECT, gmode, errorcode;
	 initgraph(&gdriver, &gmode, "c:\\tc\\bgi");

 	errorcode = graphresult();
	if (errorcode != grOk)
	{
		printf("Graphics error: %s\n", grapherrormsg(errorcode));
		printf("Press any key to halt:");
		getch();

	  exit(1);
	}
 
   sleep(1);

  settextstyle(SANS_SERIF_FONT, HORIZ_DIR, 4);

  milieu_y = getmaxy()/2;

  // afficher le fond d'ecran
	setcolor(COUL_ECRAN);
for (i1 = 0; i1 <= milieu_y; i1++) {
	rectangle (1, (milieu_y-3)-i1, getmaxx() ,(milieu_y-3) + i1);
	delay(1);
}

	// cadre principal
// x1 = 1 y1 = 1  x2 = 639  y2 = 480 coul = LIGHTBLUE  relief = 4 clic = 0
	 bouton_3D(1,1,getmaxx(),getmaxy(),COUL_ECRAN,4,NON_CLIQUE);

	 generer_afficher_chiffres();

  // effacer l'ecran

  milieu_y = getmaxy() / 2;
  setcolor(BLACK);

  for (i1 = 0; i1 <= milieu_y; i1++) {
	  rectangle (0+i1,i1,getmaxx()-i1,getmaxy()-i1);
	 delay(2);
   }
	 delay(500);

	// fermer le mode graphique
	 closegraph();
return EXIT_SUCCESS;
} // fin de main

void bouton_3D(int x1, int y1, int x2, int y2, int coul,int relief,int clic){
	int i1;

	// dessiner le bouton avec un relief
	for (i1 = 0; i1 < relief; i1++) {

	   setcolor(WHITE);
	   // trait blanc haut
	   line (x1 + i1, y1 + i1, x2 - i1, y1 + i1);
	   // trait blanc gauche
	   line (x1 + i1, y1 + i1, x1 + i1, y2 - i1);

	   setcolor(DARKGRAY);
	   // trait gris bas
	   line (x1 + i1, y2 - i1, x2 - i1, y2 - i1);
	   // trait gris droit
	   line (x2 - i1, y1 + i1, x2 - i1, y2 - i1);

	}

	// simuler le clique
	if (clic == CLIQUE) {
	  setcolor(BLACK);
	  for (i1 = 1; i1 < 3; i1++) {
		  rectangle (x1 + i1, y1 + i1, x2 - i1, y2 - i1);
	  }

	  setcolor(WHITE);
	  // cadre blanc exterieur
	  rectangle (x1 , y1 , x2 , y2 );
	} else {
	   // dessiner le fond du bouton en couleur
	   setfillstyle(SOLID_FILL,coul);
	   bar (x1 +i1 , y1 +i1, x2-i1 , y2-i1 );
	}

return ;
} // fin de la fonction bouton_3D

void box(int x1, int y1, int x2, int y2, int coul_box,int coul_fond,int effet){

	// dessiner l'ombre avec un decalage de 5
	if (effet == OMBRE) {
	   setfillstyle(SOLID_FILL,BLACK);
	   bar (x1 + 5 , y1 + 5 , x2 + 5 , y2 + 5 );
	}

	setfillstyle(SOLID_FILL,coul_fond);
	bar (x1 , y1 , x2 , y2 );

	setcolor(coul_box);
	rectangle (x1 , y1 , x2 , y2 );
return ;
} // fin de la fonction box

void generer_afficher_chiffres(void) {

   int i1 = 0, i2;
   int chiffre,ligne_en_surbrillance;
   char texte1[NBRE_COLONNES_MAXI+1];
   static char texte_du_titre[50];

   static char *noms_des_teles[15] = {
	  "TF1", "CBS","CANAL+","NET TV","ZDF","ARTE","M6","TV 5",
	  "ABC","BBC","SKY","RTBF 1","CNN","FUN TV", "NHK TV"
   };

   time_t heure;
   int graphique[3][NBRE_COLONNES_MAXI] = { NULL };

   // initialiser le generateur de nombres pseudos-alatoires
   srand( (unsigned) time(NULL) );

// x1 =10 y1 = 42 x2 = 76 y2 = 346  coul_cadre = jaune coul_fond = bleu
	// effet avec une ombre
   // cadre gauche avec les noms des teles
	box(10, 42, 76, 346, YELLOW, BLUE, OMBRE);

	// cadre avec les chiffres
// x1 =77 y1 = 42 x2 =337 y2 = 346  coul_cadre = jaune coul_fond = noir
	box(77, 42, 337, 346, YELLOW, BLACK, OMBRE);

   // cadre a droite avec l'histogramme
// x1 =345 y1 = 42 x2 =630 y2 = 346  coul_cadre = vert  coul_fond = noir
   box(345, 42, 630, 346, LIGHTGREEN, BLACK, PAS_D_OMBRE);

   // cadre en bas a gauche : graphique en courbe
// x1 =10 y1 =360 x2 =337 y2 =465  coul_cadre = blanc coul_fond = noir
   box(10, 360, 337, 465, WHITE,BLACK, PAS_D_OMBRE);

   // cadre en bas a droite : graphique barre horizontale
// x1 =345 y1 =360 x2 =630 y2 =465  coul_cadre = blanc coul_fond = noir
   box(345, 360, 630, 465, YELLOW,BLACK, PAS_D_OMBRE);

   settextstyle(TRIPLEX_FONT, HORIZ_DIR, 4);
   setcolor(LIGHTCYAN);
   outtextxy(360,5, "Bourse de PARIS");
   setcolor(BLACK);
   outtextxy(360,6, "Bourse de PARIS");

   // police de caractere
   settextstyle(SMALL_FONT, HORIZ_DIR, 5);

   while (!kbhit()) { // kbhit 1

	 while (!kbhit()) { // kbhit 2

	 if (i1 >= NBRE_LIGNES_MAXI) i1 = 0;

		// choisir la ligne a mettre en evidence
		ligne_en_surbrillance = (rand() % NBRE_LIGNES_MAXI);

		// afficher la date et l'heure
		time(&heure);
		box(10,10, 337,35,WHITE,MAGENTA,PAS_D_OMBRE);

		sprintf(texte_du_titre,"Cotations du %s",ctime(&heure) );
		outtextxy(15,15, texte_du_titre);

	if (i1 == ligne_en_surbrillance)
		setfillstyle(SOLID_FILL,COUL_CURSEUR);
	else
	   setfillstyle(SOLID_FILL,COUL_TEXTES_FOND);

	  // afficher les noms des teles
	  bar(11, 45+(i1*20), 75, 63+(i1*20));
	  outtextxy(20,45 + (i1*20), noms_des_teles[i1]);

	  for (i2 = 0; i2 < NBRE_COLONNES_MAXI; i2++) {

		   if (i2 < 8) { // tableau avec les chiffres

			   chiffre = (rand() %100)+1 ;

	if (i1 == ligne_en_surbrillance)
		setfillstyle(SOLID_FILL,COUL_CURSEUR);
	else
	   setfillstyle(SOLID_FILL,COUL_CHIFFRES_FOND);

			   bar(80+(i2*32),45 + (i1*20),110+(i2*32),63 + (i1*20));
			   sprintf(texte1,"%4d",chiffre);
			   setcolor(COUL_CHIFFRES);
			   outtextxy(75 + (i2*32),45 + (i1*20), texte1 );

		   } // if (i2 < 8)

		   if (i2 < 15) { // histogramme a droite

		   setfillstyle(SOLID_FILL,BLACK);
		   if (i2) { // effacer la barre precedente
   bar(350 + ((i2-1) * 20),43,360 + ((i2-1) * 20),340-graphique[1][i2-1]);
		   } // fin de if(i2)

			  graphique[0][i2] = (rand() % 290) +5;
			  // garder les anciennes positions des barres pour effacer
			  graphique[1][i2] = graphique[0][i2];

		  setcolor(COUL_CHIFFRES);

		  if (i2 < 14) { // afficher la barre en 3D
bouton_3D(350 + (i2*20),340-graphique[0][i2],360 + (i2*20),340,COUL_BARRE,3,0);
		  } // fin de if (i2 < 14)

		   } // if (i2 < 15)

		   if (i2 < 15) { // graphique en courbe bas

			  graphique[2][i2] = (rand() % 99) + 1;

			  // effacer la courbe precedente
  box(20 + (i2 * 20),361, 40 + (i2 * 20),460,BLACK,BLACK,PAS_D_OMBRE);

			  setcolor(COUL_COURBE);
if (i2 > 0) { // graphique en courbe : bas gauche

line (20 + (i2 * 20),460-graphique[2][i2-1], 40 + (i2 * 20),460-graphique[2][i2]);

} // fin de if (i2 > 0)

  // le graphique en barre horizontale : bas droite
	  graphique[3][i2] = (rand() % 274) + 1;

  // effacer la barre horizontale precedente
box(350, 365+(i2*6.5), 625 , 369+(i2*6.5), BLACK,BLACK, PAS_D_OMBRE);

  // dessiner la barre horizontale
box(350, 365+(i2*6.5), 350 +graphique[3][i2], 369+(i2*6.5), LIGHTGREEN,BLACK, PAS_D_OMBRE);

		   } // fin de if (i2 < 15)

	   delay(1);
	   } // fin de for (i2 = 0..)

   i1++;
   } //  fin de while (!kbhit())  kbhit 2

   };// fin de while (!kbhit())  kbhit 1
   return ;
} // fin de la fonction generer_afficher_chiffres

Conclusion :


/* PROGRAMME EN C SOUS DOS TURBO C++2 BORLAND
ecrit le 01-02-2003 par cmarsc
ECRAN DE COTATIONS BOURSIERES : MODE GRAPHIQUE */

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.