21 de maio de 2009
Projeto I
Abrir o arquivo original;
Abrir o arquivo novo;
Ler o cabeçalho do arquivo original;
Ler os números do arquivo original e ao mesmo tempo ir gravando os números no arquivo novo de acordo com as opções de Negativo ou de Alargamento de Contraste, cada uma dessas opções possuem um fórmula específica;
Exemplo do laço para ler e gravar:
//Depois que leu o cabeçalho:
do{
fscanf(arquivooriginal,"%s",&gravar);
numero = atof(gravar);
if feof(arquivooriginal) break;
if(opcao = = 1) fprintf(arquivonovo, "%.0f ",255-numero);
if(opcao = = 2) fprintf(arquivonovo, "%.0f ",255/6.4 * log(numero+128));
}while (!feof(arquivooriginal));
Obs. Opção 1 é para o Negativo e Opção 2 é para o Alargamento de Contraste.
Acho que isso já ajuda, visto que nos posts já tem as funções para abrir o arquivo original, abrir o arquivo novo,ler o cabeçlho e fechar os arquivos abertos.
Só lembrando para abrir os arquivos:
//Original - abrir um arquivo que já existe para a leitura
if ((arquivooriginal = fopen("C:/tc/BIN/clown.pgm", "rt"))== NULL)
{
fprintf(stderr, "Erro ao abrir o arquivo.\n");
return 1;
}
//Novo - abrir um arquivo que já existe e se não existir ele cria o arquivo
arquivonovo = fopen("C:/tc/BIN/clownNOVO.pgm", "wt");
29 de abril de 2009
Projeto I
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
{
FILE *in;
int gdriver = DETECT, gmode, errorcode;
int i,j;
int sign;
int tons;
int num;
float x,y;
float DadosX[300],DadosY[300];
float maxY = 0;//,maxY = 0;
float YScale = 0;//,XScale = 0;
float faixa[17];
float soma = 0;
float yData = 0,Y = 0;
char tipo[40];
char *b;
clrscr();
if ((in = fopen("C:/tc/BIN/clown.pgm", "rt"))== NULL)
{
fprintf(stderr, "Cannot open input file.\n");
return 1;
}
//Ler cabecalho
fgets(tipo,40,in);
printf("%s",tipo);
fgets(tipo,35,in);
printf("%s",tipo);
//Ler numeros
fscanf(in,"%s",&tipo);
x = atof(tipo);
printf("%3.0f ",x);
fscanf(in,"%s",&tipo);
y = atof(tipo);
printf("%3.0f = %3.0f\n",y,x*y);
fscanf(in,"%s",&tipo);
tons = atoi(tipo);
//maxX = tons;
printf("%d\n",tons);
for(j = 0;j <= 16; j++){
faixa[j] = 0;
}//FOR
do{
fscanf(in,"%s",&tipo);
num = atoi(tipo);
if feof(in) break;
if((num >= 0 ) && (num <= 15)) faixa[0]++;
if((num >= 16 ) && (num <= 30)) faixa[1]++;
if((num >= 31 ) && (num <= 45)) faixa[2]++;
if((num >= 46 ) && (num <= 60)) faixa[3]++;
if((num >= 61 ) && (num <= 75)) faixa[4]++;
if((num >= 76 ) && (num <= 90)) faixa[5]++;
if((num >= 91 ) && (num <= 105)) faixa[6]++;
if((num >= 106 ) && (num <= 120)) faixa[7]++;
if((num >= 121 ) && (num <= 135)) faixa[8]++;
if((num >= 136 ) && (num <= 150)) faixa[9]++;
if((num >= 151 ) && (num <= 165)) faixa[10]++;
if((num >= 166 ) && (num <= 180)) faixa[11]++;
if((num >= 181 ) && (num <= 195)) faixa[12]++;
if((num >= 196 ) && (num <= 210)) faixa[13]++;
if((num >= 211 ) && (num <= 225)) faixa[14]++;
if((num >= 226 ) && (num <= 240)) faixa[15]++;
if((num >= 241 ) && (num <= 255)) faixa[16]++;
}while (!feof(in));
printf("\t");
for(j = 0;j <= 16; j++){
if(faixa[j] > maxY ) maxY = faixa[j];
printf("Faixa: %d = %3.0f \t",j+1,faixa[j]);
if(j % 2 == 0) printf("\n\t");
soma = soma + faixa[j];
}//FOR
printf("\nSoma: %3.0f\n",soma);
printf("Maximo em X: %3.0f\n",maxY);
YScale = (400-40)/maxY;
printf("YScale: %f\n",YScale);
getch();
fclose(in);
// inicializar modo grafico
initgraph(&gdriver, &gmode, "C:\\tc\\bgi");
// read result of initialization
errorcode = graphresult();
if (errorcode != grOk) // an error occurred
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); // return with error code
}
//Inicializando grafico
//Linhas
line(40,40-15,40,400);
line(40,400,565,400);
//Setas
line(40-5,40-15,40+5,40-15);
line(40-5,40-15,40,40-15-15);
line(40,40-15-15,40+5,40-15);
line(565,400-5,565,400+5);
line(565,400-5,565+15,400);
line(565+15,400,565,400+5);
j = 15;
for(i = 0;i <= 16; i++){
//Linhas Pequenas
setcolor(7);
line(40+j+7,maxY*YScale+40,40+j+7,maxY*YScale+40+3);
//Numeros legenda
settextstyle(2, 0,4);
gcvt(i+1,sign,b);
outtextxy(40+j+1,maxY*YScale+40+3,b);
settextstyle(2, 0,4);
yData = faixa[i];
if(faixa[i]==0){
setcolor(7);
settextstyle(2, 0,4);
outtextxy(40+j+5,maxY*YScale+40-15,"0");
}else{
//Defindo Y
Y = (maxY*YScale)-((yData - maxY*YScale+40) * (YScale));
//Plotando no grafico
setcolor(i);
if((i == 0)||(i == 7)) setcolor(9);
if((i == 15))setcolor(4);
if((i == 16))setcolor(2);
rectangle(40+j,Y+40-1,40+j+15,maxY*YScale+40);
//Numeros
gcvt(faixa[i],sign,b);
outtextxy(40+j-5,Y+40-15,b);
}//ELSE
j = j + 30;
}//FOR
getch();
closegraph();
return 0;
}
25 de abril de 2009
20 de março de 2009
Projeto I
/***************************************************************************************
Universidade do Vale do Paraiba - Ciencia da Computacao
Materia : Projeto I - Exercicio I
Professor : Valdir Gil Pillat
Autor : Alberto Felipe Dias Rodrigues
Descricao : Trabalho em coordenadas e ultilizacao da biblioteca grafica (Bandeira do Brasil)
Data : 05 mar 2009
***************************************************************************************/
// Bibliotecas
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
void estrela (int x, int y, int tam);
int main(void)
{
/* Declaracao das variaveis e inicializacao do gdrive como DETECT para forcar a
deteccao da controladora de video */
int gdriver = DETECT, gmode, errorcode;
/* gdrive indica a controladora e gmode indica o modo.
A string "" indica o diretorio */
initgraph(&gdriver, &gmode, "");
/* graphresult retorna o codigo de erro.
A constante grOk indica que houve ou nao erro */
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
/* LIMPA A TELA GRAFICA */
cleardevice();
// Retangulo verde
/* PADRAO E COR */
setfillstyle(SOLID_FILL, GREEN);
/* ALTERA A COR DE EXIBICAO DOS GRAFICOS*/
setcolor(GREEN);
rectangle(0,50,getmaxx(),getmaxy()-50);
/* PREENCHE UMA AREA NA TELA AO REDOR DE UM PONTO
ATE ENCONTRAR A COR ESPECIFICADA*/
floodfill(10,60,GREEN);
//****
// Losango amarelo
setfillstyle(SOLID_FILL, YELLOW);
setcolor(YELLOW);
line(23, getmaxy()/2,getmaxx()/2, 53);
line(getmaxx()/2, 53, getmaxx()-23, getmaxy()/2);
line(getmaxx()-23, getmaxy()/2, getmaxx()/2, getmaxy()-53);
line(getmaxx()/2, getmaxy()-53, 23, getmaxy()/2);
floodfill(50,245,YELLOW);
//****
// Circulo azul
setfillstyle(SOLID_FILL, BLUE);
setcolor(BLUE);
circle(getmaxx()/2,getmaxy()/2,150);
floodfill(325,255,BLUE);
//****
// Meio branco
setfillstyle(SOLID_FILL, WHITE);
setcolor(WHITE);
/* X CENTRO, Y CENTRO, ANGULO INICIAL, ANGULO FINAL, RAIO */
arc(getmaxx()/2-40,getmaxy()/2+240, 50, 111, 293);
arc(getmaxx()/2-40,getmaxy()/2+252, 48, 114, 270);
arc(getmaxx()/2,getmaxy()/2, 165, 182, 150);
arc(getmaxx()/2,getmaxy()/2, 340, 355, 150);
floodfill(getmaxx()/2,getmaxy()/2-40,WHITE);
//****
// Texto
setcolor(BLACK);
/* FONTE DIRECAO E TAMANHO */
settextstyle(TRIPLEX_FONT, HORIZ_DIR, 2);
outtextxy(getmaxx()/2-100,getmaxy()/2-42, "O");
outtextxy(getmaxx()/2-87,getmaxy()/2-44, "R");
outtextxy(getmaxx()/2-74,getmaxy()/2-46, "D");
outtextxy(getmaxx()/2-61,getmaxy()/2-48, "E");
outtextxy(getmaxx()/2-48,getmaxy()/2-50, "M");
outtextxy(getmaxx()/2-28,getmaxy()/2-48, "E");
outtextxy(getmaxx()/2-8,getmaxy()/2-46, "P");
outtextxy(getmaxx()/2+5,getmaxy()/2-44, "R");
outtextxy(getmaxx()/2+18,getmaxy()/2-42, "O");
outtextxy(getmaxx()/2+31,getmaxy()/2-39, "G");
outtextxy(getmaxx()/2+44,getmaxy()/2-34, "R");
outtextxy(getmaxx()/2+57,getmaxy()/2-30, "E");
outtextxy(getmaxx()/2+70,getmaxy()/2-26, "S");
outtextxy(getmaxx()/2+81,getmaxy()/2-18, "S");
outtextxy(getmaxx()/2+92,getmaxy()/2-12, "O");
//****
// Estrelas
estrela(getmaxx()/2+40,getmaxy()/2-65,2);
estrela(getmaxx()/2+30,getmaxy()/2+30,2);
estrela(getmaxx()/2-80,getmaxy()/2+20,2);
estrela(getmaxx()/2-60,getmaxy()/2+40,2);
estrela(getmaxx()/2-40,getmaxy()/2+20,2);
estrela(getmaxx()/2,getmaxy()/2,2);
estrela(getmaxx()/2+20,getmaxy()/2+70,2);
estrela(getmaxx()/2-80,getmaxy()/2+80,2);
estrela(getmaxx()/2-90,getmaxy()/2+90,2);
estrela(getmaxx()/2-90,getmaxy()/2+50,2);
estrela(getmaxx()/2+40,getmaxy()/2+80,2);
estrela(getmaxx()/2+90,getmaxy()/2+55,2);
estrela(getmaxx()/2-50,getmaxy()/2+70,2);
estrela(getmaxx()/2-10,getmaxy()/2+77,2);
estrela(getmaxx()/2-30,getmaxy()/2+45,2);
estrela(getmaxx()/2-60,getmaxy()/2+55,2);
estrela(getmaxx()/2+60,getmaxy()/2+55,2);
estrela(getmaxx()/2+80,getmaxy()/2+50,2);
estrela(getmaxx()/2+90,getmaxy()/2+30,2);
estrela(getmaxx()/2+95,getmaxy()/2+70,2);
estrela(getmaxx()/2-50,getmaxy()/2+90,2);
estrela(getmaxx()/2-30,getmaxy()/2+90,2);
estrela(getmaxx()/2-20,getmaxy()/2+95,2);
estrela(getmaxx()/2,getmaxy()/2+80,2);
estrela(getmaxx()/2+10,getmaxy()/2+80,2);
estrela(getmaxx()/2,getmaxy()/2+100,2);
estrela(getmaxx()/2,getmaxy()/2+117,2);
getch();
/* Cancelamento do modo grafico inializado por intigraph()
liberando a memoria ultilizada para graficos */
closegraph();
return 0;
}
// Funcao para desenhar a estrela
void estrela (int x, int y, int tam)
{
int met=tam/2;
int alt=tam+3;
// Estrela
// Parte de cima da estrela
setfillstyle(SOLID_FILL, WHITE);
setcolor(WHITE);
line(x, y,x+tam, y);
line(x+tam, y, x+met, y-alt);
line(x+met, y-alt, x, y);
floodfill(x+1,y-1,WHITE);
// Parte direita de cima da estrela
line(x+tam, y, x+tam, y+tam);
line(x+tam, y+tam, x+tam+alt, y+met);
line(x+tam+alt, y+met, x+tam, y);
floodfill(x+tam+1,y+1,WHITE);
// Parte esquerda de cima da estrela
line(x, y, x, y+tam);
line(x, y+tam, x-alt, y+met);
line(x-alt, y+met, x, y);
floodfill(x-1,y+1,WHITE);
// Parte direita de baixo da estrela
line(x+tam, y+met, x+met, y+tam);
line(x+met, y+tam, x+tam+met, y+tam+alt);
line(x+tam+met, y+tam+alt, x+tam, y+met);
floodfill(x+tam,y+tam+1,WHITE);
// Parte esquerda de baixo da estrela
line(x, y+met, x+met, y+tam);
line(x+met, y+tam, x-met, y+tam+alt);
line(x-met, y+tam+alt, x, y+met);
floodfill(x,y+tam+1,WHITE);
floodfill(x+1,y+1,WHITE);
//****
}
obs: Não se esqueçam de mudar o DIR para a pasta BGI e de incluir a biblioteca gráfica do Turbo C.
2 - Arquivos
/***************************************************************************************
Universidade do Vale do Paraiba - Ciencia da Computacao
Materia : Projeto I - Exercicio II
Professor : Valdir Gil Pillat
Autor : Alberto Felipe Dias Rodrigues
Descricao : Trabalho de Manipulacao de Dados
Data : 12 mar 2009
***************************************************************************************/
// Bibliotecas
#include <stdio.h>
#include <conio.h>
#include <string.h>
// Inicio do Programa
void main() {
// Declaracoes de variaveis
FILE *arqfunc;
FILE *arqfunc2;
char c1, c2, aux, f1[8], f2[8];
char szLinha[50];
int i1, i2, i = 0, ai1 = 0,ai2 = 0,ai3 = 0,af3 = 0;
double somai1 = 0.00, somai2 = 0.00, somad = 0.00;
float f3, somaf3 = 0.00;
clrscr();
// Abertura dos arquivos
arqfunc = fopen("2003I01F.SJC", "r");
arqfunc2 = fopen("NOVO.SJC", "w");
// Teste de erros
if ((arqfunc == NULL)||(arqfunc2 == NULL)) {
printf("Ocorreu um Erro nos arquivos!");
getch();
}
else {
printf("Arquivo lido com sucesso!\nGerando o arquivo NOVO...\n\n");
// Ler cabecalho e copiar cabecalho
memset(szLinha,'\0',sizeof(szLinha));
fgets(szLinha,11,arqfunc);
fputs(szLinha,arqfunc2);
fgets(szLinha,19,arqfunc);
fputs(szLinha,arqfunc2);
fgets(szLinha,38,arqfunc); szLinha[35] = '\0';
fputs(szLinha, arqfunc2);
sprintf(szLinha,"\thpF2-h'F\n");
fputs(szLinha, arqfunc2);
// Lendo os dados e copiando os dados
while (aux != EOF) {
if(getc(arqfunc) == EOF){
break;
}
i = i + 1;
aux = fscanf(arqfunc, "%s\t%s\t%d\t%f\t%d\t%c\t%c",&f1, &f2, &i1, &f3, &i2, &c1, &c2);
fprintf(arqfunc2, "%s\t%s\t", f1, f2);
if(i1==0){
fprintf(arqfunc2, "000\t%1.1f\t", f3);
}else{
fprintf(arqfunc2, "%d\t%1.1f\t", i1, f3);
}
if(i2==0){
fprintf(arqfunc2,"000\t%c\t%c\t", c1, c2);
fprintf(arqfunc2,"000\n");
}else{
fprintf(arqfunc2,"%d\t%c\t%c\t", i2, c1, c2);
fprintf(arqfunc2,"%d\n", i2-i1);
}
// Calculando as somas
if(i1==0){
ai1 = ai1 + 1;
}else{
somai1 = somai1+i1;
}
if(i2==0){
ai2 = ai2 + 1;
}else{
somai2 = somai2+i2;
}
if(f3==0){
af3 = af3 + 1;
}else{
somaf3 = somaf3+f3;
}
if((i1==0)||(i2==0)){
ai3 = ai3 + 1;
}else{
somad = somad + (i2-i1);
}
}//WHILE
// Finalizando, calculando as medias e imprimindo os valores das mesmas
fprintf(arqfunc2, "\nMedias\t\t%1.1f\t%1.2f\t%1.1f\t\t\t%1.1f", somai1/(i - ai1), somaf3/(i - af3), somai2/(i - ai2), somad/(i - ai3));
// Fechando os arquivos abertos
fclose (arqfunc);
fclose (arqfunc2);
printf("Arquivo NOVO gerado com sucesso!\n");
printf("\nFIM : Tecle algo ! ");
getch();
}//ELSE
}
obs: Lembrando que no arquivo de leitura nas colunas em que houverem espaços em branco, (quando não tem número) , em vez dos espaços em branco o professor deixou colocar "0" então, coloquem o "0" nos espaços em branco para que funcione.
3 - Gráfico 1
/***************************************************************************************
Universidade do Vale do Paraiba - Ciencia da Computacao
Materia : Projeto I - Exercicio I
Professor : Valdir Gil Pillat
Autor : Alberto Felipe Dias Rodrigues
Descricao : Trabalho em coordenadas, ultilizacao da biblioteca grafica e manipulacao de arquivos
(Grafico 1)
Data : 19 mar 2009
***************************************************************************************/
// Bibliotecas
#include <graphics.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
FILE *arqfunc;
char c1, c2, aux, f1[8], f2[8];
char szLinha[50];
int i1, i2, i = 0,j;
float f3,ut;
double xScale,yScale;
double XData,YData,X,Y,Xtemp,Ytemp;
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
cleardevice();
setfillstyle(SOLID_FILL, WHITE);
setcolor(WHITE);
settextstyle(SMALL_FONT, VERT_DIR, 6);
outtextxy(30, 180, "F0F2 em Mhz");
settextstyle(SMALL_FONT, HORIZ_DIR, 6);
outtextxy(getmaxx()/2-80, getmaxy()/2+200, "UT");
outtextxy(getmaxx()/2-160, getmaxy()/2-200, "SJC Aug 28, 2000");
outtextxy(getmaxx()/2+120, getmaxy()/2-100, "Legenda");
outtextxy(getmaxx()/2+140+15, getmaxy()/2-70-7, "F0F2");
outtextxy(getmaxx()/2+100, getmaxy()/2-220, "UNIVAP - ALBERTO");
setfillstyle(SOLID_FILL, BLUE);
setcolor(BLUE);
rectangle(getmaxx()/2+140, getmaxy()/2-70,getmaxx()/2+150, getmaxy()/2-60);
floodfill(getmaxx()/2+140+2, getmaxy()/2-70+2,BLUE);
setfillstyle(SOLID_FILL, GREEN);
setcolor(GREEN);
xScale = (400-85)/(24.0-0);
yScale = (400-85)/(20.0-0);
settextstyle(SMALL_FONT, HORIZ_DIR, 5);
// HORIZONTAIS
for(j=1;j<=20;j++){
if(j%2!=0){
line(85-3, 85+j*yScale, 85, 85+j*yScale);//impar
switch(j){
case 1: outtextxy(85-25, 85+j*yScale+7, "18");break;
case 3: outtextxy(85-25, 85+j*yScale+7, "16");break;
case 5: outtextxy(85-25, 85+j*yScale+7, "14");break;
case 7: outtextxy(85-25, 85+j*yScale+7, "12");break;
case 9: outtextxy(85-25, 85+j*yScale+7, "10");break;
case 11: outtextxy(85-15, 85+j*yScale+7, "8");break;
case 13: outtextxy(85-15, 85+j*yScale+7, "6");break;
case 15: outtextxy(85-15, 85+j*yScale+7, "4");break;
case 17: outtextxy(85-15, 85+j*yScale+7, "2");break;
case 19: outtextxy(85-15, 85+j*yScale+7, "0");break;
};//SWHICH
}else{
line(85-5, 85+j*yScale, 24*xScale+85, 85+j*yScale); //par
}//ELSE
}//FOR
// VERTICAIS
line(85, 20*yScale+85+5, 85, 85); //esquerda
outtextxy(85-15, 20*yScale+85+15, "0,00");
for(j=1;j<=24;j++){
if((j==2)||(j==6)||(j==10)||(j==14)||(j==18)||(j==22)){
line(j*xScale+85, 20*yScale+85+3, j*xScale+85, 20*yScale+85);
}else if((j==4)||(j==8)||(j==12)||(j==16)||(j==20)||(j==24)){
line(j*xScale+85, 20*yScale+85+5, j*xScale+85, 85);
switch(j){
case 4: outtextxy(j*xScale+85-15, 20*yScale+85+15, "4,00");break;
case 8: outtextxy(j*xScale+85-15, 20*yScale+85+15, "8,00");break;
case 12: outtextxy(j*xScale+85-15, 20*yScale+85+15, "12,00");break;
case 16: outtextxy(j*xScale+85-15, 20*yScale+85+15, "16,00");break;
case 20: outtextxy(j*xScale+85-15, 20*yScale+85+15, "20,00");break;
case 24: outtextxy(j*xScale+85-15, 20*yScale+85+15, "24,00");break;
};//SWHICH
}// ELSE IF
}// FOR
setfillstyle(SOLID_FILL, BLUE);
setcolor(BLUE);
arqfunc = fopen("2003I01F.SJC", "r");
// Teste de erros
if (arqfunc == NULL) {
printf("Ocorreu um Erro no arquivo!");
getch();
exit(1);
} else {
// Ler cabecalho e copiar cabecalho
memset(szLinha,'\0',sizeof(szLinha));
fgets(szLinha,11,arqfunc);
fgets(szLinha,19,arqfunc);
fgets(szLinha,38,arqfunc); szLinha[35] = '\0';
// Lendo os dados e copiando os dados
while (aux != EOF){
if(getc(arqfunc) == EOF) {
break;
}
i = i + 1;
aux = fscanf(arqfunc, "%s\t%s\t%d\t%f\t%d\t%c\t%c",&f1, &f2, &i1, &f3, &i2, &c1, &c2);
ut = atof(f1);
if((ut == 0.0)||(f3 == 0.0)){
//
}
else{
XData = ut;
YData = f3;
X = XData * xScale + 85; //Posição do Ponto em X
Y = 85+20*yScale-(YData * yScale); //Posição do Ponto em Y
circle(X,Y,1);
if(i==1){
//
}
else {
line(Xtemp, Ytemp, X, Y);
}
Xtemp = X;
Ytemp = Y;
}//ELSE
}//WHILE
// Fechando os arquivos abertos
fclose (arqfunc);
}//ELSE
getch();
closegraph();
return 0;
}
obs: Não se esqueçam de mudar o DIR para a pasta BGI e de incluir a biblioteca gráfica do Turbo C.
Lembrando que no arquivo de leitura nas colunas em que houverem espaços em branco, (quando não tem número) , em vez dos espaços em branco o professor deixou colocar "0" então, coloquem o "0" nos espaços em branco para que funcione.
Também coloque o arquivo em questão na pasta BGI.
4 - Gráfico 2
/***************************************************************************************
Universidade do Vale do Paraiba - Ciencia da Computacao
Materia : Projeto I - Exercicio I
Professor : Valdir Gil Pillat
Autor : Alberto Felipe Dias Rodrigues
Descricao : Trabalho em coordenadas, ultilizacao da biblioteca grafica e manipulacao de arquivos
(Grafico 2)
Data : 19 mar 2009
***************************************************************************************/
// Bibliotecas
#include <graphics.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
FILE *arqfunc;
char i1[3], i2[3], c1, c2, aux, f1[8], f2[8];
char szLinha[50];
int i = 0, j;
float f3,ut, hf, hpf2;
double xScale,yScale;
double XData,YData,X,Y,Xtemp,Ytemp;
double xScale2,yScale2;
double XData2,YData2,X2,Y2,Xtemp2,Ytemp2;
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
cleardevice();
setfillstyle(SOLID_FILL, WHITE);
setcolor(WHITE);
settextstyle(SMALL_FONT, VERT_DIR, 6);
outtextxy(30, 180, "h'f hpF2 em km");
settextstyle(SMALL_FONT, HORIZ_DIR, 6);
outtextxy(getmaxx()/2-80, getmaxy()/2+200, "UT");
outtextxy(getmaxx()/2-160, getmaxy()/2-200, "SJC Aug 28, 2000");
outtextxy(getmaxx()/2+120, getmaxy()/2-100, "Legenda");
outtextxy(getmaxx()/2+140+15, getmaxy()/2-70-7, "h'f");
outtextxy(getmaxx()/2+140+15, getmaxy()/2-40-7, "hpF2");
outtextxy(getmaxx()/2+100, getmaxy()/2-220, "UNIVAP - ALBERTO");
setfillstyle(SOLID_FILL, BLUE);
setcolor(BLUE);
rectangle(getmaxx()/2+140, getmaxy()/2-70,getmaxx()/2+150, getmaxy()/2-60);
floodfill(getmaxx()/2+140+2, getmaxy()/2-70+2,BLUE);
setfillstyle(SOLID_FILL, RED);
setcolor(RED);
rectangle(getmaxx()/2+140, getmaxy()/2-40,getmaxx()/2+150, getmaxy()/2-30);
floodfill(getmaxx()/2+140+2, getmaxy()/2-40+2,RED);
setfillstyle(SOLID_FILL, GREEN);
setcolor(GREEN);
xScale = (400-85)/24.0;
yScale = (400-85)/450.0;
xScale2 = (400-85)/24.0;
yScale2 = (400-85)/450.0;
settextstyle(SMALL_FONT, HORIZ_DIR, 5);
// HORIZONTAIS
line(85-5, 85, 24*xScale+85, 85); //20 superior
outtextxy(85-32, 85-yScale-10, "450");
for(j=1;j<=450;j++){
if(j%2!=0){
switch(j){
case 425: line(85-3, 85+j*yScale, 85, 85+j*yScale);break;
case 375: line(85-3, 85+j*yScale, 85, 85+j*yScale);break;
case 325: line(85-3, 85+j*yScale, 85, 85+j*yScale);break;
case 275: line(85-3, 85+j*yScale, 85, 85+j*yScale);break;
case 225: line(85-3, 85+j*yScale, 85, 85+j*yScale);break;
case 175: line(85-3, 85+j*yScale, 85, 85+j*yScale);break;
case 125: line(85-3, 85+j*yScale, 85, 85+j*yScale);break;
case 75: line(85-3, 85+j*yScale, 85, 85+j*yScale);break;
case 25: line(85-3, 85+j*yScale, 85, 85+j*yScale);break;
};//SWHICH
}else{
switch(j){
case 450:
outtextxy(85-25, 85+j*yScale-10, "0");
line(85-5, 85+j*yScale, 24*xScale+85, 85+j*yScale);
break;
case 400:
outtextxy(85-25, 85+j*yScale-10, "50");
line(85-5, 85+j*yScale, 24*xScale+85, 85+j*yScale);
break;
case 350:
outtextxy(85-32, 85+j*yScale-10, "100");
line(85-5, 85+j*yScale, 24*xScale+85, 85+j*yScale);
break;
case 300:
outtextxy(85-32, 85+j*yScale-10, "150");
line(85-5, 85+j*yScale, 24*xScale+85, 85+j*yScale);
break;
case 250:
outtextxy(85-32, 85+j*yScale-10, "200");
line(85-5, 85+j*yScale, 24*xScale+85, 85+j*yScale);
break;
case 200:
outtextxy(85-32, 85+j*yScale-10, "250");
line(85-5, 85+j*yScale, 24*xScale+85, 85+j*yScale);
break;
case 150:
outtextxy(85-32, 85+j*yScale-10, "300");
line(85-5, 85+j*yScale, 24*xScale+85, 85+j*yScale);
break;
case 100:
outtextxy(85-32, 85+j*yScale-10, "350");
line(85-5, 85+j*yScale, 24*xScale+85, 85+j*yScale);
break;
case 50:
outtextxy(85-32, 85+j*yScale-10, "400");
line(85-5, 85+j*yScale, 24*xScale+85, 85+j*yScale);
break;
};//SWHICH
}//ELSE
}//FOR
// VERTICAIS
line(85, 450*yScale+85+5, 85, 85); //esquerda
outtextxy(85-15, 450*yScale+85+15, "0,00");
for(j=1;j<=24;j++){
if((j==2)||(j==6)||(j==10)||(j==14)||(j==18)||(j==22)){
line(j*xScale+85, 450*yScale+85+3, j*xScale+85, 450*yScale+85);
}else if((j==4)||(j==8)||(j==12)||(j==16)||(j==20)||(j==24)){
line(j*xScale+85, 450*yScale+85+5, j*xScale+85, 85);
switch(j){
case 4: outtextxy(j*xScale+85-15, 450*yScale+85+15, "4,00");break;
case 8: outtextxy(j*xScale+85-15, 450*yScale+85+15, "8,00");break;
case 12: outtextxy(j*xScale+85-15, 450*yScale+85+15, "12,00");break;
case 16: outtextxy(j*xScale+85-15, 450*yScale+85+15, "16,00");break;
case 20: outtextxy(j*xScale+85-15, 450*yScale+85+15, "20,00");break;
case 24: outtextxy(j*xScale+85-15, 450*yScale+85+15, "24,00");break;
};//SWHICH
}// ELSE IF
}// FOR
arqfunc = fopen("2003I01F.SJC", "r");
// Teste de erros
if (arqfunc == NULL) {
printf("Ocorreu um Erro no arquivo!");
getch();
exit(1);
} else {
// Ler cabecalho e copiar cabecalho
memset(szLinha,'\0',sizeof(szLinha));
fgets(szLinha,11,arqfunc);
fgets(szLinha,19,arqfunc);
fgets(szLinha,38,arqfunc); szLinha[35] = '\0';
// Lendo os dados e copiando os dados
while (aux != EOF){
if(getc(arqfunc) == EOF) {
break;
}
i = i + 1;
aux = fscanf(arqfunc, "%s\t%s\t%s\t%f\t%s\t%c\t%c",&f1, &f2, &i1, &f3, &i2, &c1, &c2);
ut = atof(f1);
hf = atof(i1);
hpf2 = atof(i2);
if((ut == 0.0)||(hpf2 == 0.0)){
//
}
else{
setfillstyle(SOLID_FILL, RED);
setcolor(RED);
XData2 = ut;
YData2 = hpf2;
X2 = (XData2 * xScale2) + 85; //Posição do Ponto em X
Y2 = (85+(450*yScale))-(YData2 * yScale2); //Posição do Ponto em Y
circle(X2,Y2,1);
if(i==1){
//
}
else {
line(Xtemp2, Ytemp2, X2, Y2);
}
Xtemp2 = X2;
Ytemp2 = Y2;
}//ELSE
if((ut == 0.0)||(hf == 0.0)){
//
}
else{
setfillstyle(SOLID_FILL, BLUE);
setcolor(BLUE);
XData = ut;
YData = hf;
X = (XData * xScale) + 85; //Posição do Ponto em X
Y = (85+(450*yScale))-(YData * yScale); //Posição do Ponto em Y
circle(X,Y,1);
if(i==1){
//
}
else {
line(Xtemp, Ytemp, X, Y);
}
Xtemp = X;
Ytemp = Y;
}//ELSE
}//WHILE
// Fechando os arquivos abertos
fclose (arqfunc);
}//ELSE
getch();
closegraph();
return 0;
}
obs: Não se esqueçam de mudar o DIR para a pasta BGI e de incluir a biblioteca gráfica do Turbo C.
Lembrando que no arquivo de leitura nas colunas em que houverem espaços em branco, (quando não tem número) , em vez dos espaços em branco o professor deixou colocar "0" então, coloquem o "0" nos espaços em branco para que funcione.
Também coloque o arquivo em questão na pasta BGI.
13 de março de 2009
Projeto I
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
int main(){
FILE *Arq, *ArqNew;
char Str1[10], Str2[10], Str3[5], Str4[5];
char Str5[5], Str6[5], Str7[5], a[50];
int i, count_hpF2 = 0 , count_hF = 0 , count_foF2 = 0;
float hpF2, hF, foF2, Soma_hF = 0, Soma_foF2 = 0, Soma_hpF2 = 0, Soma_Sub = 0, Sub;
clrscr();
Arq = fopen("C:\\TC\\ARQUIVO\\ARQ.SJC","r");
ArqNew = fopen("C:\\TC\\ARQUIVO\\ARQNEW.SJC","w");
if(!Arq){
printf("Erro ao abrir o arquivo.");
getch();
exit(1);
}
if(!ArqNew){
printf("Erro ao criar o arquivo.");
getch();
exit(1);
}
// Copia o Cabeçalho
for(i=1;i<=11;i++){
fscanf(Arq,"%s",&a);
fprintf(ArqNew,"%s\t",a);
if((i==2) || (i==4))
fprintf(ArqNew,"\n");
}
fprintf(ArqNew,"hpF2-h'F");
fprintf(ArqNew,"\n");
// Começa a leitura do arquivo
while(!feof(Arq)){
if(getc(Arq) == EOF){
break;
}
fscanf(Arq,"%s %s %s %s %s %s %s",&Str1, &Str2, &Str3, &Str4, &Str5, &Str6, &Str7);
fprintf(ArqNew,"%s\t%s\t%s\t%s\t%s\t%s\t%s\t",&Str1, &Str2, &Str3, &Str4, &Str5, &Str6, &Str7);
hF = atof(Str3);
hpF2 = atof(Str5);
if(hF){
Soma_hF = Soma_hF + hF;
count_hF = count_hF + 1;
if(hpF2){
Soma_hpF2 = Soma_hpF2 + hpF2;
count_hpF2 = count_hpF2 + 1;
Sub = hpF2 - hF;
Soma_Sub = Soma_Sub + Sub;
}
}
if(atof(Str4)){
Soma_foF2 = Soma_foF2 + atof(Str4);
count_foF2 = count_foF2 + 1;
}
if(Sub){
fprintf(ArqNew,"%.0f\n",Sub);
}
else{
fprintf(ArqNew,"-\n");
}
hF = NULL;
hpF2 = NULL;
Sub = NULL;
}
fprintf(ArqNew,"Medias \t \t%.2f",Soma_hF/count_hF);
fprintf(ArqNew,"\t%.2f",Soma_foF2/count_foF2);
fprintf(ArqNew,"\t%.2f",Soma_hpF2/count_hpF2);
fprintf(ArqNew,"\t \t \t%.2f",Soma_Sub/count_hpF2);
fclose(Arq);
getch();
return 0;
}
11 de março de 2009
Projeto I
Clique Aqui para Baixar
/***************************************************************************************
Universidade do Vale do Paraiba - Ciencia da Computacao
Materia : Projeto I - Exercicio II
Professor : Valdir Gil Pillat
Autor : Jonatas Balmant
Descricao : Trabalho de Manipulacao de Dados
Data : 10 mar 2009
***************************************************************************************/
//----( Bibliotecas )------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
//----( Inicio do Programa )-----------------------------------------------------------
void main()
{
//----( Declaracoes )-----------------------------------------------------------
char szLinha[50];
char szTemp[10];
double dbMedias[3] = {0,0,0};
double hpF_hF[3] = {0,0,0};
int cont = 0;
int nLinha = 0;
char *p; //--- PONTERIO PARA szLinha ---
int i,j,tam;
FILE *in, *out;
clrscr();
printf("Iniciando Leitura de Arquivo...");
//---( ABERTURA DOS ARQUIVOS )---------------------------------------------
if((in = fopen("C:\\Arquivo.txt", "rt"))== NULL)
{
printf("Nao Achei o Arquivo");
return;
}
if((out = fopen("C:\\RESULT.txt", "wt"))==NULL)
{
printf("Nao Consegui Criar o Arquivo");
return;
}
//---( CABECALHO )--------------------------------------------------------------------------
memset(szLinha,'\0',sizeof(szLinha));
fgets(szLinha,11,in);
fputs(szLinha,out);
fgets(szLinha,19,in);
fputs(szLinha,out);
fgets(szLinha,38,in); szLinha[35] = '\0';
fputs(szLinha, out);
sprintf(szLinha,"\thpF2-h'F\n");
fputs(szLinha, out);
//---( DADOS )-------------------------------------------------------------------------------
while((fgets(szLinha, 35, in))!= NULL)
{
hpF_hF[0] = 0; hpF_hF[1] = 0; hpF_hF[2] = 0;
nLinha++;
p = szLinha; //--- PONTEIRO PARA LINHA ---
cont=0;
//--- LOOP ATE ENCONTRAR O SEGUNDO "TAB" DA LINHA, POSICIONANDO O PONTEIRO NO LOCAL CERTO PARA O INICIO DA COLETA DOS DADOS
for(i = 0; i < 20; i++)
{
p++;
if(p[0] == '\t')
{
cont++;
if(cont == 2) { p++; break; }
}
}
memset(szTemp,'\0',sizeof(szTemp));
for(j = 0; j < 3; j++)
{
cont = 0;
for(i = 0; i < 10; i++)
{
if((p[i] == '\t') || (p[i] == '-'))
break;
cont++;
}
if((p[0] == '\t') || (p[0] == '-'))
{
dbMedias[j] = dbMedias [j] + 0;
p+=2;
}
else
{
strncpy(szTemp, p, cont);
szTemp[cont] = '\0';
hpF_hF[j] = atof(szTemp);
dbMedias[j] = dbMedias[j] + atof(szTemp);
p = p + (cont+1);
}
}
tam = strlen(szLinha);
if(szLinha[tam-1] == '\n') szLinha[tam-1] = '\0'; //--- RETIRA O CARACTER '\n' ---
fputs(szLinha,out);
sprintf(szLinha,"\t%5.0f\n",(hpF_hF[2] - hpF_hF[0]));
fputs(szLinha,out);
}
//---( RODAPE )---------------------------------------------------------------------------
sprintf(szLinha,"Medias\t\t%.1f\t%.1f\t%.1f\t\t\t%7.1f",dbMedias[0]/nLinha,dbMedias[1]/nLinha, dbMedias[2]/nLinha,(dbMedias[2] - dbMedias[0])/nLinha);
fputs(szLinha,out);
fclose(in);
fclose(out);
textcolor(10);
cprintf("\nArquivo \'Resultado\' Gerado com Sucesso!!");
getch();
}
6 de março de 2009
Projeto I
No segundo projeto da disciplina Projeto I são passados arquivos de redução de dados das ionossondas do grupo de pesquisa de Física e Astronomia do IP&D, UNIVAP, para que cada grupo onde:
Estrutura do arquivo:
Data: 03/03/2005
UT LT h'F foF2 hpF2 SF ES
0.0808 21.0808 225 6.0 318 - N
0.1732 21.1732 222 6.1 316 - N
0.2532 21.2532 217 6.3 304 - N
0.3330 21.3330 227 6.3 306 - N
0.4232 21.4232 220 6.2 301 - N
Onde UT (Universal Time - hora Universal) e LT (Local Time - hora local), h'F é a altura da camada F, foF2 é a freqüência crítica da camada F, hpF2 altura do pico da camada F, SF spread F, ES esporádica.
Grupo Ciência da Computação
| Grupo | Nome | Arquivo |
| 1 | Alberto Felipe D. Rodrigues | 2003I01F.SJC |
| 2 | André Luiz Ribeiro de Sousa | 2003I02F.SJC |
| 3 | Dalton D. Meira | 2003I03F.SJC |
| 4 | Diogo Mira Watabayashi | 2003I04F.SJC |
| 5 | Felipe Antonio Cardoso | 2003I05F.SJC |
| 6 | Fernando Costa | 2003I06F.SJC |
| 7 | Helio Tenoro dos Santos | 2003I07F.SJC |
| 8 | Janderci Pereira da Silva | 2003I08F.SJC |
| 9 | Leandro H. Mielle | 2003I09F.SJC |
| 10 | Marcos Antonio Sanches | 2003I10F.SJC |
| 11 | Rodolfo Sousa Guerra | 2003I11F.SJC |
| 12 | Walter Azevedo | 2003I12F.SJC |
| 13 | Jonatas Baltmant | 2003I13F.SJC |
O trabalho que cada grupo terá que realizar as seguintes operações sobre os dados:
- Ler o arquivo referente ao seu grupo (está na tabela acima);
- Calcular a média de: h'F, foF2 e hpF2;
- Calcular a diferença entre: hpF2 e h'F (hpF2 - h'F) e depois calcular a média desta coluna;
- Escrever o arquivo com as seguinte estrutura:
Data: 03/03/2005
UT LT h'F foF2 hpF2 SF ES hpF2-h'F
0.0808 21.0808 225 6.0 318 - N 93
0.1732 21.1732 222 6.1 316 - N 94
0.2532 21.2532 217 6.3 304 - N 87
0.3330 21.3330 227 6.3 306 - N 79
0.4232 21.4232 220 6.2 301 - N 81
Médias 222.2 6.18 309 86.8
3 de março de 2009
Projeto I
(Com a super estrela! xD)
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int left, top, right, bottom;
int x, y, i;
int poly[12];
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
/* draw a rectangle */
left = 30;
top = 10;
right = 610;
bottom = 470;
setfillstyle(SOLID_FILL, 2);
setcolor(2);
rectangle(left,top,right,bottom);
floodfill(50,20,2);
setfillstyle(SOLID_FILL, 15);
setcolor(15);
rectangle(30,100,610,370);
floodfill(50,120,15);
setfillstyle(SOLID_FILL, 4);
setcolor(4);
rectangle(30,150,610,320);
floodfill(50,170,4);
poly[0] = 6;
poly[1] = 11;
poly[2] = 36;
poly[3] = 11;
poly[4] = 12;
poly[5] = 28;
poly[6] = 21;
poly[7] = 0;
poly[8] = 30;
poly[9] = 28;
for(i=1;i<=9;i+=2){
poly[i-1] = poly[i-1] * 5 + 210;
poly[i] = poly[i] * 5 + 165;
}
poly[10] = poly[0];
poly[11] = poly[1];
setfillstyle(SOLID_FILL,14);
setcolor(14);
fillpoly(6,poly);
x = poly[0] + (poly[2] - poly[0])/2;
y = poly[1] + 20;
floodfill(x,y,14);
/* clean up */
getch();
closegraph();
return 0;
}
Projeto I
int gdriver = DETECT, gmode, errorcode;
Declaração de variáveis e inicialização do gdriver como DETECT, para forçar a detecção da controladora de vídeo.
initgraph(&gdriver, &gmode, "");
A função initgraph é chamada. Ela recebe dois parâmetros do tipo int * (pointer para inteiro) e uma string. O primeiro parâmetro é a controladora de vídeo usada ou então a constante DETECT para forçar a autodetecção. O segundo é o modo de vídeo usado. A função initgraph retorna nas varáveis gdriver e gmode a controladora detectada e o modo usado. O terceiro parâmetro é o diretório onde estão os drivers de software para o Turbo C acionar as funções gráficas. O diretório pode ser diferente na sua máquina.Quando não passamos nada nesse terceiro parâmetro o default é o diretório “C:\TC\BGI” .
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
A função graphresult serve para retornar o código do erro. A constante grOk indica que não houve erro. Caso tenha havido erro, o programa termina mostrando na tela qual foi a mensagem de erro gerada pela função initgraph. Caso contrário, o modo gráfico será acionado e a tela ficará completamente preta.
cleardevice();
A função cleardevice() limpa a tela gráfica.
As funções getmaxx() e getmaxy() retornam com valores inteiros os valores máximos das coordenadas x e y da tela.
A função rectangle desenha um retângulo com o canto superior esquerdo no ponto (xsup, ysup) e o canto inferior direito no ponto (xinf, yinf). Possui o seguinte formato: rectangle(xsup, ysup, xinf, yinf).
A função circle desenha um círculo na tela gráfica, com centro em (xcentro,ycentro) e raio especificados em pixeis. Possui o seguinte formato:
circle(xcentro, ycentro, raio).
A função arc(xcentro, ycentro, angulo_inicial, angulo_final, raio) desenha um arco circular na tela gráfica. O centro é dado pelas coordenadas (xcentro, ycentro) e o raio por raio. Os parâmetros angulo_inicial e angulo_final especificam os ângulos inicial e final em graus, onde o 0 está na posição horizontal apontando para a direita e 90 na posição vertical apontando para cima.
A função setfillstyle(padrao,cor) ajusta o padrão e a cor de preenchimento gráfico atuais.
A função floodfill(x, y, borda) preenche uma área na tela gráfica ao redor do ponto dado por (x, y) com a cor e o padrão atuais de preenchimento, setados pela instrução setfillstyle(), até encontrar a cor especificada por borda. O padrao assume um dos valores abaixo.
A função setcolor(cor) é usada para alterar a cor de exibição dos gráficos, sendo o default a cor branca (WHITE). O parâmetro COR é um valor de 0 a 15 ( VGA) ou os nomes definidos como na função textcolor(COR) , que altera a cor dos caracteres no modo texto.
A função settextstyle(fonte, direcao, tamanho) seta o estilo das letras no modo gráfico. Há cinco fontes, Default, triplex, Small, Sans_serif e gótico. Direção = 0, para texto na horizontal e direção=1 para texto na vertical. Tamanho se refere ao tamanho das letras.
A função closegraph() cancela o modo gráfico estabelecido por initgraph() liberando a memória utilizada para gráficos.
A função line(x1, y1, x2, y2) desenha linha entre os pontos de coordenadas x1, y1 e x2, y2.
A função outtextxy(x, y, “texto”) escreve texto colocado dentro das aspas na posição x, y.
23 de fevereiro de 2009
Projeto I
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
char msg[80];
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
cleardevice();
//RETANGULO********************
setfillstyle(SOLID_FILL, GREEN);
setcolor(GREEN);
rectangle(0,50,getmaxx(),getmaxy()-50);
floodfill(10,60,GREEN);
//*****************************
//LOSANGO**********************
setfillstyle(SOLID_FILL, YELLOW);
setcolor(YELLOW);
line(23, getmaxy()/2,getmaxx()/2, 53);
line(getmaxx()/2, 53, getmaxx()-23, getmaxy()/2);
line(getmaxx()-23, getmaxy()/2, getmaxx()/2, getmaxy()-53);
line(getmaxx()/2, getmaxy()-53, 23, getmaxy()/2);
floodfill(50,245,YELLOW);
//*****************************
//CIRCULO**********************
setfillstyle(SOLID_FILL, BLUE);
setcolor(BLUE);
circle(getmaxx()/2,getmaxy()/2,150);
floodfill(325,255,BLUE);
//*****************************
//RETANGULO2*******************
setfillstyle(SOLID_FILL, WHITE);
setcolor(WHITE);
rectangle(getmaxx()/2-150,getmaxy()/2-10,getmaxx()/2+150,getmaxy()/2+10);
floodfill(getmaxx()/2,getmaxy()/2,WHITE);
//*****************************
//TEXTO************************
setcolor(BLACK);
settextstyle(TRIPLEX_FONT, HORIZ_DIR, 2);
sprintf(msg, "ORDEM E PROGRESSO");
outtextxy(getmaxx()/2-100,getmaxy()/2-13, msg);
//*****************************
//ESTRELAS
estrela(getmaxx()/2+40,getmaxy()/2-30,2);
estrela(getmaxx()/2+30,getmaxy()/2+30,2);
estrela(getmaxx()/2+60,getmaxy()/2+40,2);
estrela(getmaxx()/2-10,getmaxy()/2+50,2);
estrela(getmaxx()/2-40,getmaxy()/2+80,2);
estrela(getmaxx()/2-30,getmaxy()/2+30,2);
estrela(getmaxx()/2+20,getmaxy()/2+70,2);
estrela(getmaxx()/2-80,getmaxy()/2+80,2);
estrela(getmaxx()/2-90,getmaxy()/2+90,2);
estrela(getmaxx()/2-90,getmaxy()/2+50,2);
estrela(getmaxx()/2+40,getmaxy()/2+80,2);
estrela(getmaxx()/2+90,getmaxy()/2+55,2);
estrela(getmaxx()/2-50,getmaxy()/2+70,2);
estrela(getmaxx()/2-10,getmaxy()/2+77,2);
estrela(getmaxx()/2-30,getmaxy()/2+45,2);
estrela(getmaxx()/2-60,getmaxy()/2+55,2);
estrela(getmaxx()/2+60,getmaxy()/2+55,2);
estrela(getmaxx()/2+80,getmaxy()/2+50,2);
estrela(getmaxx()/2+90,getmaxy()/2+30,2);
estrela(getmaxx()/2+95,getmaxy()/2+70,2);
estrela(getmaxx()/2-50,getmaxy()/2+90,2);
estrela(getmaxx()/2-30,getmaxy()/2+90,2);
estrela(getmaxx()/2-20,getmaxy()/2+95,2);
estrela(getmaxx()/2,getmaxy()/2+80,2);
estrela(getmaxx()/2+10,getmaxy()/2+80,2);
estrela(getmaxx()/2,getmaxy()/2+100,2);
estrela(getmaxx()/2,getmaxy()/2+117,2);
/* clean up */
getch();
closegraph();
return 0;
}
//FUNCAO PARA DESENHAR ESTRELA
void estrela (int x, int y, int tam)
{
int met=tam/2;
int alt=tam+3;
//ESTRELA**********************
//PARTE DE CIMA
setfillstyle(SOLID_FILL, WHITE);
setcolor(WHITE);
line(x, y,x+tam, y);
line(x+tam, y, x+met, y-alt);
line(x+met, y-alt, x, y);
floodfill(x+1,y-1,WHITE);
//PARTE DA DIREITA
line(x+tam, y, x+tam, y+tam);
line(x+tam, y+tam, x+tam+alt, y+met);
line(x+tam+alt, y+met, x+tam, y);
floodfill(x+tam+1,y+1,WHITE);
//PARTE DA ESQUERDA
line(x, y, x, y+tam);
line(x, y+tam, x-alt, y+met);
line(x-alt, y+met, x, y);
floodfill(x-1,y+1,WHITE);
//PARTE DA DIREITA BAIXO
line(x+tam, y+met, x+met, y+tam);
line(x+met, y+tam, x+tam+met, y+tam+alt);
line(x+tam+met, y+tam+alt, x+tam, y+met);
floodfill(x+tam,y+tam+1,WHITE);
//PARTE DA ESQUERDA BAIXO
line(x, y+met, x+met, y+tam);
line(x+met, y+tam, x-met, y+tam+alt);
line(x-met, y+tam+alt, x, y+met);
floodfill(x,y+tam+1,WHITE);
floodfill(x+1,y+1,WHITE);
//*****************************
}
20 de fevereiro de 2009
Projeto I
//Se ajudar em algo já ta bom!
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
int x,y;
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
cleardevice();
x=getmaxx()/2-50;
y=getmaxy()/2-50;
//CENTRO*********************************
setfillstyle(SOLID_FILL, WHITE);
setcolor(WHITE);
line(x, y,x+80, y);
line(x, y, x-30, y+80);
line(x+80, y, x+110, y+80);
line(x+110, y+80, x+40, y+110);
line(x+40, y+110, x-30, y+80);
floodfill(x+1,y+1,WHITE);
//*********************************************
//PONTA DE CIMA***********************
line(x, y, x+40, y-110);
line(x+40, y-110, x+80, y);
floodfill(x+1,y-1,WHITE);
//********************************************
//PONTA DIREITA***********************
line(x+80, y, x+190, y);
line(x+190, y, x+110, y+80);
floodfill(x+80+1,y+1,WHITE);
//********************************************
//PONTA ESQUERDA**********************
line(x, y, x-110, y);
line(x-110, y, x-30, y+80);
floodfill(x-1,y+1,WHITE);
//**********************************************
//PONTA DIREITA DE BAIXO**************
line(x+110, y+80, x+150, y+190);
line(x+150, y+190, x+40, y+110);
floodfill(x+110,y+90+1,WHITE);
//**********************************************
//PONTA ESQUERDA DE BAIXO*************
line(x-30, y+80, x-80, y+190);
line(x-80, y+190, x+40, y+110);
floodfill(x-30+1,y+80+1,WHITE);
//*************************************************
getch();
closegraph();
return 0;
}
Projeto I
Quem quiser baixar um mini tutorial de como utilizar a biblioteca "graphics.h"
Abaixo alguns exemplos:
Exemplos:
- Escreva uma função "opengraph" que inicialize o modo gráfico utilizando as funções "detectgraph" e "initgraph".
Em seguida escreva um programa que utilize essa função e exiba uma sequência de quatro círculos de diferentes cores para visualização do modo, bem como o modo em uso.
Solução: ini_graf.c - Faça um programa capaz de desenhar um círculo, um quadrado ou uma reta no estilo de preenchimento e cor determinadas pelo usuário.
Solução: desenha.c - Crie uma função que gere um gráfico de barras verticais a partir de 5 números (positivos) de entrada.
Solução: graf_bar.c - Crie uma função que gere um gráfico de pizza a partir de 5 números (positivos) de entrada.
Solução: graf_piz.c - Utilize a função e "outtextxy" para esvrever legendas dos valores de entrada nos gráficos dos exercícios 3 e 4.
Solução: lege_bar.c
Solução: lege_piz.c - Escreva um programa que permita mover um círculo pela tela utilizando as setas do teclado.
Solução: mov_circ.c
p.s. Essa 6 é bem interessante!
19 de fevereiro de 2009
Projeto I
