lap grafika

Post on 18-Nov-2014

142 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

LAPORAN GRAFIKA KOMPUTER

“APLIKASI MENGGUNAKAN BORLAN C++ BUILDER”

Disusun oleh :

1. WAHYU NURHIDAYAT 123070015

2. DHODI YUDHA PRADANA 123070055

3. PUTRA TEGUH P 123070043

4. YANUAR 123070045

5. GAUTAMA MAHARDIKA 123080088

Dosen :

Herry Sofyan, S.T., M.T.

JURUSAN TEKNIK INFORMATIKA

FAKULTAS TEKNOLOGI INDUSTRI

UNIVERSITAS PEMBANGUNAN NASIONAL “VETERAN”

YOGYAKARTA

2009

BAB I

PENDAHULUAN

1. Latar Belakang

Grafika computer (computer graphics) adalah seperangkat alat yang terdiri

dari hardware dan software yang digunakan untuk membuat desain, grafik

presentasi, computer art, pendidikan , hiburan, visualisasi, pengolahan citra dan

GUI. Grafika computer salah satu mata kuliah yang menyenangkan untuk

dipelajari dari bidang ilmu computer karena untuk dapat memahaminya dan dapat

mengimplementasikannya dengan baik diperlukan kemampuan matematik,

keahlian untuk memprogram dan kreativitas. Dengan menggunakan aplikasi ini

banyak variasi yang dapat dihasilkan. Untuk menghasilkan gambar dan variasi

sesuai dengan yang diinginkan, dalam aplikasi ini diterapakan beberapa konsep

premrograman grafika computer dengan perhitungan matematika

2. Rumusan Masalah

Bagaimana membuat aplikasi grafika yang dapat digunakan untuk melakukan

pemrosesan pembuatan objek, pewarnaan, zooming, translasi / perpindahan objek,

rotasi dan pencerminan.

3. Batasan Masalah

Objek yang dibuat diantaranya segitiga, lingkaran, persegi,segilima, dan

elips

Apliksi ini dapat melakukan pewarnaan, rotasi, pencerminan, zooming

dan translasi/perpindahan.

4. Manfaat

Aplikasi ini memiliki beberapa variasi diantaranya pembuatan objek,

pewarnaan, zooming , translasi / perpindahan objek, rotasi dan pencerminan, yang

seluruhnya diimplementasikan dari konsep-konsep perhitungan matematika dalam

pembuatan algoritma pemrogramannya dan dengan dibuatnya aplikasi ini proses

belajar semakin jelas dan lebih mudah untuk dipahami.

5. Tujuan

Memberikan variasi dalam pembuatan objek .

Untuk memenuhi tugas mata kuliah grafika computer.

Membuat aplikasi yang menerapkan konsep-konsep perhitungan matematika

dalam pembuatan algoritma programannya

BAB II

DASAR TEORI

A. Grafika Komputer

Grafika computer (computer graphics) adalah seperangkat alat yang terdiri dari

hardware dan software yang digunakan untuk membuat desain, grafik presentasi, computer

art, pendidikan , hiburan, visualisasi, pengolahan citra dan GUI. Grafika dapat dijumpai

dalam berbagai aplikasi seperti design,grafik persentasi,pendidikan,hiburan dan juga

pengolahan citra.

B. C++ Builder

C++ Builder merupakan salah satu bahasa pemograman yang dapat membuat

aplikasi-aplikasi yang berbasis muldimedia atau visual.dengan C++ builder pembuatan

aplikasi akan bejalan lebih mudah,ini dikarenakan dalam aplikasi ini kita dapat langsung

menambahkan buton-buton atau tampilan gambarnya. Hal ini memudahkan dalam

membuat aplikasi yang berbasis grafis.

BAB III

PERANCANGAN

A. Source Code Form Activated

void __fastcall TForm1::FormActivate(TObject *Sender){ Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height);}

B. Source Code Form Show

