CPPASCAL
Newbie | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору program grafick; uses Crt,Graph; type TFunction=function(x:real):real; Const Scale=80.0; var cx,cy, { to4ka ots4eta } mx,my: integer; { maximum X Y } function InitGraphics: integer; Var grDriver, grMode : Integer; begin grDriver:=Detect; InitGraph(grDriver, grMode, '..\bgi'); InitGraphics:=GraphResult; end; function CoordX(X: real): integer; begin CoordX:=cx+Trunc(X*Scale); end; function CoordY(Y: real): integer; begin CoordY:=cy-Trunc(Y*Scale); end; function MyVeryCoolFunction(v:real):real; Far; begin MyVeryCoolFunction:=v*v*v; end; procedure PlotAxis; begin SetColor(LightBlue); Line(0,cy,mx,cy); Line(cx,0,cx,my); end; procedure DrawGraph(PF: Pointer; a,b: real); var F: TFunction; temp, Step, x,y, Minimum,Maximum: real; begin @F:=PF; if a=b then begin putpixel(CoordX(a),CoordX(F(a)),Yellow); exit end; if a>b then begin temp:=a; a:=b; b:=temp; end; Step:=(b-a)/(MX+1)*1.0; Minimum:=F(a); Maximum:=Minimum; x:=a; MoveTo(CoordX(x),CoordY(F(x))); SetColor(Yellow); while x<=b do begin x:=x+Step; y:=F(x); LineTo(CoordX(x),CoordY(y)); if Minimum<y then Minimum:=y; if Maximum>y then Maximum:=y; end; end; begin if InitGraphics<>grOK then Exit; MX := GetMaxX; MY := GetMaxY; CX := MX div 2; CY := MY div 2; PlotAxis; DrawGraph(@MyVeryCoolFunction,-1,10); readkey; CloseGraph; end. |