只要算法正确,用画布 Canvas.Pixels[x,y] := tcolor;画
很好的.
比如sin
var
x,l: Integer;
y,a: Double;
begin
Image1.Picture.Bitmap := TBitmap.Create;
Image1.Picture.Bitmap.Width := Image1.Width;
Image1.Picture.Bitmap.Height := Image1.Height; {These three lines could
go in Form1.Create instead}
l := Image1.Picture.Bitmap.Width;
for x := 0 to l do
begin
a := (x/l) * 2 * Pi; {Convert position on X to angle between 0 & 2Pi}
y := Sin(a); {Your function would go here}
y := y * (Image1.Picture.Bitmap.Height / 2); {Scale Y so it fits}
y := y * -1; {Invert Y, the screen top is 0 !}
y := y + (Image1.Picture.Bitmap.Height / 2); {Add offset for middle 0}
Image1.Picture.Bitmap.Canvas.Pixels[Trunc(x), Trunc
] := clBlack;
end;
end;
A:
I've found the best way is to draw directly onto the canvas. Preferably in a
separate procedure taking a TCanvas and a TRect as parameters. That way you
can pass your window's canvas and client rect as parameters for drawing on
screen and the printer's canvas and a rect comprising of the area where
you wan't it to be positioned to print. Look at the canvasses methods to
get the available drawing routines.
A:
You could use a TCanvas object to draw the function yourself.
A TImage component would be good to use, as it's bitmap contains
a canvas that you can draw on.
eg: (Create a new form, add an Image and a Button. Attach this code
to the button)
var
x,l: Integer;
y,a: Double;
begin
Image1.Picture.Bitmap := TBitmap.Create;
Image1.Picture.Bitmap.Width := Image1.Width;
Image1.Picture.Bitmap.Height := Image1.Height; {These three lines could
go in Form1.Create instead}
l := Image1.Picture.Bitmap.Width;
for x := 0 to l do
begin
a := (x/l) * 2 * Pi; {Convert position on X to angle between 0 & 2Pi}
y := Sin(a); {Your function would go here}
y := y * (Image1.Picture.Bitmap.Height / 2); {Scale Y so it fits}
y := y * -1; {Invert Y, the screen top is 0 !}
y := y + (Image1.Picture.Bitmap.Height / 2); {Add offset for middle 0}
Image1.Picture.Bitmap.Canvas.Pixels[Trunc(x), Trunc
] := clBlack;
end;
end;