Canvas obyektining pixels xossasi tipidagi ikki olchovli massiv
bo‘lib. har bir soha nuqtasining rangi haqidagi ma’lumotni o‘z ichiga
oladi. Pixels xossasidan foydalanib ixtiyoriy nuqta rangini o‘zgartirish.
ya’ni nuqta chizish mumkin. Misol uchun:
126
y = 2- Sinx • e|- funksiyasi grafigini chiqaradi.
TForml = class(TForm) Buttonl: TButton; procedure ButtonlClick(Sender: TObject); private { Private declarations } public { Public declarations } end; Var Forml: TForml; implementation {$R *.dfm} Function f(x:real):real; Begin f:=2*Sin(x)*exp(x/5) ; end; Procedure GrOfFunc; Var xl,x2:real; yl,y2:real; x:real; y:real; dx:real; l,b:Integer; w,h:Integer; mx,my:real; xO,yO:Integer; Begin 1:=10; b:=Forml.ClientHeight-20;
127
h:=Form1. ClientHeight-40; w:=Forml.Width-40; xl:=0; x2:=25; dx:=0.01; yl:=f(xl); y2:=f(xl); x:=xl; Repeat y := f (x); if y < yl then yl:=y; if y > y2 then y2:=y; x:=x+dx; until (x >= x2); my:=h/abs(y2-yl); mx:=w/abs(x2-xl); x0:=l; yO:=b-Abs(Round(yl*my)); with forml.Canvas do Begin / / °si MoveTo(l,b);LineTo(l,b-h); MoveTo(x0,y0);LineTo(x0+w,y0); TextOut(l+5,b-h,FloatToStrF(y2,ffGeneral,6,3)); TextOut(l+5,b,FloatToStrF(yl,ffGeneral,6,3)); x:=xl; repeat y:=f(x); Pixels[xO+Round(x*mx),y0 - Round(y*my)]:=clRed; x:=x+dx; Until (x >= x2); end; end; procedure TForml.ButtonlClick(Sender: TObject); begin Buttonl.Visible:=false; GrOfFunc; end; end. Asosiy vazifani GrOfFunc protsedurasi bajaradi. Awal [xl,x2]
oraliqda funksiyaning maksimal (y2) va minimal (yl) qiymatlari
hisoblanadi. So‘ngra koordinatalar y ki bo‘yicha masshtab hisoblanadi.
Shundan so‘ng protsedura grafikni quradi.