Gambar Persegi, Lingkaran, dan Garis C++

langkah pertama untuk membuat gambar 2D di C++ adalah :

1. jalankan dahulu aplikasinya, kita coba pake borland C++ builder 6

2. kemudian muncul window borland c++

3. yang muncul pertama adalah “form1”

4. kemudian di bagian Object Inspector, double klik pada OnPaint

5. muncul “Unit1.cpp”

6. nah ini tempat kita mulai menuliskan code c++

7. ketikan code berikut di dalam “void __fastcall TForm1::FormPaint(TObject *Sender)

Canvas->MoveTo(250,50);
Canvas->LineTo(180,100);
Canvas->MoveTo(250,50);
Canvas->LineTo(320,100);
Canvas->MoveTo(180,100);
Canvas->LineTo(320,100);

Canvas->Pen->Color=clBlack;
Canvas->Brush->Color=clRed;
Canvas->Ellipse(50, 50, 150, 150);

Canvas->Pen->Color=clRed;
Canvas->Brush->Color=clBlue;
Canvas->Rectangle(150,150,250,250);

8. hasilnya adalah sebagai berikut

void __fastcall TForm1::FormPaint(TObject *Sender)
{
Canvas->MoveTo(250,50);
Canvas->LineTo(180,100);
Canvas->MoveTo(250,50);
Canvas->LineTo(320,100);
Canvas->MoveTo(180,100);
Canvas->LineTo(320,100);

Canvas->Pen->Color=clBlack;
Canvas->Brush->Color=clRed;
Canvas->Ellipse(50, 50, 150, 150);

Canvas->Pen->Color=clRed;
Canvas->Brush->Color=clBlue;
Canvas->Rectangle(150,150,250,250);
}

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s