当前位置:网站首页>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
-lgdi32
Code:
#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);
}
}
边栏推荐
- 支持多模多态 GBase 8c数据库持续创新重磅升级
- Shell Sort
- Haut OJ 1221: a tired day
- Pause and resume of cocos2dx Lua scenario
- Applet Live + e - commerce, si vous voulez être un nouveau e - commerce de détail, utilisez - le!
- 十年不用一次的JVM调用
- Simple HelloWorld color change
- A complete attack chain
- Haut OJ 1352: string of choice
- Research on the value of background repeat of background tiling
猜你喜欢
Ue4/ue5 illusory engine, material chapter, texture, compression and memory compression and memory
[to be continued] [UE4 notes] L3 import resources and project migration
lxml.etree.XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8
Learning notes of "hands on learning in depth"
对象的序列化
Count sort
Ue4/ue5 illusory engine, material part (III), material optimization at different distances
Page countdown
TF-A中的工具介绍
win10虚拟机集群优化方案
随机推荐
Introduction to memory layout of FVP and Juno platforms
[转]:Apache Felix Framework配置属性
[leetcode] integer inversion [7]
[binary search] 69 Square root of X
Haut OJ 1245: large factorial of CDs --- high precision factorial
Add level control and logger level control of Solon logging plug-in
PMP考试敏捷占比有多少?解疑
lxml.etree.XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8
Haut OJ 1218: maximum continuous sub segment sum
Haut OJ 1241: League activities of class XXX
Web APIs DOM节点
[to be continued] [UE4 notes] L3 import resources and project migration
cocos_ Lua loads the file generated by bmfont fnt
To the distance we have been looking for -- film review of "flying house journey"
Bucket sort
Embedded database development programming (VI) -- C API
[allocation problem] 455 Distribute cookies
Solon Logging 插件的添加器级别控制和日志器的级别控制
Haut OJ 1316: sister choice buys candy III
Embedded database development programming (V) -- DQL