Transformasi (Translasi dan Scalling) pada Delphi

Sebelumnya kita telah belajar mengenai membuat objek dengan paintbox, bisa dibaca disini atau disini.

Dan sekarang kita akan belajar bagaimana menggerakkan dan merubah ukuran objek tersebut.
Ini dinamakan dengan proses TRANSLASI atau TRANSFORMASI.
Sebetulnya gak jelas juga sih apa namanya, tapi itu yang paling keren menurut penulis :))

Okeh, awalnya buat form[Video] Transfer Data antar Form di Delphi. Read more ... » seperti ini:

  • PaintBox1
  • Button1 : Tombol Proses
  • Button2 : Tombol Hapus
  • Button3 : Tombol Tutup
  • Label1 : Translasi
  • Label2: Scalling
  • Edit1 : dibawah Label1
  • Edit2 : dibawah Label2

Dan buat seperti gambar dibawah ini:

form awal

form awal

Masuk ke bagian coding..

Dobel klik pada tombol PROSES, dan tulis kodeMembuat Kode Acak dengan PHP. Read more ... »..

  with paintbox1.canvas do
  begin
  paintbox1.Refresh;
  // input
  x1 := 150; x2 := 175; x3 := 225; x4 := 200; x5 := 225;
  x6 := 150; x7 := 75;  x8 := 100; x9 := 75;  x10:= 125;

  y1 := 50;  y2 := 100; y3 := 100; y4 := 150; y5 := 200;
  y6 := 150; y7 := 200; y8 := 150; y9 := 100; y10:= 100;

  brush.Color := clLime;
  polygon([point(x1,y1), point(x2,y2), point(x3,y3), point(x4,y4), point(x5,y5),
           point(x6,y6), point(x7,y7), point(x8,y8), point(x9,y9), point(x10,y10)]);
  end;

Dobel klik pada tombol HAPUS, dan tulis kode..

  paintbox1.Repaint;

Dobel klik pada tombol TUTUP, dan tulis kode..

  close;

Dobel klik pada Edit1 (dibawah translasi), dan tulis kode..

  with paintbox1.Canvas do
  begin
    paintbox1.Refresh;
    xx := StrToInt(Edit1.Text);
    xx1 := x1 + xx;
    xx2 := x2 + xx;
    xx3 := x3 + xx;
    xx4 := x4 + xx;
    xx5 := x5 + xx;
    xx6 := x6 + xx;
    xx7 := x7 + xx;
    xx8 := x8 + xx;
    xx9 := x9 + xx;
    xx10 := x10 + xx;

  brush.Color := clRed;
  polygon([point(xx1,y1), point(xx2,y2), point(xx3,y3), point(xx4,y4), point(xx5,y5),
           point(xx6,y6), point(xx7,y7), point(xx8,y8), point(xx9,y9), point(xx10,y10)]);
  end;

Dobel klik pada Edit2 (dibawah scalling), dan tulis kode..

  with paintbox1.Canvas do
  begin
    paintbox1.Refresh;
    yy := StrToInt(Edit2.Text);
    yy1 := x1 * yy;
    yy2 := x2 * yy;
    yy3 := x3 * yy;
    yy4 := x4 * yy;
    yy5 := x5 * yy;
    yy6 := x6 * yy;
    yy7 := x7 * yy;
    yy8 := x8 * yy;
    yy9 := x9 * yy;
    yy10 := x10 * yy;
    z1 := y1 * yy;
    z2 := y2 * yy;
    z3 := y3 * yy;
    z4 := y4 * yy;
    z5 := y5 * yy;
    z6 := y6 * yy;
    z7 := y7 * yy;
    z8 := y8 * yy;
    z9 := y9 * yy;
    z10 := y10 * yy;

  brush.Color := clYellow;
  polygon([point(yy1,z1), point(yy2,z2), point(yy3,z3), point(yy4,z4), point(yy5,z5),
           point(yy6,z6), point(yy7,z7), point(yy8,z8), point(yy9,z9), point(yy10,z10)]);
  end;

setelah barisan kode..

implementation

{$R *.dfm}

tambahkan..

var
  // ini untuk translasi
  x1,x2,x3,x4,x5,x6,x7,x8,x9,x10 : integer;
  xx, xx1,xx2,xx3,xx4,xx5,xx6,xx7,xx8,xx9,xx10 : integer;

  // ini untuk scalling
  y1,y2,y3,y4,y5,y6,y7,y8,y9,y10 : integer;
  z1,z2,z3,z4,z5,z6,z7,z8,z9,z10 : integer;  // Y
  yy, yy1,yy2,yy3,yy4,yy5,yy6,yy7,yy8,yy9,yy10 : integer; // X

