当前位置:网站首页>Drawing dynamic 3D circle with pure C language
Drawing dynamic 3D circle with pure C language
2022-07-05 05:20:00 【Korloa】
Recently, I found something about using C Language in Windows Environment to draw dynamic circle code , It is worth learning from .
Everyone knows ,C/C++ Born with a black window , Only characters . But running the following code will definitely surprise you .
Be careful :
The code may need to add the following code to the compilation options to run
-lgdi32Code:
#include <math.h>
#include <windows.h>
#define PI 3.1415926
#define SX 8
#define SY 16
#define DX PI / SX
#define DY PI * 2 / SY
#define X(a, b) (cx + v[a][b].x * r), (cy + v[a][b].y * r)
typedef struct { double x, y; } Vec;
void calc(double i, double j, double rot, Vec* v) {
double x = sin(i) * cos(j), y = sin(i) * sin(j), z = cos(i),
s = sin(rot), c = cos(rot), c1 = 1 - c, u = 1 / sqrt(3.0f), u2 = u * u;
v->x = x * (c + u2 * c1) + y * (u2 * c1 - u * s) + z * (u2 * c1 + u * s);
v->y = x * (u2 * c1 + u * s) + y * (c + u2 * c1) + z * (u2 * c1 - u * s);
}
int main() {
HWND hwnd = GetConsoleWindow(); HDC hdc1 = GetDC(hwnd);
double rot = 0;
while(1) {
RECT rect; GetClientRect(hwnd, &rect); int w = rect.right, h = rect.bottom, cx = w / 2, cy = h / 2, r = h * 0.375;
HDC hdc2 = CreateCompatibleDC(hdc1); HBITMAP bmp = CreateCompatibleBitmap(hdc1, w, h); SelectObject(hdc2, bmp);
SelectObject(hdc2, GetStockObject(WHITE_PEN));
Vec v[SX + 1][SY + 1];
for(int i = 0; i <= SX; ++i) for(int j = 0; j <= SY; ++j) calc(i * DX, j * DY, rot, &v[i][j]);
for(int i = 0; i < SX; ++i) for(int j = 0; j < SY; ++j) {
MoveToEx(hdc2, X(i, j), NULL); LineTo(hdc2, X(i + 1, j));
MoveToEx(hdc2, X(i, j), NULL); LineTo(hdc2, X(i, j + 1));
}
BitBlt(hdc1, 0, 0, w, h, hdc2, 0, 0, SRCCOPY); DeleteObject(bmp); DeleteDC(hdc2);
rot += 0.01; Sleep(10);
}
}边栏推荐
- The next key of win generates the timestamp file of the current day
- Research on the value of background repeat of background tiling
- To be continued] [UE4 notes] L4 object editing
- 动漫评分数据分析与可视化 与 IT行业招聘数据分析与可视化
- When will Wei Lai, who has been watched by public opinion, start to "build high-rise buildings" again?
- PMP考生,请查收7月PMP考试注意事项
- Haut OJ 1243: simple mathematical problems
- A new micro ORM open source framework
- [turn]: Apache Felix framework configuration properties
- Download xftp7 and xshell7 (official website)
猜你喜欢

Page countdown

Embedded database development programming (VI) -- C API

BUUCTF MISC

小程序直播+电商,想做新零售电商就用它吧!

Romance of programmers on Valentine's Day

Optimization scheme of win10 virtual machine cluster

对象的序列化

Bucket sort

Ue4/ue5 illusory engine, material part (III), material optimization at different distances

lxml.etree.XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8
随机推荐
[depth first search] 695 Maximum area of the island
使用命令符关闭笔记本自带键盘命令
被舆论盯上的蔚来,何时再次“起高楼”?
嵌入式数据库开发编程(六)——C API
Yolov5 ajouter un mécanisme d'attention
Under the national teacher qualification certificate in the first half of 2022
支持多模多态 GBase 8c数据库持续创新重磅升级
Use of room database
[binary search] 69 Square root of X
Web APIs DOM节点
Fragment addition failed error lookup
小程序直播+電商,想做新零售電商就用它吧!
2022/7/2 question summary
Applet live + e-commerce, if you want to be a new retail e-commerce, use it!
UE fantasy engine, project structure
Es module and commonjs learning notes
2022上半年全国教师资格证下
object serialization
Yolov5 adds attention mechanism
记录QT内存泄漏的一种问题和解决方案