void __fastcall TForm1::FormShow(TObject *Sender){ if(bangun=="kotak"){ int i; Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height); Image1->Canvas->MoveTo(el[1].x,el[1].y); for(i=1; i<=4; i++){ Image1->Canvas->LineTo(el[i].x,el[i].y); } Image1->Canvas->LineTo(el[1].x,el[1].y); if(ComboBox1->ItemIndex == 0 ){ BoundaryFill(el[5].x,el[5].y,clRed,clBlack); } if(ComboBox1->ItemIndex == 1 ){ BoundaryFill(el[5].x,el[5].y,clWhite,clBlack); } if(ComboBox1->ItemIndex == 2 ){ BoundaryFill(el[5].x,el[5].y,clYellow,clBlack); } if(ComboBox1->ItemIndex == 3 ){ BoundaryFill(el[5].x,el[5].y,clGreen,clBlack); } if(ComboBox1->ItemIndex == 4 ){ BoundaryFill(el[5].x,el[5].y,clBlue,clBlack); } } if(bangun=="segilima"){ int i; Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height); Image1->Canvas->MoveTo(el[1].x,el[1].y); for(i=1; i<=5; i++){ Image1->Canvas->LineTo(el[i].x,el[i].y); } Image1->Canvas->LineTo(el[1].x,el[1].y); if(ComboBox1->ItemIndex == 0 ){ BoundaryFill(el[6].x,el[6].y,clRed,clBlack); } if(ComboBox1->ItemIndex == 1 ){ BoundaryFill(el[6].x,el[6].y,clWhite,clBlack); } if(ComboBox1->ItemIndex == 2 ){ BoundaryFill(el[6].x,el[6].y,clYellow,clBlack);

} if(ComboBox1->ItemIndex == 3 ){ BoundaryFill(el[6].x,el[6].y,clGreen,clBlack); } if(ComboBox1->ItemIndex == 4 ){ BoundaryFill(el[6].x,el[6].y,clBlue,clBlack); } } if(bangun=="segitiga"){ int i; Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height); Image1->Canvas->MoveTo(el[1].x,el[1].y); for(i=1; i<=3; i++){ Image1->Canvas->LineTo(el[i].x,el[i].y); } Image1->Canvas->LineTo(el[1].x,el[1].y); if(ComboBox1->ItemIndex == 0 ){ BoundaryFill(el[4].x,el[4].y,clRed,clBlack); } if(ComboBox1->ItemIndex == 1 ){ BoundaryFill(el[4].x,el[4].y,clWhite,clBlack); } if(ComboBox1->ItemIndex == 2 ){ BoundaryFill(el[4].x,el[4].y,clYellow,clBlack); } if(ComboBox1->ItemIndex == 3 ){ BoundaryFill(el[4].x,el[4].y,clGreen,clBlack); } if(ComboBox1->ItemIndex == 4 ){ BoundaryFill(el[4].x,el[4].y,clBlue,clBlack); } } if(bangun=="bersih"){ Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height); }}

C. Source Code Image Mouse Down

void __fastcall TForm1::Image1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y){ if(ComboBox1->ItemIndex == 0 ){ BoundaryFill(X,Y,clRed,clBlack); } if(ComboBox1->ItemIndex == 1 ){ BoundaryFill(X,Y,clWhite,clBlack); } if(ComboBox1->ItemIndex == 2 ){ BoundaryFill(X,Y,clYellow,clBlack); } if(ComboBox1->ItemIndex == 3 ){ BoundaryFill(X,Y,clGreen,clBlack); } if(ComboBox1->ItemIndex == 4 ){ BoundaryFill(X,Y,clBlue,clBlack); }}

D. Source Code Button New

void __fastcall TForm1::BitBtn4Click(TObject *Sender){ Image1->Canvas->Pen->Width = 0; bangun="bersih"; FormShow(Sender);}

E. Source Code Button Lingkaran

void __fastcall TForm1::BitBtn1Click(TObject *Sender){ a =((Image1->Width)/2); b =((Image1->Height)/2); c = 30; Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height); CircleMidPoint(a,b,c); bangun="lingkaran";}

void __fastcall TForm1::CircleMidPoint(int XC, int YC, int R){ int x, y, p, k=0; x=0; y=R; p=1-R; do { k++; if(p<0) { x=x+1; } else { x=x+1; y=y-1; } if(p<0) { p=p+2*x+1; } else { p=p+2*(x-y)+1; } CirclePlotPoint(XC, YC, x, y); } while(x<y); Image1->Canvas->Pixels[XC][YC+R]=clBlack; Image1->Canvas->Pixels[XC-R][YC]=clBlack; Image1->Canvas->Pixels[XC+R][YC]=clBlack; Image1->Canvas->Pixels[XC][YC-R]=clBlack; c=R;}

void __fastcall TForm1::CirclePlotPoint(int XC, int YC, int X, int Y){ Image1->Canvas->Pixels[XC+X][YC+Y]=clBlack; Image1->Canvas->Pixels[XC-X][YC+Y]=clBlack; Image1->Canvas->Pixels[XC+X][YC-Y]=clBlack; Image1->Canvas->Pixels[XC-X][YC-Y]=clBlack; Image1->Canvas->Pixels[XC+Y][YC+X]=clBlack;

Image1->Canvas->Pixels[XC-Y][YC+X]=clBlack; Image1->Canvas->Pixels[XC+Y][YC-X]=clBlack; Image1->Canvas->Pixels[XC-Y][YC-X]=clBlack;

a=XC;b=YC;}

F. Source Code Button Kotak

void __fastcall TForm1::BitBtn2Click(TObject *Sender){ el[1].x=((Image1->Width)/2)-20; el[1].y=((Image1->Height)/2)-20; el[2].x=((Image1->Width)/2)+20; el[2].y=((Image1->Height)/2)-20; el[3].x=((Image1->Width)/2)+20; el[3].y=((Image1->Height)/2)+20; el[4].x=((Image1->Width)/2)-20; el[4].y=((Image1->Height)/2)+20; el[5].x=((el[1].x+el[2].x+el[3].x+el[4].x)/4); el[5].y=((el[1].y+el[2].y+el[3].y+el[4].y)/4); bangun="kotak"; FormShow(Sender);}

