Assalamualaikum...
full code :
unit Garis;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
editX1: TEdit;
editX2: TEdit;
Label3: TLabel;
Label4: TLabel;
editY1: TEdit;
editY2: TEdit;
ScrollBox1: TScrollBox;
Image1: TImage;
btnDDA: TButton;
btnBrese: TButton;
btnClear: TButton;
btnExit: TButton;
btnEllipse: TButton;
Label5: TLabel;
Label6: TLabel;
EditRx: TEdit;
EditRy: TEdit;
Label7: TLabel;
Label8: TLabel;
EditA: TEdit;
EditB: TEdit;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
EditWal: TEdit;
EditHir: TEdit;
Label12: TLabel;
procedure FormShow(Sender: TObject);
procedure btnClearClick(Sender: TObject);
procedure btnDDAClick(Sender: TObject);
procedure btnExitClick(Sender: TObject);
procedure btnBreseClick(Sender: TObject);
procedure rgbwarna;
procedure btnEllipseClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
x1,x2,y1,y2,i,j : integer;
x,y : double;
m,step,stepX,stepY : double;
dx,dy,p : integer;
red, green, blue, d : integer;
c, rx, ry : double;
sudwal, sudhir : double;
n, g : integer;
implementation
uses Math;
{$R *.dfm}
procedure TForm1.FormShow(Sender: TObject);
begin
Image1.Canvas.Pen.Color := clRed;
Image1.Canvas.Pen.Style := psDash;
Image1.Canvas.MoveTo(Image1.Width div 2, 0);
Image1.Canvas.LineTo(Image1.Width div 2,Image1.Height);
Image1.Canvas.MoveTo(0, Image1.Height div 2);
Image1.Canvas.LineTo(Image1.Width,Image1.Height div 2);
end;
procedure TForm1.btnClearClick(Sender: TObject);
begin
Image1.Canvas.Pen.Color := clWhite;
Image1.Canvas.Brush.Color := clWhite;
Image1.Canvas.Brush.Style := bsSolid;
Image1.Canvas.Pen.Style := psSolid;
Image1.Canvas.Rectangle(0,0,Image1.Width,Image1.Height);
FormShow(nil);
end;
procedure TForm1.btnDDAClick(Sender: TObject);
begin
x1 := StrToInt(editX1.Text);
x2 := StrToInt(editX2.Text);
y1 := StrToInt(editY1.Text);
y2 := StrToInt(editY2.Text);
dx := abs(x2-x1);
dy := abs(y2-y1);
//m := abs(dy / dx);
step := max(abs(dx),abs(dy));
stepX := (x2 - x1) / step;
stepY := (y2 - y1) / step;
x := x1;
y := y1;
j := round(step)-1;
red := 0;
green := 0;
blue := 0;
btnClearClick(sender);
Image1.Canvas.Pixels[(Image1.Width div 2 + round(x)),(Image1.Height div 2 - round(y))] := RGB(red,green,blue);
for i := 1 to j do
begin
x := x + stepX;
y := y + stepY;
rgbwarna();
Image1.Canvas.Pixels[(Image1.Width div 2 + round(x)),(Image1.Height div 2 - round(y))] := RGB(red,green,blue);
end;
end;
procedure TForm1.btnExitClick(Sender: TObject);
begin
close;
end;
procedure TForm1.btnBreseClick(Sender: TObject);
begin
x1 := StrToInt(editX1.Text);
x2 := StrToInt(editX2.Text);
y1 := StrToInt(editY1.Text);
y2 := StrToInt(editY2.Text);
//dx dan dy dibulatkan
dx := abs(x2-x1);
dy := abs(y2-y1);
m := abs(dy / dx);
step := max(abs(dx),abs(dy));
stepX := (x2 - x1) / dx;
stepY := (y2 - y1) / dy;
x := x1;
y := y1;
j := round(step)-1;
red := 0;
green := 0;
blue := 0;
if dx > dy then
begin
p := (2 * dy) - dx;
btnClearClick(sender);
//rgbwarna();
Image1.Canvas.Pixels[(Image1.Width div 2 + round(x)),(Image1.Height div 2 - round(y))] := RGB(red,green,blue);
for i := 1 to j do
begin
x := x + stepX;
if p > 0 then
begin
y := y + stepY;
p := p + ((2 * dy) - (2 * dx));
end
else
p := p + (2 * dy);
rgbwarna();
Image1.Canvas.Pixels[(Image1.Width div 2 + round(x)),(Image1.Height div 2 - round(y))] := RGB(red,green,blue);
end
end
else
begin
p := (2 * dx) - dy;
btnClearClick(sender);
//rgbwarna();
Image1.Canvas.Pixels[(Image1.Width div 2 + round(x)),(Image1.Height div 2 - round(y))] := RGB(red,green,blue);
for i := 1 to j do
begin
y := y + stepY;
if p > 0 then
begin
x := x + stepX;
p := p + ((2 * dx) - (2 * dy));
end
else
p := p + (2 * dx);
rgbwarna();
Image1.Canvas.Pixels[(Image1.Width div 2 + round(x)),(Image1.Height div 2 - round(y))] := RGB(red,green,blue);
end
end
end;
procedure TForm1.rgbwarna;
begin
red := red + 1;
green := green + 1;
blue := blue + 1;
end;
procedure TForm1.btnEllipseClick(Sender: TObject);
var
sud : double;
begin
n := StrToInt(EditA.Text);
g := StrToInt(EditB.Text);
sudwal := StrToFloat(EditWal.Text);
sudhir := StrToFloat(EditHir.Text);
rx := StrToFloat(EditRx.Text);
ry := StrToFloat(EditRy.Text);
red := 0;
green:= 0;
blue:= 0;
//ambil C sebagai pencacah dengan nilai R yang terbesar (Rx atau Ry)
if rx > ry then
c := 1 / rx
else
c := 1 / max(rx,ry);
//sudwal := 0;
sud := sudhir / 180 * pi;
btnClearClick(sender);
Image1.Canvas.Pixels[(Image1.Width div 2 + round(x)),(Image1.Height div 2 - round(y))] := RGB(red,green,blue);
(*while (sudwal <= sudhir) do
begin
x := n + (rx * cos(sud));
y := g + (ry * sin(sud));
Image1.Canvas.Pixels[(Image1.Width div 2 + round(x)),(Image1.Height div 2 - round(y))] := clGreen;
sudwal := round(sudwal + c);
end; *)
end;
end.
Sabtu, 14 Mei 2016
Langganan:
Posting Komentar (Atom)
0 komentar:
Posting Komentar