http://www.oschina.net/code/snippet_103482_14802

看到这个稀奇古怪的语言画国旗,代码真心简洁。试着用C语言实现,确实麻烦不少——主要是数字全要自己算啊。

1.[代码][C/C++]代码

#include

#include

/* Declare Windows procedure */

LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

void DrawFiveStarFlag(HDC hdc, int x, int y, int w);

void DrawFivePointedStar(HDC hdc, int x, int y, int r, float d);

/* Current app instance */

HINSTANCE hInst;

/* Make the class name into a global variable */

TCHAR szClassName[] = TEXT("WindowsApp");

int WINAPI

WinMain (HINSTANCE hThisInstance,

HINSTANCE hPrevInstance,

LPSTR lpszArgument,

int nFunsterStil)

{

HWND hwnd; /* This is the handle for our window */

MSG messages; /* Here messages to the application are saved */

WNDCLASSEX wincl; /* Data structure for the windowclass */

/* Save this instance */

hInst = hThisInstance;

/* The Window structure */

wincl.hInstance = hThisInstance;

wincl.lpszClassName = szClassName;

wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */

wincl.style = CS_DBLCLKS; /* Catch double-clicks */

wincl.cbSize = sizeof (WNDCLASSEX);

/* Use default icon and mouse-pointer */

wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);

wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);

wincl.hCursor = LoadCursor (NULL, IDC_ARROW);

wincl.lpszMenuName = NULL;

wincl.cbClsExtra = 0; /* No extra bytes after the window class */

wincl.cbWndExtra = 0; /* structure or the window instance */

/* Use Windows's default color as the background of the window */

wincl.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);

/* Register the window class, and if it fails quit the program */

if (!RegisterClassEx (&wincl))

return 0;

/* The class is registered, let's create the program*/

hwnd = CreateWindowEx (

0, /* Extended possibilites for variation */

szClassName, /* Classname */

TEXT("TestPie"), /* Title Text */

WS_OVERLAPPEDWINDOW, /* default window */

CW_USEDEFAULT, /* Windows decides the position */

0, /* where the window ends up on the screen */

CW_USEDEFAULT, /* The programs width */

0, /* and height in pixels */

HWND_DESKTOP, /* The window is a child-window to desktop */

NULL, /* No menu */

hThisInstance, /* Program Instance handler */

NULL /* No Window Creation data */

);

/* Make the window visible on the screen */

ShowWindow (hwnd, nFunsterStil);

/* Run the message loop. It will run until GetMessage() returns 0 */

while (GetMessage (&messages, NULL, 0, 0))

{

/* Translate virtual-key messages into character messages */

TranslateMessage(&messages);

/* Send message to WindowProcedure */

DispatchMessage(&messages);

}

/* The program return-value is 0 - The value that PostQuitMessage() gave */

return messages.wParam;

}

/* This function is called by the Windows function DispatchMessage() */

LRESULT CALLBACK

WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)

{

PAINTSTRUCT ps;

HDC hdc;

switch (message) /* handle the messages */

{

case WM_PAINT:

hdc = BeginPaint(hwnd, &ps);

/* TODO: Add any drawing code here... */

DrawFiveStarFlag(hdc, 50, 50, 300);

EndPaint(hwnd, &ps);

break;

case WM_DESTROY:

PostQuitMessage (0); /* send a WM_QUIT to the message queue */

break;

default: /* for messages that we don't deal with */

return DefWindowProc (hwnd, message, wParam, lParam);

}

return 0;

}

/* 画五角星

* 参数:hdc画图句柄,xy中心点坐标,r外圆半径,d偏斜角度(逆时针)

*/

void DrawFivePointedStar(HDC hdc, int x, int y, int r, float d)

{

float r0 = 0.381966*r;//内圆半径:r*sin(0.1*M_PI)/sin(0.7*M_PI)

int i;

POINT p[10];

//计算10个顶点的坐标(72度为实心五角星,144为空心五角星)

for(i=0; i<5; i++)

{

p[2*i].x = x + r*cos((i*72-18+d)*M_PI/180);

p[2*i].y = y + r*sin((i*72-18+d)*M_PI/180);

p[2*i+1].x = x + r0*cos((i*72+18+d)*M_PI/180);

p[2*i+1].y = y + r0*sin((i*72+18+d)*M_PI/180);

}

//画五角星

Polygon(hdc, p, 10);

}

/* 画五星红旗

* 参数:hdc画图句柄,xy旗左上角坐标,w旗宽

*/

void DrawFiveStarFlag(HDC hdc, int x, int y, int w)

{

COLORREF RED = RGB(255, 0, 0), YELLOW = RGB(255, 255, 0);

HPEN hPen1 = CreatePen(PS_SOLID, 1, RED), hPen2 = CreatePen(PS_SOLID, 1, YELLOW);

HBRUSH hBrush1 = CreateSolidBrush(RED), hBrush2 = CreateSolidBrush(YELLOW);

//画旗面

SelectObject(hdc, hPen1);

SelectObject(hdc, hBrush1);

Rectangle(hdc, x, y, x+w, y+2*w/3);

//画5星

SelectObject(hdc, hPen2);

SelectObject(hdc, hBrush2);

DrawFivePointedStar(hdc, x+w/6, y+w/6, w/10, 0);//大星

DrawFivePointedStar(hdc, x+w/3, y+w/15, w/30, 18);//4个小星,倾斜角度都是估的

DrawFivePointedStar(hdc, x+2*w/5, y+2*w/15, w/30, 45);

DrawFivePointedStar(hdc, x+2*w/5, y+7*w/30, w/30, 9);

DrawFivePointedStar(hdc, x+w/3, y+3*w/10, w/30, 27);

DeleteObject(hPen1);

DeleteObject(hPen2);

DeleteObject(hBrush1);

DeleteObject(hBrush2);

}