G. Source Code Button Segitiga

void __fastcall TForm1::BitBtn3Click(TObject *Sender){ el[1].x=((Image1->Width)/2); el[1].y=((Image1->Height)/2)-20; el[2].x=((Image1->Width)/2)+20; el[2].y=((Image1->Height)/2)+20; el[3].x=((Image1->Width)/2)-20; el[3].y=((Image1->Height)/2)+20; el[4].x=((el[1].x+el[2].x+el[3].x)/3); el[4].y=((el[1].y+el[2].y+el[3].y)/3); bangun="segitiga"; FormShow(Sender);}

H. Source Code Button Segilima

void __fastcall TForm1::BitBtn14Click(TObject *Sender){ el[1].x=((Image1->Width)/2)-20; el[1].y=((Image1->Height)/2)-20; el[2].x=((Image1->Width)/2)+20; el[2].y=((Image1->Height)/2)-20; el[3].x=((Image1->Width)/2)+20; el[3].y=((Image1->Height)/2)+20; el[4].x=((Image1->Width)/2); el[4].y=((Image1->Height)/2)+40; el[5].x=((Image1->Width)/2)-20; el[5].y=((Image1->Height)/2)+20; el[6].x=((el[1].x+el[2].x+el[3].x+el[4].x+el[5].x)/5); el[6].y=((el[1].y+el[2].y+el[3].y+el[4].y+el[5].y)/5); bangun="segilima"; FormShow(Sender);}

I. Source Code Button Ellips

void __fastcall TForm1::BitBtn20Click(TObject *Sender){ a =((Image1->Width)/2); b =((Image1->Height)/2); c = 25; d = 40;

Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height); EllipsMidPoint(a,b,c,d); bangun="ellips";}

void __fastcall TForm1::EllipsMidPoint(int xc,int yc, int rx, int ry){ int p=0;int k=0; int Rx2=rx*rx; int Ry2=ry*ry; int TwoRx2=2*Rx2; int TwoRy2=2*Ry2; int x=0; int y=ry; int px=0; int py=TwoRx2*y; do { if((2*ry*ry*x)<(2*rx*rx*y)) { p=abs(Ry2-(Rx2*ry)+(0.25*Rx2)); ellipsPlotPoint(float(xc),float(yc), x, y); while(px<py){ x++; k++; px=px+TwoRy2; if(p<0) p += Ry2 + px; else { y--; py -=TwoRx2; p += Ry2+px-py; } ellipsPlotPoint(float(xc),float(yc), x, y); }} p=abs(Ry2*(x+0.5)*(x+0.5)+Rx2*(y-1)*(y-1)-Rx2*Ry2); while(y>0) { y--; py =py-TwoRx2; if(p>0) p += Rx2 - py; else { x++; k++; px +=TwoRy2; p += Ry2+px-py; } ellipsPlotPoint(float(xc),float(yc), x, y); }} while(x<y);}

void __fastcall TForm1::ellipsPlotPoint(int xc, int yc, int x, int y){ Image1->Canvas->Pixels[xc+x][yc+y]=clBlack; Image1->Canvas->Pixels[xc-x][yc+y]=clBlack; Image1->Canvas->Pixels[xc+x][yc-y]=clBlack; Image1->Canvas->Pixels[xc-x][yc-y]=clBlack;}

J. Source Code Button Translasi ke Kiri Atas

void __fastcall TForm1::BitBtn5Click(TObject *Sender){ int k = StrToInt(Edit1->Text); if(bangun=="kotak"){ el[1].x=el[1].x-k; el[1].y=el[1].y-k; el[2].x=el[2].x-k; el[2].y=el[2].y-k; el[3].x=el[3].x-k; el[3].y=el[3].y-k; el[4].x=el[4].x-k; el[4].y=el[4].y-k; el[5].x=el[5].x-k; el[5].y=el[5].y-k; bangun="kotak"; FormShow(Sender); } if(bangun=="segitiga"){ el[1].x=el[1].x-k; el[1].y=el[1].y-k; el[2].x=el[2].x-k; el[2].y=el[2].y-k; el[3].x=el[3].x-k; el[3].y=el[3].y-k; el[4].x=el[4].x-k; el[4].y=el[4].y-k; bangun="segitiga"; FormShow(Sender); } if(bangun=="lingkaran"){ Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height); CircleMidPoint(a-k,b-k,c); bangun="lingkaran"; } if(bangun=="segilima"){ el[1].x=el[1].x-k; el[1].y=el[1].y-k; el[2].x=el[2].x-k; el[2].y=el[2].y-k; el[3].x=el[3].x-k; el[3].y=el[3].y-k; el[4].x=el[4].x-k; el[4].y=el[4].y-k; el[5].x=el[5].x-k; el[5].y=el[5].y-k; el[6].x=el[6].x-k; el[6].y=el[6].y-k; bangun="segilima"; FormShow(Sender); } if(bangun=="ellips"){ Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height); EllipsMidPoint(a-k,b-k,c,d); bangun="ellips"; }}

