Jaring dapat digunakan untuk membuat ‘kulit’ dari suatu objek.
- Metode daftar titik (vertex list method)
- Metode daftar muka (face list method)
interface:
Source code Program :
Unit1.cpp
//---------------------------------------------------------------------------
#include
#pragma hdrstop // library yang sudah disediakan oleh Borland C++ Builder
#include "Unit1.h" // membaca file Unit1.h
#pragma resource "*.dfm" // library yang sudah disediakan oleh Borland C++ Builder
TForm1 *Form1;
struct Elemen { float x,y ;} ; // objek berbentuk struktur dengan variabel X dan Y yang bertipe float
Elemen Objek[17]; // deklarasi elemen
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
// memanggil fungsi TForm1
//---------------------------------------------------------------------------
void __fastcall TForm1::FormActivate(TObject *Sender)
// memanggil fungsi FormActivate untuk membuat objek dengan menentukan titik-titik objek pada koordinat x dan y
{
Objek[1].x = 100; Objek[1].y = 50;
Objek[2].x = 50; Objek[2].y = 50;
Objek[3].x = 50; Objek[3].y = 100;
Objek[4].x = 100; Objek[4].y = 100;
Objek[5].x = 125; Objek[5].y = 125;
Objek[6].x = 75; Objek[6].y = 125;
Objek[7].x = 75; Objek[7].y = 175;
Objek[8].x = 125; Objek[8].y = 175;
// Objek 1 sampai objek 8 merupakan penulisan posisi titik dalam pembuatan objek.
Objek[9].x = 100; Objek[9].y = 100;
Objek[10].x = 125; Objek[10].y = 175;
Objek[11].x = 50; Objek[11].y = 100;
Objek[12].x = 75; Objek[12].y = 175;
Objek[13].x = 50; Objek[13].y = 50;
Objek[14].x = 75; Objek[14].y = 125;
Objek[15].x = 100; Objek[15].y = 50;
Objek[16].x = 125; Objek[16].y = 125;
//Objek 9 sampai objek 16 merupakan penulisan posisi garis dalam pembuatan objek.
FormShow(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow(TObject *Sender)
{
int i;
Image1->Canvas->Rectangle(0,0,Image1->Width,Image1->Height);
Image1->Canvas->MoveTo(Objek[4].x,Objek[4].y);
for (i=1;i<=4;i++){ Image1->Canvas->LineTo(Objek[i].x,Objek[i].y);};
Image1->Canvas->MoveTo(Objek[8].x,Objek[8].y);
for (i=5;i<=8;i++){ Image1->Canvas->LineTo(Objek[i].x,Objek[i].y);};
Image1->Canvas->MoveTo(Objek[10].x,Objek[10].y);
for (i=9;i<=10;i++){ Image1->Canvas->LineTo(Objek[i].x,Objek[i].y);};
Image1->Canvas->MoveTo(Objek[12].x,Objek[12].y);
for (i=11;i<=12;i++){ Image1->Canvas->LineTo(Objek[i].x,Objek[i].y);};
Image1->Canvas->MoveTo(Objek[14].x,Objek[14].y);
for (i=13;i<=14;i++){ Image1->Canvas->LineTo(Objek[i].x,Objek[i].y);};
Image1->Canvas->MoveTo(Objek[16].x,Objek[16].y);
for (i=15;i<=16;i++){ Image1->Canvas->LineTo(Objek[i].x,Objek[i].y);};
}
//memanggil fungsi FormShow
Unit.h
// File ini berisi event handler untuk mengatasi sebuah event dari komponen yang ditempatkan pada sebuah form.
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include
#include
#include
#include
#include
#include
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TImage *Image1;
void __fastcall FormActivate(TObject *Sender);
void __fastcall FormShow(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
OUTPUT :
Tidak ada komentar:
Posting Komentar