duci.ro FORUM at forumco.com
duci.ro FORUM at forumco.com
Home | Profile | Register | Active Topics | Active Polls | Members | Private Messages | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?




 All Forums
 ProgrammingPool environment
 Functii grafice WinBGI (Pascal, C )
 Grafic simplu 2D (PASCAL & C)
 Forum Locked
 Send Topic to a Friend
 Printer Friendly
Author  Topic Next Topic  

duci
Forum Admin


210 Posts

Posted - 08/07/2005 :  10:13:27  Show Profile  Email Poster Send duci a Private Message
Exemplu WinBGI - graficul functiei sin(x)/x - limbajul C

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <winbgim.h>

/* O reprezentare grafica elementara a unei functii de
o singura variabila */

double func(double x,double pi)
{
double z;
z = 50.0 * sin ( x * x ) / 1000.0 * exp( - x / 2.0 );
return (z);
}
double MAX ( double a , double b )
{
if ( a >= b ) return a ; else return b ;
}
double MIN(double a, double b)
{
if ( a <= b ) return a ; else return b ;
}

void plot ( double v[] , double may , double miy)
{
int i,j;
for ( i = 0 ; i < 640 ; i++ )
{
j = 349 - 350 / (may-miy) * ( v[i] - miy );// Intreg !!!
putpixel ( i , j , 15 );//Functia plotata cu puncte
}
}

int main()

{
double y,a,b,h,may,miy;
double v[640];//vector continand esantionarea functiei
int i,j,k;
double pi=atan(1.0)*4.0;
a = 0.0 ;//Intervalul de plotare [a,b]
b = 6.0 ;
h= ( b - a ) / 640 ;//Pasul in reprezentarea grafica
//Calculam functia pe intervalul [a,b] cu pasul h
for ( i = 0 ; i < 640 ;
v[ i ] = func( a + i * h , pi ),i++);
//********scalare
may=v[0];
miy=v[0];
for ( i = 1 ; i < 640 ; i++ )
{
may = MAX ( may , v[i] );
miy = MIN ( miy , v[i] );
}
i = DETECT ;//Grafic BGI
j = DETECT ;
initgraph (&i,&j,"d:\\tc");
cleardevice ();
plot ( v,may,miy);//Graficul propriu-zis
closegraph ;
system ( "pause" );
return 0 ;
}

Prof.Dr. D. Ciurchea

Google AdSense

USA
Mountain View


duci
Forum Admin



210 Posts

Posted - 08/07/2005 :  10:17:41  Show Profile  Email Poster Send duci a Private Message
Exemplu WinBGI- graficul functiei sin(x)/x - limbajul Pascal
Program grafic_elementar;
(* O reprezentare grafica elementara a unei functii de
o singura variabila *)

uses graph ;
const
npct = 640 ;
type
vec = array [1..npct] of real ;

var
v : vec ; {vector continand esantionarea functiei}
i,j :integer ;
x,a,b,h,may,miy :real ;

function func (var x : real ) : real ;
Begin
func := 50.0 * sin ( x ) * 1000.0 ;
End ;
{**************************************************************}

function max(a,b:real):real; { Val. maxima intre 2 nr. reale }
Begin
if a>b then max:=a else max:=b;
End ;

{**************************************************************}

function min(a,b:real):real; { Val. minima intre 2 nr. reale }
Begin
if a>b then min:=b else min:=a;
End ;

BEGIN
a := 0.0 ;{Intervalul de plotare [a,b]}
b := 6.0 ;
h := ( b - a ) / npct ;{Pasul in reprezentarea grafica}
{Calculam functia pe intervalul [a,b] cu pasul h}
for i := 1 to npct do
begin
x := a + i * h ;
v[ i ] := func( x );
end ;
{********scalare}
may := v[ 1 ];
miy := v[ 1 ];
for i := 1 to npct do
begin
may := max ( may , v[ i ] );
miy := min ( miy , v[ i ] );
end ;
{Grafic BGI }
i := DETECT ;
j := DETECT ;
initgraph ( i , j , 'd:\tp\bgi');
cleardevice ();
outtextxy ( 1 , 10 , 'Text in fereastra grafica');
{Graficul propriu-zis}
for i := 1 to 640 do
begin
j := 349 - round (350.0 /
( may - miy ) * ( v[ i ] - miy ) );{ Intreg !!!}
putpixel ( i , j , 15 ) ; {Functia plotata cu puncte}
end ;
writeln ('Gata. Apasa orice tasta in fereastra consola.');
readln ;
closegraph ;
END.

Prof.Dr. D. Ciurchea
Go to Top of Page
   Topic Next Topic  
 Forum Locked
 Send Topic to a Friend
 Printer Friendly
Jump To:
duci.ro FORUM at forumco.com © 2000-05 ForumCo.com Go To Top Of Page
Generated in 3.59 seconds. Hello from Duci !!! Snitz Forums 2000
RSS Feed 1 RSS Feed 2
Powered by ForumCo 2000-2008
TOS - AUP - URA - Privacy Policy
ForumCo Free Blogs and Galleries
Signup for a free forum or Go Banner Free