K. Source Code Button Translasi ke Atas

void __fastcall TForm1::BitBtn6Click(TObject *Sender){ int k = StrToInt(Edit1->Text); if(bangun=="kotak"){ el[1].y=el[1].y-k; el[2].y=el[2].y-k; el[3].y=el[3].y-k; el[4].y=el[4].y-k; el[5].y=el[5].y-k; bangun="kotak"; FormShow(Sender);

} if(bangun=="segitiga"){ el[1].y=el[1].y-k; el[2].y=el[2].y-k; el[3].y=el[3].y-k; el[4].y=el[4].y-k; bangun="segitiga"; FormShow(Sender); } if(bangun=="lingkaran"){ Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height); CircleMidPoint(a,b-k,c); bangun="lingkaran"; } if(bangun=="segilima"){ el[1].y=el[1].y-k; el[2].y=el[2].y-k; el[3].y=el[3].y-k; el[4].y=el[4].y-k; el[5].y=el[5].y-k; el[6].y=el[6].y-k; bangun="segilima"; FormShow(Sender); } if(bangun=="ellips"){ Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height); EllipsMidPoint(a,b-k,c,d); bangun="ellips"; }}

L. Source Code Button Translasi ke Kanan Atas

void __fastcall TForm1::BitBtn7Click(TObject *Sender){ int k = StrToInt(Edit1->Text); if(bangun=="kotak"){ el[1].x=el[1].x+k; el[1].y=el[1].y-k; el[2].x=el[2].x+k; el[2].y=el[2].y-k; el[3].x=el[3].x+k; el[3].y=el[3].y-k; el[4].x=el[4].x+k; el[4].y=el[4].y-k; el[5].x=el[5].x+k; el[5].y=el[5].y-k; bangun="kotak"; FormShow(Sender); } if(bangun=="segitiga"){ el[1].x=el[1].x+k; el[1].y=el[1].y-k; el[2].x=el[2].x+k; el[2].y=el[2].y-k; el[3].x=el[3].x+k; el[3].y=el[3].y-k; el[4].x=el[4].x+k; el[4].y=el[4].y-k; bangun="segitiga"; FormShow(Sender); } if(bangun=="lingkaran"){ Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height); CircleMidPoint(a+k,b-k,c); bangun="lingkaran"; } if(bangun=="segilima"){ el[1].x=el[1].x+k; el[1].y=el[1].y-k;

el[2].x=el[2].x+k; el[2].y=el[2].y-k; el[3].x=el[3].x+k; el[3].y=el[3].y-k; el[4].x=el[4].x+k; el[4].y=el[4].y-k; el[5].x=el[5].x+k; el[5].y=el[5].y-k; el[6].x=el[6].x+k; el[6].y=el[6].y-k; bangun="segilima"; FormShow(Sender); } if(bangun=="ellips"){ Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height); EllipsMidPoint(a+k,b-k,c,d); bangun="ellips"; }}

M. Source Code Button Translasi ke Kiri

void __fastcall TForm1::BitBtn8Click(TObject *Sender){ int k = StrToInt(Edit1->Text); if(bangun=="kotak"){ el[1].x=el[1].x-k; el[2].x=el[2].x-k; el[3].x=el[3].x-k; el[4].x=el[4].x-k; el[5].x=el[5].x-k; bangun="kotak"; FormShow(Sender); } if(bangun=="segitiga"){ el[1].x=el[1].x-k; el[2].x=el[2].x-k; el[3].x=el[3].x-k; el[4].x=el[4].x-k; bangun="segitiga"; FormShow(Sender); } if(bangun=="lingkaran"){ Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height); CircleMidPoint(a-k,b,c); bangun="lingkaran"; } if(bangun=="segilima"){ el[1].x=el[1].x-k; el[2].x=el[2].x-k; el[3].x=el[3].x-k; el[4].x=el[4].x-k; el[5].x=el[5].x-k; el[6].x=el[6].x-k; bangun="segilima"; FormShow(Sender); } if(bangun=="ellips"){ Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height); EllipsMidPoint(a-k,b,c,d); bangun="ellips"; }}

N. Source Code Button Translasi ke Kanan

void __fastcall TForm1::BitBtn9Click(TObject *Sender){ int k = StrToInt(Edit1->Text); if(bangun=="kotak"){ el[1].x=el[1].x+k; el[2].x=el[2].x+k; el[3].x=el[3].x+k; el[4].x=el[4].x+k; el[5].x=el[5].x+k; bangun="kotak"; FormShow(Sender); } if(bangun=="segitiga"){ el[1].x=el[1].x+k; el[2].x=el[2].x+k; el[3].x=el[3].x+k; el[4].x=el[4].x+k; bangun="segitiga"; FormShow(Sender); } if(bangun=="lingkaran"){ Image1->Canvas->Rectangle (0,0,Image1->Width,Image1=>Height); CircleMidPoint(a+k,b,c); bangun="lingkaran"; } if(bangun=="segilima"){ el[1].x=el[1].x+k; el[2].x=el[2].x+k; el[3].x=el[3].x+k; el[4].x=el[4].x+k; el[5].x=el[5].x+k; el[6].x=el[6].x+k; bangun="segilima"; FormShow(Sender); } if(bangun=="ellips"){ Image1->Canvas->Rectangle (0,0,Image1->Width,Image1->Height); EllipsMidPoint(a+k,b,c,d); bangun="ellips"; }}

