Enviado em 21/06/2014 - 22:35h
Galera, Algum Tempo Atrás eu tinha perguntado se alguem me ajudava a criar uma parabola (sem resposta), entao eu decidi criar eu mesmo , mas estou com um monte de erro e queria a ajuda de vcs
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
int main(){
// Variaveis
int a,b,c;
double cons =(double)5/(double)21;
int cuadr = 1;
double yCuad(double x);
int yPix(double y);
double yCuad = yCuad(x);
double y1Cuad = yCuad(x1);
// Pede o A,B e C e os 5 'X'
printf("Digite o Valor de 'A'\n");
scanf("%i",&a);
printf("Digite o Valor de 'B'\n");
scanf("%i",&b);
printf("Digite o Valor de 'C'\n");
scanf("%i",&c);
// Iniciar o Modo Grafico
int gdriver = DETECT, gmode;
initgraph(&gdriver, &gmode, NULL);
// Define a Cor do Fundo
setbkcolor(12);
// Pega o Tamanho Maximo da Tela e Coloca Nas Variaveis 'xmax' e 'ymax'
int xmax = getmaxx();
int ymax = getmaxy();
// Pega o Tamanho da Tela ('xmax' e 'ymax') e Divide por 2 (para ter a metade do tamanho da tela).
//x_Div=xmax/2;
//y_Div=ymax/2;
// Declara as Variaveis da Grade . H=Horizontal/V=Vertical
int gradeH = 0;
int gradeV = 0;
int gradeH2 = 0;
int gradeV2 = 0;
// Desenha as Linhas para o lado direito
int suvaco = 0;
for (;suvaco <= xmax + 230;suvaco++){
putpixel(gradeH,gradeV,WHITE);
putpixel(gradeH,gradeV + 20,WHITE);
putpixel(gradeH,gradeV + 40,WHITE);
putpixel(gradeH,gradeV + 60,WHITE);
putpixel(gradeH,gradeV + 80,WHITE);
putpixel(gradeH,gradeV + 100,WHITE);
putpixel(gradeH,gradeV + 120,WHITE);
putpixel(gradeH,gradeV + 140,WHITE);
putpixel(gradeH,gradeV + 160,WHITE);
putpixel(gradeH,gradeV + 180,WHITE);
putpixel(gradeH,gradeV + 200,WHITE);
putpixel(gradeH,gradeV + 220,WHITE);
putpixel(gradeH,gradeV + 240,WHITE);
putpixel(gradeH,gradeV + 260,WHITE);
putpixel(gradeH,gradeV + 280,WHITE);
putpixel(gradeH,gradeV + 300,WHITE);
putpixel(gradeH,gradeV + 320,WHITE);
putpixel(gradeH,gradeV + 340,WHITE);
putpixel(gradeH,gradeV + 360,WHITE);
putpixel(gradeH,gradeV + 380,WHITE);
putpixel(gradeH,gradeV + 400,WHITE);
putpixel(gradeH,gradeV + 420,WHITE);
putpixel(gradeH,gradeV + 440,WHITE);
putpixel(gradeH,gradeV + 460,WHITE);
putpixel(gradeH,gradeV + 480,WHITE);
// Para Não Ocorrer Erros de Tamanho
if (gradeH >= 640){
gradeH--;
}
gradeH++;
}
// Desenha as Linhas Para Baixo
for (int suvaco1 = 0;suvaco1 <= xmax + 230;suvaco1++){
moveto(0,0);
putpixel(gradeH2,gradeV2,WHITE);
putpixel(gradeH2 + 20,gradeV2,WHITE);
putpixel(gradeH2 + 40,gradeV2,WHITE);
putpixel(gradeH2 + 60,gradeV2,WHITE);
putpixel(gradeH2 + 80,gradeV2,WHITE);
putpixel(gradeH2 + 100,gradeV2,WHITE);
putpixel(gradeH2 + 120,gradeV2,WHITE);
putpixel(gradeH2 + 140,gradeV2,WHITE);
putpixel(gradeH2 + 160,gradeV2,WHITE);
putpixel(gradeH2 + 180,gradeV2,WHITE);
putpixel(gradeH2 + 200,gradeV2,WHITE);
putpixel(gradeH2 + 220,gradeV2,WHITE);
putpixel(gradeH2 + 240,gradeV2,WHITE);
putpixel(gradeH2 + 260,gradeV2,WHITE);
putpixel(gradeH2 + 280,gradeV2,WHITE);
putpixel(gradeH2 + 300,gradeV2,WHITE);
putpixel(gradeH2 + 320,gradeV2,WHITE);
putpixel(gradeH2 + 340,gradeV2,WHITE);
putpixel(gradeH2 + 360,gradeV2,WHITE);
putpixel(gradeH2 + 380,gradeV2,WHITE);
putpixel(gradeH2 + 400,gradeV2,WHITE);
putpixel(gradeH2 + 420,gradeV2,WHITE);
putpixel(gradeH2 + 440,gradeV2,WHITE);
putpixel(gradeH2 + 460,gradeV2,WHITE);
putpixel(gradeH2 + 480,gradeV2,WHITE);
putpixel(gradeH2 + 500,gradeV2,WHITE);
putpixel(gradeH2 + 520,gradeV2,WHITE);
putpixel(gradeH2 + 540,gradeV2,WHITE);
putpixel(gradeH2 + 560,gradeV2,WHITE);
putpixel(gradeH2 + 580,gradeV2,WHITE);
putpixel(gradeH2 + 600,gradeV2,WHITE);
putpixel(gradeH2 + 620,gradeV2,WHITE);
putpixel(gradeH2 + 640,gradeV2,WHITE);
// Para Não Ocorrer Erros de Tamanho(2)
if (gradeV2 >= 480){
gradeV2--;
}
gradeV2++;
}
//g.drawLine(40, 40, 40, 460);//ordenada(y)
setlinestyle(3, 0, 2);
line(250, 40, 250, 460);//ordenada(y)
// x y x y
//g.drawLine(40, 460, 800, 460);//absisa(x)
line(40, 250, 460, 250);//absisa(x)
outtextxy(215, 45,"50");
line(245, 40, 255, 40);
outtextxy(215, 87,"40");
line(245, 82, 255, 82);
outtextxy( 215, 129,"30");
line(245, 124, 255, 124);
outtextxy(215, 171,"20");
line(245, 166, 255, 166);
outtextxy(215, 213,"10");
line(245, 208, 255, 208);
outtextxy(215, 255,"0");
line(245, 250, 255, 250);
outtextxy(215, 297,"-10");
line(245, 292, 255, 292);
outtextxy( 215, 339,"-20");
line(245, 334, 255, 334);
outtextxy(215, 381,"-30");
line(245, 376, 255, 376);
outtextxy(215, 423,"-40");
line(245, 418, 255, 418);
outtextxy( 215, 465,"-50");
line(245, 460, 255, 460);
outtextxy( 25, 270,"-50");
line(40, 245, 40, 255);
outtextxy(67, 270,"-40");
line(82, 245, 82, 255);
outtextxy( 109, 270,"-30");
line(124, 245, 124, 255);
outtextxy( 151, 270,"-20");
line(166, 245, 166, 255);
outtextxy(193, 270,"-10");
line(208, 245, 208, 255);
outtextxy( 235, 270,"0");
line(250, 245, 250, 255);
outtextxy(277, 270,"10");
line(292, 245, 292, 255);
outtextxy( 319, 270,"20");
line(334, 245, 334, 255);
outtextxy(361, 270," 30" );
line(376, 245, 376, 255);
outtextxy( 403, 270,"40");
line(418, 245, 418, 255);
outtextxy( 445, 270,"50");
line(460, 245, 460, 255)
if(cuadr==1)
line(i, yPix(yCuad), i+1, yPix(y1Cuad));
//double yCuad = yLin(x);
system("clear");
getch();
return 0;
closegraph();
}
double yCuad(double x){
double y =a*(x*x)+b*x+c;
double x = -50;
double x1 = -50;
for (int i = 40; i < 460; i++) {
if(i==40){
x= -50;
x1 = x+cons;
}else{
x=x1;
x1 = x1+cons;
}
return y;
}
int yPix(double y){
int pixel= 250;
if(y==0)
pixel= 250;
else if(y<0){
float ypix = (float) (250+(y*(-1)/cons));
pixel= round(ypix);
}else if(y>0){
float ypix = (float) (250-(y/cons));
pixel= round(ypix);
}
return pixel;
}