圣诞树Easyx绘图
生活随笔
收集整理的這篇文章主要介紹了
圣诞树Easyx绘图
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
這是用VS2019借用easyx圖形庫寫的代碼,能力有限
easyx點此官網下載安裝
#include<easyx.h> #include<conio.h> #include<math.h> #include <time.h> #include<mmsystem.h> #pragma comment(lib,"winmm.lib")#define PI 3.14 #define X 640 #define Y 480void music() {mciSendString(_T("open ./music/花海.mp3"), NULL, 0, NULL);//打開音樂mciSendString(_T("play ./music/花海.mp3 repeat"), NULL, 0, NULL);//播放音樂 } void tree() {cleardevice();settextcolor(RGB(rand() % 256, rand() % 256, rand() % 256));settextstyle(30, 0, _T("宋體"));outtextxy(rand() % X - 10, rand() % Y - 10, _T("?"));outtextxy(rand() % X - 10, rand() % Y - 10, _T("?"));outtextxy(rand() % X - 10, rand() % Y - 10, _T("?"));outtextxy(rand() % X - 10, rand() % Y - 10, _T("?"));outtextxy(rand() % X - 10, rand() % Y - 10, _T("?"));//第一個三角形setlinecolor(RGB(144, 238, 144));setfillcolor(RGB(34, 139, 34));POINT pts1[] ={{X / 2,Y / 10},//頂點{2 * X / 5,19 * Y / 100},//左點{3 * X / 5,19 * Y / 100}//右點};solidpolygon(pts1, 3);// 繪制五角星POINT pts[5];double a = PI / 2;for (int i = 0; i < 5; i++){pts[i].x = int(X / 2 + cos(a) * 23);pts[i].y = int(Y / 10 - sin(a) * 23);a += PI * 4 / 5;}setpolyfillmode(WINDING);setfillcolor(RGB(255, 230, 0));solidpolygon(pts, 5);//第2個三角形setlinecolor(RGB(144, 238, 144));setfillcolor(RGB(34, 139, 34));POINT pts2[] ={{X / 2,3 * Y / 20 },//頂點{8 * X / 25,3 * Y / 10},//左點{17 * X / 25,3 * Y / 10}//右點};solidpolygon(pts2, 3);//第三個三角形POINT pts3[] ={{X / 2,6 * Y / 25 },//頂點{1 * X / 4,43 * Y / 100},//左點{3 * X / 4,43 * Y / 100}//右點};solidpolygon(pts3, 3);//樹干setfillcolor(RGB(139, 69, 19));solidrectangle(9 * X / 20, 43 * Y / 100, 11 * X / 20, 7 * Y / 10); } void bulb() {setfillcolor(RGB(rand() % 256, rand() % 256, rand() % 256));solidcircle(12 * X / 25, Y / 10 + (19 * Y / 100 - Y / 10), 5);setfillcolor(RGB(rand() % 256, rand() % 256, rand() % 256));solidcircle(45 * X / 100, Y / 10 + 13 * Y / 100, 5);setfillcolor(RGB(rand() % 256, rand() % 256, rand() % 256));solidcircle(49 * X / 100, 28 * Y / 100, 5);setfillcolor(RGB(rand() % 256, rand() % 256, rand() % 256));solidcircle(44 * X / 100, 31 * Y / 100, 5);setfillcolor(RGB(rand() % 256, rand() % 256, rand() % 256));solidcircle(13 * X / 25, Y / 10 + (19 * Y / 100 - Y / 10), 5);setfillcolor(RGB(rand() % 256, rand() % 256, rand() % 256));solidcircle(55 * X / 100, Y / 10 + 13 * Y / 100, 5);setfillcolor(RGB(rand() % 256, rand() % 256, rand() % 256));solidcircle(54 * X / 100, 29 * Y / 100, 5);setfillcolor(RGB(rand() % 256, rand() % 256, rand() % 256));solidcircle(53 * X / 100, 34 * Y / 100, 5);setfillcolor(RGB(rand() % 256, rand() % 256, rand() % 256));solidcircle(40 * X / 100, 36 * Y / 100, 5);setfillcolor(RGB(rand() % 256, rand() % 256, rand() % 256));solidcircle(35 * X / 100, 40 * Y / 100, 5);setfillcolor(RGB(rand() % 256, rand() % 256, rand() % 256));solidcircle(50 * X / 100, 37 * Y / 100, 5);setfillcolor(RGB(rand() % 256, rand() % 256, rand() % 256));solidcircle(65 * X / 100, 40 * Y / 100, 5); }int main() {initgraph(X, Y);srand((unsigned)time(NULL));//隨機數種子setbkcolor(WHITE);setbkmode(TRANSPARENT);//字體背景透明music();BeginBatchDraw();while (1) {tree();bulb();FlushBatchDraw();Sleep(500);//延遲0.5秒}_getch();closegraph();return 0; }總結
以上是生活随笔為你收集整理的圣诞树Easyx绘图的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: NIST发布四种抗量子密码算法
- 下一篇: 梦幻古龙服务器 文档,梦幻古龙GM命令大