O. Source Code Button Translasi ke Kiri Bawah

void __fastcall TForm1::BitBtn10Click(TObject *Sender){ int k = StrToInt(Edit1->Text); if(bangun=="kotak"){ el[1].x=el[1].x-k; el[1].y=el[1].y+k; el[2].x=el[2].x-k; el[2].y=el[2].y+k;

el[3].x=el[3].x-k; el[3].y=el[3].y+k; el[4].x=el[4].x-k; el[4].y=el[4].y+k; el[5].x=el[5].x-k; el[5].y=el[5].y+k; bangun="kotak"; FormShow(Sender); } if(bangun=="segitiga"){ el[1].x=el[1].x-k; el[1].y=el[1].y+k; el[2].x=el[2].x-k; el[2].y=el[2].y+k; el[3].x=el[3].x-k; el[3].y=el[3].y+k; el[4].x=el[4].x-k; el[4].y=el[4].y+k; bangun="segitiga"; FormShow(Sender); } if(bangun=="lingkaran"){ Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height); CircleMidPoint(a-k,b+k,c); bangun="lingkaran"; } if(bangun=="segilima"){ el[1].x=el[1].x-k; el[1].y=el[1].y+k; el[2].x=el[2].x-k; el[2].y=el[2].y+k; el[3].x=el[3].x-k; el[3].y=el[3].y+k; el[4].x=el[4].x-k; el[4].y=el[4].y+k; el[5].x=el[5].x-k; el[5].y=el[5].y+k; el[6].x=el[6].x-k; el[6].y=el[6].y+k; bangun="segilima"; FormShow(Sender); } if(bangun=="ellips"){ Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height); EllipsMidPoint(a-k,b+k,c,d); bangun="ellips"; }}

P. Source Code Button Translasi ke Bawah

void __fastcall TForm1::BitBtn11Click(TObject *Sender){ int k = StrToInt(Edit1->Text); if(bangun=="kotak"){ el[1].y=el[1].y+k; el[2].y=el[2].y+k; el[3].y=el[3].y+k; el[4].y=el[4].y+k; el[5].y=el[5].y+k; bangun="kotak"; FormShow(Sender); } if(bangun=="segitiga"){ el[1].y=el[1].y+k; el[2].y=el[2].y+k; el[3].y=el[3].y+k; el[4].y=el[4].y+k; bangun="segitiga"; FormShow(Sender); } if(bangun=="lingkaran"){ Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height);

CircleMidPoint(a,b+k,c); bangun="lingkaran"; } if(bangun=="segilima"){ el[1].y=el[1].y+k; el[2].y=el[2].y+k; el[3].y=el[3].y+k; el[4].y=el[4].y+k; el[5].y=el[5].y+k; el[6].y=el[6].y+k; bangun="segilima"; FormShow(Sender); } if(bangun=="ellips"){ Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height); EllipsMidPoint(a,b+k,c,d); bangun="ellips"; }}

Q. Source Code Button Translasi ke Kanan Bawah

void __fastcall TForm1::BitBtn12Click(TObject *Sender){ int k = StrToInt(Edit1->Text); if(bangun=="kotak"){ el[1].x=el[1].x+k; el[1].y=el[1].y+k; el[2].x=el[2].x+k; el[2].y=el[2].y+k; el[3].x=el[3].x+k; el[3].y=el[3].y+k; el[4].x=el[4].x+k; el[4].y=el[4].y+k; el[5].x=el[5].x+k; el[5].y=el[5].y+k; bangun="kotak"; FormShow(Sender); } if(bangun=="segitiga"){ el[1].x=el[1].x+k; el[1].y=el[1].y+k; el[2].x=el[2].x+k; el[2].y=el[2].y+k; el[3].x=el[3].x+k; el[3].y=el[3].y+k; el[4].x=el[4].x+k; el[4].y=el[4].y+k; bangun="segitiga"; FormShow(Sender); } if(bangun=="lingkaran"){ Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height); CircleMidPoint(a+k,b+k,c); bangun="lingkaran"; } if(bangun=="segilima"){ el[1].x=el[1].x+k; el[1].y=el[1].y+k; el[2].x=el[2].x+k; el[2].y=el[2].y+k; el[3].x=el[3].x+k; el[3].y=el[3].y+k; el[4].x=el[4].x+k; el[4].y=el[4].y+k; el[5].x=el[5].x+k; el[5].y=el[5].y+k; el[6].x=el[6].x+k; el[6].y=el[6].y+k; bangun="segilima"; FormShow(Sender); } if(bangun=="ellips"){

Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height); EllipsMidPoint(a+k,b+k,c,d); bangun="ellips"; }}

