📜  在C++图形中绘制三角形

📅  最后修改于: 2021-05-30 19:02:34             🧑  作者: Mango

先决条件: graphics.h,如何在CodeBlocks中包含graphics.h?

任务是编写一个C程序以使图形具有图形的直线函数。

要运行该程序,我们必须包含以下头文件:

#include 

方法:这个想法是在几条线的帮助下创建一个三角形。我们将通过向line()函数传递4个数字来在图形中画一条线

下面是上述方法的实现:

C++
// C++ program for drawing a triangle
#include 
#include 
  
// Driver code
int main()
{
    // gm is Graphics mode which
    // is a computer display
    // mode that generates
    // image using pixels.
    // DETECT is a macro
    // defined in "graphics.h"
    // header file
    int gd = DETECT, gm;
  
    // initgraph initializes
    // the graphics system
    // by loading a graphics
    // driver from disk
    initgraph(&gd, &gm, "");
  
    // Triangle
  
    // line for x1, y1, x2, y2
    line(150, 150, 450, 150);
  
    // line for x1, y1, x2, y2
    line(150, 150, 300, 300);
  
    // line for x1, y1, x2, y2
    line(450, 150, 300, 300);
  
    // closegraph function closes
    // the graphics mode and
    // deallocates all memory
    // allocated by graphics system
    getch();
  
    // Close the initialized gdriver
    closegraph();
}


输出:
以下是上述程序的输出:

要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程”