{*****************************************} {The following is a point-by-point Become a straight algorithm,} {If there is a suggestion or opinion, please contact me .qq: 287179523} {email: wagnhongbottt123@163.com} {COPY Right (c) 2003-2004 reserved.} {****** ******************************************} Unit Uniteline;
Interface
Uses Windows, Messages, Sysutils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls, ExtCtrls
type Tlinefrm = class (TForm) StaticText1: TStaticText; StaticText2: TStaticText; input1: TEdit; input2: TEdit; input3: TEdit; input4: TEdit; Button1: TButton; GroupBox1: TGroupBox; Image1: TImage; procedure Button1Click (Sender: TObject) ; procedure FormCreate (Sender: TObject); procedure input1KeyPress (Sender: TObject; var Key: Char); procedure input2KeyPress (Sender: TObject; var Key: Char); procedure input3KeyPress (Sender: TObject; var Key: Char); procedure input4KeyPress (Sender: TOBJECT; VAR Key: char); private {private declarations}
Var linefrm: tLINEFRM;
IMPLEMENTATION
{$ R * .dfm}
Procedure TLINEFRM.BUTTON1CLICK (Sender: Tobject); // Description, my first point (X0 1, Y0); and in the first quadrant VAR i, J, X0, Y0, XE, Ye, X, Y , N, N1, N2: INTEGER; F: Array [1..1024] of integer; begin linefrm.groupbox1.visible: = true; linefrm.groupbox1.align: = alclient; j: = 1; x0: = start ( INPUT1.TEXT); Y0: = STRTOINT (INPUT2.TEXT); XE: = STRTOINT (INPUT3.TEXT); YE: = STRTOINT (INPUT4.TEXT); x: = x0 1; Y: = Y0; N1: = XE-X0; N2: = ye-y0; // fm: = ym * xa-ya * xm => f1: = - Y1 Point (1,0) f [1]: = 0-ye; N: = N1 N2; for i: = 0 to n-1 do begin linefrm.image1.canvas.pixels [x, y]: = CLRED; if f [j] <0 dam y: = y 1; J: = J 1; F [J 1]: = F [J] XE; ELSE IF F [J]> = 0 THEN BEGIN J: = J 1; F [J 1]: = F [J] - Ye; x: = x 1; end; end; end; procedure tLineFrm.form, begin linefrm.left: = 0; linefrm.top:=0; linefrm.width: = 600; linefrm.height : = 450nd;
Procedure TLINEFRM.INPUT1KEYPRESS (Sender: Tobject; var key: char); beginif ord (key) = 13 kilnput2.setfocus;
Procedure TLINEFRM.INPUT2KEYPRESS (Sender: Tobject; var key: char); beginif key = # 13 kilnput3.setfocus;
Procedure TLINEFRM.INPUT3KEYPRESS (Sender: Tobject; Var Key: char); beginif key = # 13input4.setfocus;
Procedure TLINEFRM.INPUT4KEYPRESS (Sender: Tobject; Var Key: char); beginif key = # 13 thenbutton1.setfocus;
End.