R. Source Code Button Rotasi

void __fastcall TForm1::BitBtn13Click(TObject *Sender){ float sdt=(((StrToFloat(Edit2->Text))/180)*(22/7)); Elemen Tempel[4]; if(bangun=="kotak"){ int i; int tbox=el[5].x; int tboy=el[5].y; for(i=1; i<=4; i++){ el[i].x=el[i].x-tbox; el[i].y=el[i].y-tboy; Tempel[i].x=(el[i].x*cos(sdt)-el[i].y*sin(sdt)); Tempel[i].y=(el[i].x*sin(sdt)+el[i].y*cos(sdt)); el[i].x = Tempel[i].x; el[i].y = Tempel[i].y; el[i].x=el[i].x+tbox; el[i].y=el[i].y+tboy; } bangun="kotak"; FormShow(Sender); } if(bangun=="segitiga"){ int i; int tbox = el[4].x ; int tboy = el[4].y ; for(i=1; i<=3; i++){ el[i].x=el[i].x-tbox; el[i].y=el[i].y-tboy; Tempel[i].x=(el[i].x*cos(sdt)-el[i].y*sin(sdt)); Tempel[i].y=(el[i].x*sin(sdt)+el[i].y*cos(sdt)); el[i] = Tempel[i]; el[i].x=el[i].x+tbox; el[i].y=el[i].y+tboy; } bangun="segitiga"; FormShow(Sender); } if(bangun=="segilima"){ int i; int tbox=el[6].x; int tboy=el[6].y; for(i=1; i<=5; i++){ el[i].x=el[i].x-tbox; el[i].y=el[i].y-tboy; Tempel[i].x=(el[i].x*cos(sdt)-el[i].y*sin(sdt)); Tempel[i].y=(el[i].x*sin(sdt)+el[i].y*cos(sdt)); el[i].x = Tempel[i].x; el[i].y = Tempel[i].y; el[i].x=el[i].x+tbox; el[i].y=el[i].y+tboy;

} bangun="segilima"; FormShow(Sender); }}

S. Source Code Button Pencerminan Terhadap Sumbu X

void __fastcall TForm1::BitBtn17Click(TObject *Sender){ if(bangun=="kotak"){ el[1].x=el[1].x; el[1].y=el[1].y-(2*(el[1].y-((Image1->Height)/2))); el[2].x=el[2].x; el[2].y=el[2].y-(2*(el[2].y-((Image1->Height)/2))); el[3].x=el[3].x; el[3].y=el[3].y-(2*(el[3].y-((Image1->Height)/2))); el[4].x=el[4].x; el[4].y=el[4].y-(2*(el[4].y-((Image1->Height)/2))); el[5].x=el[5].x; el[5].y=el[5].y-(2*(el[5].y-((Image1->Height)/2))); bangun="kotak"; FormShow(Sender); } if(bangun=="segitiga"){ el[1].x=el[1].x; el[1].y=el[1].y-(2*(el[1].y-((Image1->Height)/2))); el[2].x=el[2].x; el[2].y=el[2].y-(2*(el[2].y-((Image1->Height)/2))); el[3].x=el[3].x; el[3].y=el[3].y-(2*(el[3].y-((Image1->Height)/2))); el[4].x=el[4].x; el[4].y=el[4].y-(2*(el[4].y-((Image1->Height)/2))); bangun="segitiga"; FormShow(Sender); } if(bangun=="segilima"){ el[1].x=el[1].x; el[1].y=el[1].y-(2*(el[1].y-((Image1->Height)/2))); el[2].x=el[2].x; el[2].y=el[2].y-(2*(el[2].y-((Image1->Height)/2))); el[3].x=el[3].x; el[3].y=el[3].y-(2*(el[3].y-((Image1->Height)/2))); el[4].x=el[4].x; el[4].y=el[4].y-(2*(el[4].y-((Image1->Height)/2))); el[5].x=el[5].x; el[5].y=el[5].y-(2*(el[5].y-((Image1->Height)/2))); el[6].x=el[6].x; el[6].y=el[6].y-(2*(el[6].y-((Image1->Height)/2))); bangun="segilima"; FormShow(Sender); } if(bangun=="lingkaran"){ Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height); CircleMidPoint(a,(b-(2*(b-((Image1->Height)/2)))),c); bangun="lingkaran"; } if(bangun=="ellips"){

Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height); EllipsMidPoint(a,(b-(2*(b-((Image1->Height)/2)))),c,d); bangun="ellips"; }}

T. Source Code Button Pencerminan Terhadap Sumbu Y