Kalau source codeJavaScript: Konversi Angka ke Huruf. Read more ... » lengkapnya, seperti ini:

unit bintang;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    PaintBox1: TPaintBox;
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Button2: TButton;
    Button3: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure Edit2Change(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

var
  // ini untuk translasi
  x1,x2,x3,x4,x5,x6,x7,x8,x9,x10 : integer;
  xx, xx1,xx2,xx3,xx4,xx5,xx6,xx7,xx8,xx9,xx10 : integer;

  // ini untuk scalling
  y1,y2,y3,y4,y5,y6,y7,y8,y9,y10 : integer;
  z1,z2,z3,z4,z5,z6,z7,z8,z9,z10 : integer;  // Y
  yy, yy1,yy2,yy3,yy4,yy5,yy6,yy7,yy8,yy9,yy10 : integer; // X

{
  REZA NURFACHMI
  KAMIS PAGI
  TUGAS 11
}

procedure TForm1.Button1Click(Sender: TObject);
begin
  with paintbox1.canvas do
  begin
  paintbox1.Refresh;
  // input
  x1 := 150; x2 := 175; x3 := 225; x4 := 200; x5 := 225;
  x6 := 150; x7 := 75;  x8 := 100; x9 := 75;  x10:= 125;

  y1 := 50;  y2 := 100; y3 := 100; y4 := 150; y5 := 200;
  y6 := 150; y7 := 200; y8 := 150; y9 := 100; y10:= 100;

  brush.Color := clLime;
  polygon([point(x1,y1), point(x2,y2), point(x3,y3), point(x4,y4), point(x5,y5),
           point(x6,y6), point(x7,y7), point(x8,y8), point(x9,y9), point(x10,y10)]);
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  paintbox1.Repaint;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  close;
end;

procedure TForm1.Edit1Change(Sender: TObject);
begin
  with paintbox1.Canvas do
  begin
    paintbox1.Refresh;
    xx := StrToInt(Edit1.Text);
    xx1 := x1 + xx;
    xx2 := x2 + xx;
    xx3 := x3 + xx;
    xx4 := x4 + xx;
    xx5 := x5 + xx;
    xx6 := x6 + xx;
    xx7 := x7 + xx;
    xx8 := x8 + xx;
    xx9 := x9 + xx;
    xx10 := x10 + xx;

  brush.Color := clRed;
  polygon([point(xx1,y1), point(xx2,y2), point(xx3,y3), point(xx4,y4), point(xx5,y5),
           point(xx6,y6), point(xx7,y7), point(xx8,y8), point(xx9,y9), point(xx10,y10)]);
  end;
end;

procedure TForm1.Edit2Change(Sender: TObject);
begin
  with paintbox1.Canvas do
  begin
    paintbox1.Refresh;
    yy := StrToInt(Edit2.Text);
    yy1 := x1 * yy;
    yy2 := x2 * yy;
    yy3 := x3 * yy;
    yy4 := x4 * yy;
    yy5 := x5 * yy;
    yy6 := x6 * yy;
    yy7 := x7 * yy;
    yy8 := x8 * yy;
    yy9 := x9 * yy;
    yy10 := x10 * yy;
    z1 := y1 * yy;
    z2 := y2 * yy;
    z3 := y3 * yy;
    z4 := y4 * yy;
    z5 := y5 * yy;
    z6 := y6 * yy;
    z7 := y7 * yy;
    z8 := y8 * yy;
    z9 := y9 * yy;
    z10 := y10 * yy;

  brush.Color := clYellow;
  polygon([point(yy1,z1), point(yy2,z2), point(yy3,z3), point(yy4,z4), point(yy5,z5),
           point(yy6,z6), point(yy7,z7), point(yy8,z8), point(yy9,z9), point(yy10,z10)]);
  end;
end;

end.

Bagaimana hasilnya? Coba dong dijalankan sendiri programnya ;)

Popular Keywords

Aa

Masih seorang pelajar yang belum bosan menuntut ilmu. Ilmu tentang pemrograman, networking, website, anime dan lain sebagainya. Yuk kenalan.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Baca juga artikel iniclose