BRESENHAM algorithm

xiaoxiao2021-03-06  40

{***********************************************} {Bresenham, the line paint} { Designed by Whco, Copyright (C) 2003-2004} {Get in touch with me .tel: 07102690635} {email: WanghongBottt123@163.com} {************************** **********************} Unit unitline;

Interface

Uses Windows, Messages, Sysutils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls, ExtCtrls

type Tlinefrm = class (TForm) Button1: TButton; input1: TEdit; input3: TEdit; StaticText1: TStaticText; StaticText2: TStaticText; input2: TEdit; input4: TEdit; Button2: TButton; procedure Button1Click (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); procedure FormShow (Sender: Tobject); Procedure Button2Click (Sender: TOBJECT); private {private declarations} end;

Var linefrm: tLINEFRM;

IMPLEMENTATION

Uses UnitsHow;

{$ R * .dfm} Procedure TLINEFRM.BUTTON1CLICK (Sender: TOBJECT); VARX0, Y0, X1, Y1, X, Y, I, DX, DY, E: Integer; // X0, Y0 is the starting point, X1, Y1 It is the end point, x, y is used. Begin showfrm.visible: = true; showfrm.show; if (input1.text <> ') and (input2.text <>') and (input3.text <> ') and (input4.text <> " ') The begin x1: = start (Input3.Text); Y1: = STRTOINT (INPUT4.TEXT); X0: = STRTOINT (INPUT1.TEXT); Y0: = STRTOINT (INPUT2.TEXT); DX: = X1-X0 DY: = Y1-Y0; E: = - DX; x: = x0; y: = y0; for i: = 0 to Dy do begin showfrm.canvas.pixels [x, y]: = CLRED; x: = X 1; E: = E 2 * DY; if (e> = 0) THEN BEGIN Y: = Y 1; E: = E-2 * Dx; End; End; End; IF (Input1.Text = '') or ') or (Input3.Text =' ') or (INPUT4.TEXT =' ') THEN BEGIN SHOWMESSAGE (' No Data Enter '); showfrm.visible: = false; end; procedure Tlinefrm.input1KeyPress (Sender: TObject; var Key: Char); beginif key = # 13 theninput2.SetFocus; end; procedure Tlinefrm.input2KeyPress (Sender: TObject; var Key: Char); beginif key = # 13 theninput3. 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;

Procedure TLINEFRM.FORMSHOW (Sender: TOBJECT); BeginInput1.Setfocus; showfrm.visible: = FALSE; END;

Procedure TLINEFRM.BUTTON2CLICK (Sender: Tobject); Var i: integer; begin for i: = 0 to ComponentCount-1 Do Begin if Components [i] IS TEDIT THEN TEDIT (Components [i]). Text: = '; END .

转载请注明原文地址:https://www.9cbs.com/read-75594.html

New Post(0)