当前位置:网站首页>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);
}
}边栏推荐
- To be continued] [UE4 notes] L4 object editing
- Listview is added and deleted at the index
- 发现一个很好的 Solon 框架试手的教学视频(Solon,轻量级应用开发框架)
- Download and use of font icons
- room数据库的使用
- 第六章 数据流建模—课后习题
- Vs2015 secret key
- Haut OJ 1241: League activities of class XXX
- Solon Logging 插件的添加器级别控制和日志器的级别控制
- Collapse of adjacent vertical outer margins
猜你喜欢

YOLOv5添加注意力机制

win10虚拟机集群优化方案
![[paper notes] multi goal reinforcement learning: challenging robotics environments and request for research](/img/17/db8614b177f33ee4f67b7d65a8430f.png)
[paper notes] multi goal reinforcement learning: challenging robotics environments and request for research

Research on the value of background repeat of background tiling

Ue4/ue5 illusory engine, material part (III), material optimization at different distances
![[speed pointer] 142 circular linked list II](/img/f8/222a360c01d8ef120b61bdd2025044.jpg)
[speed pointer] 142 circular linked list II

National teacher qualification examination in the first half of 2022

Use of snippets in vscode (code template)

Count sort

Double pointer Foundation
随机推荐
[to be continued] [depth first search] 547 Number of provinces
[转]:Apache Felix Framework配置属性
YOLOv5-Shufflenetv2
远程升级怕截胡?详解FOTA安全升级
[merge array] 88 merge two ordered arrays
TF-A中的工具介绍
Learning notes of "hands on learning in depth"
sync.Mutex源码解读
Bubble sort summary
记录QT内存泄漏的一种问题和解决方案
National teacher qualification examination in the first half of 2022
Warning using room database: schema export directory is not provided to the annotation processor so we cannot export
Reverse one-way linked list of interview questions
Use of room database
Find a good teaching video for Solon framework test (Solon, lightweight application development framework)
GBase数据库助力湾区数字金融发展
Pointnet++的改进
Pointnet++学习
Es module and commonjs learning notes
Embedded database development programming (zero)