void __fastcall TForm1::BitBtn18Click(TObject *Sender){ if(bangun=="kotak"){ el[1].x=el[1].x-(2*(el[1].x-((Image1->Width)/2))); el[1].y=el[1].y; el[2].x=el[2].x-(2*(el[2].x-((Image1->Width)/2))); el[2].y=el[2].y; el[3].x=el[3].x-(2*(el[3].x-((Image1->Width)/2))); el[3].y=el[3].y; el[4].x=el[4].x-(2*(el[4].x-((Image1->Width)/2))); el[4].y=el[4].y; el[5].x=el[5].x-(2*(el[5].x-((Image1->Width)/2))); el[5].y=el[5].y; bangun="kotak"; FormShow(Sender); } if(bangun=="segitiga"){ el[1].x=el[1].x-(2*(el[1].x-((Image1->Width)/2))); el[1].y=el[1].y; el[2].x=el[2].x-(2*(el[2].x-((Image1->Width)/2))); el[2].y=el[2].y; el[3].x=el[3].x-(2*(el[3].x-((Image1->Width)/2))); el[3].y=el[3].y; el[4].x=el[4].x-(2*(el[4].x-((Image1->Width)/2))); el[4].y=el[4].y; bangun="segitiga"; FormShow(Sender); } if(bangun=="segilima"){ el[1].x=el[1].x-(2*(el[1].x-((Image1->Width)/2))); el[1].y=el[1].y; el[2].x=el[2].x-(2*(el[2].x-((Image1->Width)/2))); el[2].y=el[2].y; el[3].x=el[3].x-(2*(el[3].x-((Image1->Width)/2))); el[3].y=el[3].y; el[4].x=el[4].x-(2*(el[4].x-((Image1->Width)/2))); el[4].y=el[4].y; el[5].x=el[5].x-(2*(el[5].x-((Image1->Width)/2))); el[5].y=el[5].y; el[6].x=el[6].x-(2*(el[6].x-((Image1->Width)/2))); el[6].y=el[6].y; bangun="seiglima"; FormShow(Sender); } if(bangun=="lingkaran"){ Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height); CircleMidPoint((a-(2*(a-((Image1->Width)/2)))),b,c); bangun="lingkaran"; } if(bangun=="ellips"){

Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height); EllipsMidPoint((a-(2*(a-((Image1->Width)/2)))),b,c,d); bangun="ellips"; }}

U. Source Code Button Pencerminan Terhadap X=Y

void __fastcall TForm1::BitBtn19Click(TObject *Sender){ if(bangun=="kotak"){ int a1=el[1].x; int a2=el[2].x; int a3=el[3].x; int a4=el[4].x; int a5=el[5].x; int b1=el[1].y; int b2=el[2].y; int b3=el[3].y; int b4=el[4].y; int b5=el[5].y; el[1].x=b1; el[1].y=a1; el[2].x=b2; el[2].y=a2; el[3].x=b3; el[3].y=a3; el[4].x=b4; el[4].y=a4; el[5].x=b5; el[5].y=a5; bangun="kotak"; FormShow(Sender); } if(bangun=="segitiga"){ int a1=el[1].x; int a2=el[2].x; int a3=el[3].x; int a4=el[4].x; int b1=el[1].y; int b2=el[2].y; int b3=el[3].y; int b4=el[4].y; el[1].x=b1; el[1].y=a1; el[2].x=b2; el[2].y=a2; el[3].x=b3; el[3].y=a3; el[4].x=b4; el[4].y=a4; bangun="segitiga"; FormShow(Sender); } if(bangun=="segilima"){ int a1=el[1].x; int a2=el[2].x; int a3=el[3].x; int a4=el[4].x; int a5=el[5].x; int a6=el[6].x; int b1=el[1].y; int b2=el[2].y; int b3=el[3].y; int b4=el[4].y; int b5=el[5].y; int b6=el[6].y;

el[1].x=b1; el[1].y=a1; el[2].x=b2; el[2].y=a2; el[3].x=b3; el[3].y=a3; el[4].x=b4; el[4].y=a4; el[5].x=b5; el[5].y=a5; el[6].x=b6; el[6].y=a6; bangun="segilima"; FormShow(Sender); } if(bangun=="lingkaran"){ Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height); CircleMidPoint(b,a,c); bangun="lingkaran"; } if(bangun=="ellips"){ Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height); EllipsMidPoint(b,a,d,c); bangun="lingkaran"; }}

V. Source Code Button Pencerminan Zoom In

