Share 875. koko eating bananas c++,

yellowbird560

New member
#C ++, #Koko, #eat, #BanAnas ## 875. Koko ăn chuối trong C ++

Koko con khỉ đột là một con vật nổi tiếng đã học cách giao tiếp bằng ngôn ngữ ký hiệu.Trong một video nổi tiếng, Koko được hiển thị ăn một quả chuối.Bài viết này sẽ chỉ cho bạn cách tạo lại cảnh này trong C ++.

### Bước 1: Tạo một dự án mới

Để bắt đầu, hãy mở C ++ IDE yêu thích của bạn và tạo một dự án mới.

### Bước 2: Xác định lớp cửa sổ

Tiếp theo, bạn cần xác định lớp cửa sổ cho ứng dụng của mình.Lớp này sẽ xác định ngoại hình và hành vi của cửa sổ.

`` `C ++
lớp kokowindow: wxframe công khai {
công cộng:
Kokowindow (const wxString & tiêu đề);

riêng tư:
void onpaint (wxpaintevent & sự kiện);
};
`` `

Lớp `kokowindow` kế thừa từ lớp` wxframe`, cung cấp chức năng cơ bản cho một cửa sổ.Trình xây dựng cho lớp `kokowindow` lấy một chuỗi tiêu đề làm đối số duy nhất của nó.

Hàm `onpaint` được gọi bất cứ khi nào cửa sổ cần được sơn lại.Chức năng này sẽ vẽ hình ảnh của Koko ăn chuối.

### Bước 3: Triển khai lớp cửa sổ

Bây giờ bạn cần thực hiện lớp `kokowindow`.Mã sau đây cho thấy việc triển khai lớp `kokowindow`:

`` `C ++
Kokowindow :: Kokowindow (Const WXString & Title)
: wxframe (nullptr, wxid_any, title, wxDefaultPocation, wxsize (800, 600)) {
// Đặt màu nền của cửa sổ.
SetBackgroundColour (WXColour (255, 255, 255));

// Tạo hình ảnh Koko ăn chuối.
hình ảnh wxbitmap (wimpage (
"https://upload.wikimedia.org/wikipe..._ating_bananas.jpg/220px-koko_eat_bananas.jpg"));

// Tạo một bảng điều khiển để giữ hình ảnh.
wxpanel* bảng điều khiển = new wxpanel (this);

// Thêm hình ảnh vào bảng điều khiển.
bảng-> statBackgroundImage (hình ảnh);

// Đặt kích thước của bảng điều khiển với cùng kích thước với hình ảnh.
Bảng-> setSize (Image.getSize ());
}

void kokowindow :: onpaint (wxpaintevent & event) {
// Nhận bối cảnh đồ họa cho cửa sổ.
wxpaintdc dc (this);

// Vẽ hình ảnh của koko ăn chuối.
dc.drawbitmap (hình ảnh, 0, 0);
}
`` `

`Kokowindow :: Nhà xây dựng Kokowindow` khởi tạo màu nền của cửa sổ và tạo ra hình ảnh của Koko đang ăn chuối.Chức năng `kokowindow :: onpaint` vẽ hình ảnh koko ăn chuối vào cửa sổ.

### Bước 4: Chạy ứng dụng

Bây giờ bạn có thể chạy ứng dụng bằng cách nhấp vào nút ** Build ** trong IDE của bạn.Ứng dụng sẽ tạo ra một cửa sổ hiển thị hình ảnh của Koko đang ăn chuối.

! [Koko ăn chuối] (https://upload.wikimedia.org/wikipedia/commons/thumb/4/42/koko_eat_bananas.jpg

### Phần kết luận

Bài viết này chỉ cho bạn cách tái tạo cảnh Koko ăn chuối trong C ++.Bạn có thể sử dụng kỹ thuật này để tạo hình ảnh động và trò chơi của riêng bạn.

## 5 hashtags

* #C ++
* #Koko
* #Ăn
* #BanAnas
* #Animalc truyền thông
=======================================
#C++, #Koko, #eating, #BanAnas ## 875. Koko Eating Bananas in C++

Koko the gorilla is a famous animal who learned to communicate using sign language. In one famous video, Koko is shown eating a banana. This article will show you how to recreate this scene in C++.

### Step 1: Create a new project

To get started, open your favorite C++ IDE and create a new project.

### Step 2: Define the window class

Next, you need to define the window class for your application. This class will define the window's appearance and behavior.

```c++
class KokoWindow : public wxFrame {
public:
KokoWindow(const wxString& title);

private:
void OnPaint(wxPaintEvent& event);
};
```

The `KokoWindow` class inherits from the `wxFrame` class, which provides the basic functionality for a window. The constructor for the `KokoWindow` class takes a title string as its only argument.

The `OnPaint` function is called whenever the window needs to be repainted. This function will draw the image of Koko eating a banana.

### Step 3: Implement the window class

Now you need to implement the `KokoWindow` class. The following code shows the implementation of the `KokoWindow` class:

```c++
KokoWindow::KokoWindow(const wxString& title)
: wxFrame(nullptr, wxID_ANY, title, wxDefaultPosition, wxSize(800, 600)) {
// Set the window's background color.
SetBackgroundColour(wxColour(255, 255, 255));

// Create the image of Koko eating a banana.
wxBitmap image(wxImage(
"https://upload.wikimedia.org/wikipe...ing_bananas.jpg/220px-Koko_eating_bananas.jpg"));

// Create a panel to hold the image.
wxPanel* panel = new wxPanel(this);

// Add the image to the panel.
panel->SetBackgroundImage(image);

// Set the panel's size to the same size as the image.
panel->SetSize(image.GetSize());
}

void KokoWindow::OnPaint(wxPaintEvent& event) {
// Get the graphics context for the window.
wxPaintDC dc(this);

// Draw the image of Koko eating a banana.
dc.DrawBitmap(image, 0, 0);
}
```

The `KokoWindow::KokoWindow` constructor initializes the window's background color and creates the image of Koko eating a banana. The `KokoWindow::OnPaint` function draws the image of Koko eating a banana to the window.

### Step 4: Run the application

Now you can run the application by clicking the **Build** button in your IDE. The application will create a window that displays the image of Koko eating a banana.

![Koko Eating Bananas](https://upload.wikimedia.org/wikipedia/commons/thumb/4/42/Koko_eating_bananas.jpg/220px-Koko_eating_bananas.jpg)

### Conclusion

This article showed you how to recreate the scene of Koko eating bananas in C++. You can use this technique to create your own animations and games.

## 5 Hashtags

* #C++
* #Koko
* #eating
* #BanAnas
* #AnimalCommunication
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top