CRONOMETRO DIGITAL
Publicado por Thiago 12/04/2006
[ Hits: 13.886 ]
Este é um cronômetro digital bem básico.
A lógica usada no desenvolvimento do programa é apenas uma proposta de solucionar um problema.
Sendo assim sugestões serão bem aceitas e comentários também é claro ;)
/*
* PROGRAMA: SCD.C
* VERSAO: 1.0
* AUTOR: THIAGOAMM
* DATA: 05/04/06
* LOCAL: GOIANIA (GYN) - G0
*
* =========================================================================
* CABE A NÓS MUDAR O BRASIL
* Pare de sonhar o Brasil e começe a trabalhar!
* Pare de reclamar e volte seu pensamento e ações em prol de transformações
* positivas.
* Os políticos não querem mudar o Brasil!
* Então o que estamos esperando?!
* ==========================================================================
*
*/
#include <curses.h>
#include <stdio.h>
#include <stdlib.h>
#define msg " ============ CRONOMETRO DIGITAL =========="
#define aut "\n .**o._.o**. By thiagoamm .**o._.o**."
/* Cabecalhos */
void desenha_hrDE(WINDOW *win, int hr);
void desenha_hrDD(WINDOW *win, int hr);
void desenha_minDE(WINDOW *win, int min);
void desenha_minDD(WINDOW *win, int min);
void desenha_segDE(WINDOW *win, int seg);
void desenha_segDD(WINDOW *win, int seg);
int main(void)
{
/* Declarando as variáveis */
int hora,min,seg,qh,rh,qm,rm,qs,rs;
char sair;
WINDOW *wstd, *wborder;
int i;
int u = 0;
/* Inicializando variáveis */
hora = 0, min = 0, seg = 0;
/* Inicializando modo grafico com curses.h */
(void)initscr();
wstd = newwin(9,58,5,10);
wborder = newwin(11,62,4,8);
start_color();
init_pair(1,COLOR_BLACK,COLOR_RED);
init_pair(2,COLOR_BLUE,COLOR_YELLOW);
init_pair(3,COLOR_BLACK,COLOR_WHITE);
init_pair(4,COLOR_YELLOW,COLOR_BLUE);
init_pair(5,COLOR_BLACK,COLOR_WHITE);
init_pair(6,COLOR_RED,COLOR_BLACK);
init_pair(7,COLOR_YELLOW,COLOR_YELLOW);
init_pair(8,COLOR_WHITE,COLOR_BLACK);
wbkgd(wstd,COLOR_PAIR(8) | A_BOLD | A_BLINK);
wbkgd(wborder,COLOR_PAIR(3) | A_BLINK);
curs_set(0); /* Desabilitando o cursor do mouse */
system("clear");
puts(msg);
puts(aut);
sleep(2);
while (hora < 24)
{
while (min < 60)
{
while (seg < 60)
{
wrefresh(wborder);
wrefresh(wstd);
/* Calculo para segundos */
qs = seg / 10;
rs = seg % 10;
desenha_segDE(wstd,qs);
desenha_segDD(wstd,rs);
/* Calculo para minutos */
qm = min / 10;
rm = min % 10;
desenha_minDE(wstd,qm);
desenha_minDD(wstd,rm);
/* Calculo para horas */
qh = hora / 10;
rh = hora % 10;
desenha_hrDE(wstd,qh);
desenha_hrDD(wstd,rh);
sleep(1);
seg = seg + 1;
}
seg = 0; /* Resetando segundo */
min = min + 1; /* Incrementando minuto */
}
min = 0;
hora = hora + 1; /* Incrementando hora */
/* Reseta hora para que o loop seja continuo */
if (hora > 23)
{
hora = 0;
}
}
endwin(); /* Finalizando modo curses */
return(0);
}
/* Sub-rotina que controla o digito da esquerda nas horas */
void desenha_hrDE(WINDOW *win, int hr)
{
switch(hr)
{
case 0:
mvwprintw(win,1,3,"###");
mvwprintw(win,2,2,"# #");
mvwprintw(win,3,2,"# #");
mvwprintw(win,4,2," ");
mvwprintw(win,5,2,"# #");
mvwprintw(win,6,2,"# #");
mvwprintw(win,7,3,"###");
break;
case 1:
mvwprintw(win,1,3," #");
mvwprintw(win,2,2," ");
mvwprintw(win,3,2," ");
mvwprintw(win,4,2," ");
mvwprintw(win,5,2," ");
mvwprintw(win,6,2," ");
mvwprintw(win,7,2," #");
break;
case 2:
mvwprintw(win,1,3,"### ");
mvwprintw(win,4,3,"###");
mvwprintw(win,5,2,"# ");
mvwprintw(win,6,2,"# ");
mvwprintw(win,7,3,"### ");
break;
}
return;
}
/* Sub-rotina que controla o digito da direita nas horas */
void desenha_hrDD(WINDOW *win, int hr)
{
switch(hr)
{
case 0:
mvwprintw(win,1,12,"###");
mvwprintw(win,2,11,"# #");
mvwprintw(win,3,11,"# # #");
mvwprintw(win,4,11," ");
mvwprintw(win,5,11,"# #");
mvwprintw(win,6,11,"# # #");
mvwprintw(win,7,12,"###");
break;
case 1:
mvwprintw(win,1,12," #");
mvwprintw(win,2,11," ");
mvwprintw(win,3,11," ");
mvwprintw(win,4,11," ");
mvwprintw(win,5,11," ");
mvwprintw(win,6,11," ");
mvwprintw(win,7,12," #");
break;
case 2:
mvwprintw(win,1,12,"### ");
mvwprintw(win,4,12,"###");
mvwprintw(win,5,11,"# ");
mvwprintw(win,6,11,"# ");
mvwprintw(win,7,12,"### ");
break;
case 3:
mvwprintw(win,4,12,"###");
mvwprintw(win,5,11," #");
mvwprintw(win,6,11," #");
break;
}
return;
}
/* Subrotina para controle do digito da esquerda nos minutos */
void desenha_minDE(WINDOW *win, int min)
{
switch(min)
{
case 0:
mvwprintw(win,1,23,"###");
mvwprintw(win,2,22,"# #");
mvwprintw(win,3,22,"# #");
mvwprintw(win,4,22," ");
mvwprintw(win,5,22,"# #");
mvwprintw(win,6,22,"# #");
mvwprintw(win,7,23,"###");
break;
case 1:
mvwprintw(win,1,23," #");
mvwprintw(win,2,22," ");
mvwprintw(win,3,22," ");
mvwprintw(win,4,22," ");
mvwprintw(win,5,22," ");
mvwprintw(win,6,22," ");
mvwprintw(win,7,23," #");
break;
case 2:
mvwprintw(win,1,23,"### ");
mvwprintw(win,4,23,"###");
mvwprintw(win,5,22,"# ");
mvwprintw(win,6,22,"# ");
mvwprintw(win,7,23,"### ");
break;
case 3:
mvwprintw(win,4,23,"###");
mvwprintw(win,5,22," #");
mvwprintw(win,6,22," #");
break;
case 4:
mvwprintw(win,1,22,"# #");
mvwprintw(win,2,22,"#");
mvwprintw(win,3,22,"#");
mvwprintw(win,4,23,"###");
mvwprintw(win,7,22," #");
break;
case 5:
mvwprintw(win,1,22," ### ");
mvwprintw(win,2,25," ");
mvwprintw(win,3,25," ");
mvwprintw(win,5,22," ");
mvwprintw(win,6,22," ");
mvwprintw(win,7,22," ### ");
break;
case 6:
mvwprintw(win,5,26,"#");
mvwprintw(win,6,26,"#");
break;
case 7:
mvwprintw(win,2,26,"#");
mvwprintw(win,3,26,"#");
mvwprintw(win,4,22," ");
mvwprintw(win,5,22," ");
mvwprintw(win,6,22," ");
mvwprintw(win,7,22," #");
break;
case 8:
mvwprintw(win,4,23,"###");
mvwprintw(win,5,22,"#");
mvwprintw(win,6,22,"#");
mvwprintw(win,7,23,"### ");
break;
case 9:
mvwprintw(win,5,22," ");
mvwprintw(win,6,22," ");
break;
}
return;
}
/* Sub-rotina para controle do digito da direita nos minutos */
void desenha_minDD(WINDOW *win, int min)
{
switch(min)
{
case 0:
mvwprintw(win,1,31,"###");
mvwprintw(win,2,30,"# #");
mvwprintw(win,3,30,"# # #");
mvwprintw(win,4,30," ");
mvwprintw(win,5,30,"# #");
mvwprintw(win,6,30,"# # #");
mvwprintw(win,7,31,"###");
break;
case 1:
mvwprintw(win,1,31," #");
mvwprintw(win,2,30," ");
mvwprintw(win,3,30," ");
mvwprintw(win,4,30," ");
mvwprintw(win,5,30," ");
mvwprintw(win,6,30," ");
mvwprintw(win,7,31," #");
break;
case 2:
mvwprintw(win,1,31,"### ");
mvwprintw(win,4,31,"###");
mvwprintw(win,5,30,"# ");
mvwprintw(win,6,30,"# ");
mvwprintw(win,7,31,"### ");
break;
case 3:
mvwprintw(win,4,31,"###");
mvwprintw(win,5,30," #");
mvwprintw(win,6,30," #");
break;
case 4:
mvwprintw(win,1,30,"# #");
mvwprintw(win,2,30,"#");
mvwprintw(win,3,30,"#");
mvwprintw(win,4,31,"###");
mvwprintw(win,7,30," #");
break;
case 5:
mvwprintw(win,1,30," ### ");
mvwprintw(win,2,33," ");
mvwprintw(win,3,33," ");
mvwprintw(win,5,30," ");
mvwprintw(win,6,30," ");
mvwprintw(win,7,30," ### ");
break;
case 6:
mvwprintw(win,5,30,"#");
mvwprintw(win,6,30,"#");
break;
case 7:
mvwprintw(win,2,34,"#");
mvwprintw(win,3,34,"#");
mvwprintw(win,4,30," ");
mvwprintw(win,5,30," ");
mvwprintw(win,6,30," ");
mvwprintw(win,7,30," #");
break;
case 8:
mvwprintw(win,4,31,"###");
mvwprintw(win,5,30,"#");
mvwprintw(win,6,30,"#");
mvwprintw(win,7,31,"### ");
break;
case 9:
mvwprintw(win,5,30," ");
mvwprintw(win,6,30," ");
break;
}
return;
}
/* Sub-rotina para controle do digito da esquerda nos segundos */
void desenha_segDE(WINDOW *win, int seg)
{
switch(seg)
{
case 0:
mvwprintw(win,1,43,"###");
mvwprintw(win,2,42,"# #");
mvwprintw(win,3,42,"# #");
mvwprintw(win,4,42," ");
mvwprintw(win,5,42,"# #");
mvwprintw(win,6,42,"# #");
mvwprintw(win,7,43,"###");
break;
case 1:
mvwprintw(win,1,43," #");
mvwprintw(win,2,42," ");
mvwprintw(win,3,42," ");
mvwprintw(win,4,42," ");
mvwprintw(win,5,42," ");
mvwprintw(win,6,42," ");
mvwprintw(win,7,43," #");
break;
case 2:
mvwprintw(win,1,43,"### ");
mvwprintw(win,4,43,"###");
mvwprintw(win,5,42,"# ");
mvwprintw(win,6,42,"# ");
mvwprintw(win,7,43,"### ");
break;
case 3:
mvwprintw(win,4,43,"###");
mvwprintw(win,5,42," #");
mvwprintw(win,6,42," #");
break;
case 4:
mvwprintw(win,1,42,"# #");
mvwprintw(win,2,42,"#");
mvwprintw(win,3,42,"#");
mvwprintw(win,4,43,"###");
mvwprintw(win,7,42," #");
break;
case 5:
mvwprintw(win,1,42," ### ");
mvwprintw(win,2,45," ");
mvwprintw(win,3,45," ");
mvwprintw(win,5,42," ");
mvwprintw(win,6,42," ");
mvwprintw(win,7,42," ### ");
break;
case 6:
mvwprintw(win,5,42,"#");
mvwprintw(win,6,42,"#");
break;
case 7:
mvwprintw(win,2,46,"#");
mvwprintw(win,3,46,"#");
mvwprintw(win,4,42," ");
mvwprintw(win,5,42," ");
mvwprintw(win,6,42," ");
mvwprintw(win,7,42," #");
break;
case 8:
mvwprintw(win,4,43,"###");
mvwprintw(win,5,42,"#");
mvwprintw(win,6,42,"#");
mvwprintw(win,7,43,"### ");
break;
case 9:
mvwprintw(win,5,42," ");
mvwprintw(win,6,42," ");
break;
}
return;
}
/* Sub-rotina que controla o digito da direita nos segundos */
void desenha_segDD(WINDOW *win, int seg)
{
switch(seg)
{
case 0:
mvwprintw(win,1,51,"###");
mvwprintw(win,2,50,"# #");
mvwprintw(win,3,50,"# #");
mvwprintw(win,4,50," ");
mvwprintw(win,5,50,"# #");
mvwprintw(win,6,50,"# #");
mvwprintw(win,7,51,"###");
break;
case 1:
mvwprintw(win,1,51," #");
mvwprintw(win,2,50," ");
mvwprintw(win,3,50," ");
mvwprintw(win,4,50," ");
mvwprintw(win,5,50," ");
mvwprintw(win,6,50," ");
mvwprintw(win,7,51," #");
break;
case 2:
mvwprintw(win,1,51,"### ");
mvwprintw(win,4,51,"###");
mvwprintw(win,5,50,"# ");
mvwprintw(win,6,50,"# ");
mvwprintw(win,7,51,"### ");
break;
case 3:
mvwprintw(win,4,51,"###");
mvwprintw(win,5,50," #");
mvwprintw(win,6,50," #");
break;
case 4:
mvwprintw(win,1,50,"# #");
mvwprintw(win,2,50,"#");
mvwprintw(win,3,50,"#");
mvwprintw(win,4,51,"###");
mvwprintw(win,7,50," #");
break;
case 5:
mvwprintw(win,1,50," ### ");
mvwprintw(win,2,53," ");
mvwprintw(win,3,53," ");
mvwprintw(win,5,50," ");
mvwprintw(win,6,50," ");
mvwprintw(win,7,50," ### ");
break;
case 6:
mvwprintw(win,5,50,"#");
mvwprintw(win,6,50,"#");
break;
case 7:
mvwprintw(win,2,54,"#");
mvwprintw(win,3,54,"#");
mvwprintw(win,4,50," ");
mvwprintw(win,5,50," ");
mvwprintw(win,6,50," ");
mvwprintw(win,7,50," #");
break;
case 8:
mvwprintw(win,4,51,"###");
mvwprintw(win,5,50,"#");
mvwprintw(win,6,50,"#");
mvwprintw(win,7,51,"### ");
break;
case 9:
mvwprintw(win,5,50," ");
mvwprintw(win,6,50," ");
break;
}
return;
}
Cálculo da circunferência de um círculo
Número par ou ímpar e positivo ou negativo
Modo Simples de Baixar e Usar o bash-completion
Monitorando o Preço do Bitcoin ou sua Cripto Favorita em Tempo Real com um Widget Flutuante
Adicionar botão "mostrar área de trabalho" no Zorin OS
Como montar um servidor de backup no linux
Trazendo de volta o Serviços em Segundo Plano no Plasma6
É normal não gostar de KDE? (21)
Servidor para arquivos e banco de dados (4)
780 mil usuários do Janelas baIxaram Linux em um mês (4)
Atualizei meu ubuntu e desliguei e ele não inicia corretamente (12)