void __fastcall TForm1::BitBtn16Click(TObject *Sender){ int z = 2; if(bangun=="kotak"){ int tbox = el[5].x; int tboy = el[5].y; el[1].x = tbox+(el[1].x-tbox)*z; el[1].y = tboy+(el[1].y-tboy)*z; el[2].x = tbox+(el[2].x-tbox)*z; el[2].y = tboy+(el[2].y-tboy)*z; el[3].x = tbox+(el[3].x-tbox)*z; el[3].y = tboy+(el[3].y-tboy)*z; el[4].x = tbox+(el[4].x-tbox)*z; el[4].y = tboy+(el[4].y-tboy)*z; bangun="kotak"; FormShow(Sender); } if(bangun=="segitiga"){ int tbox = el[4].x; int tboy = el[4].y; el[1].x = tbox+(el[1].x-tbox)*z; el[1].y = tboy+(el[1].y-tboy)*z; el[2].x = tbox+(el[2].x-tbox)*z; el[2].y = tboy+(el[2].y-tboy)*z; el[3].x = tbox+(el[3].x-tbox)*z; el[3].y = tboy+(el[3].y-tboy)*z; bangun="segitiga"; FormShow(Sender); } if(bangun=="lingkaran"){ Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height); CircleMidPoint(a,b,c*z); bangun="lingkaran"; } if(bangun=="segilima"){ int tbox = el[6].x; int tboy = el[6].y; el[1].x = tbox+(el[1].x-tbox)*z; el[1].y = tboy+(el[1].y-tboy)*z; el[2].x = tbox+(el[2].x-tbox)*z; el[2].y = tboy+(el[2].y-tboy)*z; el[3].x = tbox+(el[3].x-tbox)*z; el[3].y = tboy+(el[3].y-tboy)*z; el[4].x = tbox+(el[4].x-tbox)*z; el[4].y = tboy+(el[4].y-tboy)*z; el[5].x = tbox+(el[5].x-tbox)*z; el[5].y = tboy+(el[5].y-tboy)*z; bangun="segilima"; FormShow(Sender);

} if(bangun=="ellips"){ Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height); EllipsMidPoint(a,b,c*z,d*z); bangun="ellips"; }}

W. Source Code Button Pencerminan Zoon Out

void __fastcall TForm1::BitBtn15Click(TObject *Sender){ float z = 0.5; if(bangun=="kotak"){ int tbox = el[5].x; int tboy = el[5].y; el[1].x = tbox+(el[1].x-tbox)*z; el[1].y = tboy+(el[1].y-tboy)*z; el[2].x = tbox+(el[2].x-tbox)*z; el[2].y = tboy+(el[2].y-tboy)*z; el[3].x = tbox+(el[3].x-tbox)*z; el[3].y = tboy+(el[3].y-tboy)*z; el[4].x = tbox+(el[4].x-tbox)*z; el[4].y = tboy+(el[4].y-tboy)*z; bangun="kotak"; FormShow(Sender); } if(bangun=="segitiga"){ int tbox = el[4].x; int tboy = el[4].y; el[1].x = tbox+(el[1].x-tbox)*z; el[1].y = tboy+(el[1].y-tboy)*z; el[2].x = tbox+(el[2].x-tbox)*z; el[2].y = tboy+(el[2].y-tboy)*z; el[3].x = tbox+(el[3].x-tbox)*z; el[3].y = tboy+(el[3].y-tboy)*z; bangun="segitiga"; FormShow(Sender); } if(bangun=="lingkaran"){ Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height); CircleMidPoint(a,b,c*z); bangun="lingkaran"; } if(bangun=="segilima"){ int tbox = el[6].x; int tboy = el[6].y; el[1].x = tbox+(el[1].x-tbox)*z; el[1].y = tboy+(el[1].y-tboy)*z; el[2].x = tbox+(el[2].x-tbox)*z; el[2].y = tboy+(el[2].y-tboy)*z; el[3].x = tbox+(el[3].x-tbox)*z; el[3].y = tboy+(el[3].y-tboy)*z; el[4].x = tbox+(el[4].x-tbox)*z; el[4].y = tboy+(el[4].y-tboy)*z; el[5].x = tbox+(el[5].x-tbox)*z; el[5].y = tboy+(el[5].y-tboy)*z; bangun="segilima"; FormShow(Sender); } if(bangun=="ellips"){ Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height); EllipsMidPoint(a,b,c*z,d*z); bangun="ellips"; }}

BAB IV

IMPLEMENTASI

Tampilan Awal

Jika Icon Lingkaran di klik maka Gambar Lingkaran akan terbentuk

Jika Icon Segitiga di klik maka Gambar Segitiga akan terbentuk

Jika Icon Kotak di klik maka Gambar Kotak akan terbentuk

Jika Icon SegiLima di klik maka Gambar SegiLima akan terbentuk

Jika Icon Elips di klik maka Gambar Elips akan terbentuk

Proses Zoom Segitiga

Sebelum Sesudah

Proses Pewarnaan Objek

Sebelum Sesudah

Proses Translasi Objek Ke arah Kanan AtasSebelum Sesudah

Proses Rotasi 90o Sebelum Sesudah

Proses Pencerminan Terhadap Y=X

Sebelum Sesudah

BAB V

KESIMPULAN

Kami telah membuat tugas grafika computer dengan menggunakan konsep

perhitungan matematika dan penggabungan logika dengan algoritma dapat membuat dan

memberi variasi objek berupa pewarnaan, rotasi, pencerminan, zooming dan

translasi/perpindahan. Kami juga telah membuat beberapa gambar objek 2D dengan

menggunakan aplikasi C++ Builder.

VI

DAFTAR PUSTAKA

Sofyan,Herry., Materi pembelajaran grafika computer, Yogyakarta, 2010.

top related