2.[图片] 1.JPG

linux画国旗程序,C语言也能画国旗相关推荐

  1. c语言画猪程序,C语言画小猪佩奇(转载)

    C语言画小猪佩奇 分享下如何用 C 语言画小猪佩奇 使用带符号距离场(signed distance field, SDF)表示圆形: 沿用这个方法表示形状,但这次我们想利用 ASCII 字符|/=\ ...

  2. 画图板程序c语言,【原创】画图板程序

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 #include #include #include #include #define PAINTAREA 1//画图区标志 #define CASEAR ...

  3. 在Linux系统中运行C语言程序

    正式学习c语言的第一天   2022/1/10 在之前的学习中已经在Windows系统中用Microsoft VC++上实现了C语言程序的运行,现在将在Linux系统上运行C语言程序. 首先明确C语言 ...

  4. 简单的c语言三角形程序,剖析C语言是如何画出这样的三角形的

    哈哈,就是喜欢这些有意思的C语言 上篇文章是这样写的 那篇文章写的有点不直接,然后再查了下资料,看到了下面这些,我觉得解释更加好,这里主要是运用了光栅法,至于光栅法,可以百度看看,后面我会再写文章理理 ...

  5. 在Linux环境下用C语言编写一个乘法程序mult,从命令行接收两个数字,然后输出其乘积;再用C语言编写一个exec1程序,在程序中使用execvp调用mult程序计算5与10的乘积。

    在Linux环境下用C语言编写一个乘法程序mult,从命令行接收两个数字,然后输出其乘积:再用C语言编写一个exec1程序,在程序中使用execvp调用mult程序计算5与10的乘积. 1.mult. ...

  6. linux运行go程序命令行,宝塔面板Linux环境-安装Golang:Go语言环境安装以及程序如何运行...

    有的人可能对Go语言很感兴趣,这也是近几年很火的一门编程语言,我们可以在宝塔面板Linux环境下安装Go语言环境. 安装环境:CentOS Linux 7.6.宝塔面板6.9.3.golang:go1 ...

  7. 黑白棋代码Linux程序,C语言编写的黑白棋游戏源代码.doc

    PAGE PAGE 1 C语言编写的黑白棋游戏源代码 /*3.3.4 源程序*/ #include "graphics.h" /*图形系统头文件*/ #define LEFT 0x ...

  8. linux newt 安装程序,NEWT程序设计指南

    NEWT是在Linux下一个基于文本方式的窗口开发工具,最初是为Red Hat Linux的安装程序而设计的.本文将告诉您怎样一步步使用NEWT为自己的应用程序加上文本方式下的窗口界面. 考虑到Red ...

  9. 棱形旋转c语言程序_C 语言时隔 5 年重回巅峰,这 20 个热门项目拿去练手!

    在上个月的 TIOBE 编程语言排名中,C 语言和 Java 的差距只有 0.01%.在近日 TIOBE 公布的 2020 年 5 月编程语言排行榜中,C 语言成功超越了 Java,重返第一的王者宝座 ...

最新文章

  1. 怎么判断时double和floatc++_安居客堂:您知道怎么选择优质的轻钢龙骨吗?
  2. b500k电位器引脚接法_可调电位器实物接线图及接线方法详解
  3. boost::hana::metafunction_class用法的测试程序
  4. Vue电商后台B站的项目需要的材料 密码等
  5. NS2安装笔记---SUSE Linux
  6. 比特币的密钥、地址、钱包
  7. 19.04.13--指针笔记
  8. 微型计算机中call指令,微机原理 第四章 微型计算机指令系统.ppt
  9. Whistle抓包详细使用教程
  10. 英语系大一计算机课程有哪些,英语专业大一学习计划.docx
  11. backup archivelog all not backed up
  12. Go语言操作excel
  13. MySQL级联优缺点_【Mysql】外键级联与级联的劣势
  14. 数据库的横向和纵向分表
  15. Python 图片与pdf相互转换
  16. 5G NR帧结构与物理资源
  17. Apriori算法详解及手写案例
  18. 2012浙大招收比例
  19. 基于emp的 单表查询 练习题及答案
  20. java-net-php-python-jspm广联超市管理系统计算机毕业设计程序

热门文章

  1. PACS医学影像DICOM dcmdictpath知识记录梳理
  2. 云安全|云原生安全概述
  3. Internet随笔
  4. 计算机学硕毕业论文字数,华科硕士毕业论文几多要求?
  5. 实战三:手把手教你实现物体识别
  6. 数据库:常用数据库的创建
  7. 系统服务器算固定资产吗,服务器操作系统算固定资产
  8. 读《诗经·邶风·击鼓》有感-间歇博客
  9. 增加对IE11的兼容
  10. HDU2058 The sum problem(数学问题)