GRAFIKA KOMPUTER
Grafika Komputer
adalah bagian ilmu komputer yang memperlajari tentang proses pembuatan dan
manipulasi Gambar Visual secara Digital. Pada kesempatan ini adalah Latihan
dasar dalam pembuataan 7 Transformasi Grafika Komputer.
Tranformasi Pada Grafika Komputer
Langsung Pratekkan di Aplikasi Delphi 7 teman2 ya....
Selamat Belajar. Mudah-mudahan membantu.
public
{ Public declarations }
procedure reset_layar;
procedure Tampilkan_objek;
procedure tampilkan_warna(var Image:timage;
warna:colorref);
procedure grafik_layar;
procedure Translasi;
procedure Scala;
end;
type
Twarna = record
line : colorref;
surface : colorref;
end;
var
Form1: TForm1;
p0 : tpoint;
p1 : tpoint;
p2 : tpoint;
cek : boolean;
warna : twarna;
geser : boolean;
implementation
{$R *.dfm}
procedure
tform1.tampilkan_warna(var Image:timage; warna:colorref);
begin
image.Canvas.Create;
image.Canvas.Brush.Color := warna;
image.Canvas.Rectangle(0,0,image.Width,image.Height);
end;
procedure
tform1.reset_layar;
begin
image1.Width := 400;
image1.Height := 400;
image1.Canvas.Create;
image1.Canvas.Brush.Color := clwhite;
image1.Canvas.Pen.Color := clwhite;
image1.Canvas.Rectangle(0,0,image1.Width,image1.Height);
end;
procedure
tform1.grafik_layar;
begin
image1.Canvas.Pen.Color := clblack;
image1.Canvas.Brush.Color := clwhite;
image1.Canvas.MoveTo(0,200);
image1.Canvas.LineTo(400,200);
image1.Canvas.MoveTo(200,0);
image1.Canvas.LineTo(200,400);
image1.Canvas.TextOut(190,205,'0');
image1.Canvas.TextOut(190,5,'y');
image1.Canvas.TextOut(190,380,'-y');
image1.Canvas.TextOut(5,205,'-x');
image1.Canvas.TextOut(380,205,'x');
end;
procedure
tform1.Tampilkan_objek;
begin
if cek = true then
begin
image1.Canvas.Pen.Color := warna.line;
image1.Canvas.Brush.Color := warna.surface;
image1.Canvas.Rectangle(p1.X,p1.Y,p2.X,p2.Y);
end;
end;
procedure
TForm1.FormCreate(Sender: TObject);
begin
reset_layar;
grafik_layar;
cek
:= false;
geser := false;
warna.line := 0;
warna.surface := 255;
tampilkan_warna(image2,warna.line);
tampilkan_warna(image3,warna.surface);
end;
procedure
TForm1.Button1Click(Sender: TObject);
begin
if colordialog1.Execute = true then
begin
warna.line := colordialog1.Color;
tampilkan_warna(image2,warna.line);
end;
end;
procedure
TForm1.Button2Click(Sender: TObject);
begin
if colordialog1.Execute = true then
begin
warna.surface := colordialog1.Color;
tampilkan_warna(image3,warna.surface);
end;
end;
procedure
TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
p1.X := x;
p1.Y := y;
p2.X := x;
p2.Y := y;
geser := true;
cek := true;
reset_layar;
tampilkan_objek;
grafik_layar;
end;
procedure
TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if geser = true then
begin
p2.X := x;
p2.Y := y;
reset_layar;
tampilkan_objek;
grafik_layar;
end;
end;
procedure
TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
geser:= false;
end;
procedure
tform1.Translasi;
var px,py : integer;
begin
if (length(edit1.Text)>0) and
(length(edit2.Text)>0)
then
begin
px := strtoint(edit1.Text);
py := strtoint(edit2.Text);
p1.X := ((p1.X - 200) + px) + 200;
p2.X := ((p2.X - 200) + px) + 200;
p1.y := ((p1.y - 200) + py) + 200;
p2.y := ((p2.y - 200) + py) + 200;
end;
end;
procedure
TForm1.Button3Click(Sender: TObject);
begin
Translasi;
reset_layar;
tampilkan_objek;
grafik_layar;
end;
procedure tform1.Scala;
var px,py : integer;
begin
if (length(edit1.Text)>0) and
(length(edit2.Text)>0)
then
begin
px := strtoint(edit1.Text);
py := strtoint(edit2.Text);
p1.X := ((p1.X - 200) * px) + 200;
p2.X := ((p2.X - 200) * px) + 200;
p1.y := ((p1.y - 200) * py) + 200;
p2.y := ((p2.y - 200) * py) + 200;
end;
end;
procedure
TForm1.Button4Click(Sender: TObject);
begin
Scala;
reset_layar;
tampilkan_objek;
grafik_layar;
end;
procedure
TForm1.Button5Click(Sender: TObject);
begin
cek := false;
reset_layar;
tampilkan_objek;
grafik_layar;
end;
end.
0 komentar: