当前位置:网站首页>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);
}
}
边栏推荐
- [allocation problem] 135 Distribute candy
- [to be continued] [UE4 notes] L3 import resources and project migration
- Yolov5 ajouter un mécanisme d'attention
- [转]MySQL操作实战(一):关键字 & 函数
- The present is a gift from heaven -- a film review of the journey of the soul
- 软件测试 -- 0 序
- FVP和Juno平台的Memory Layout介绍
- Improvement of pointnet++
- 发现一个很好的 Solon 框架试手的教学视频(Solon,轻量级应用开发框架)
- [turn to] MySQL operation practice (III): table connection
猜你喜欢
Learning notes of "hands on learning in depth"
Ue4/ue5 illusory engine, material chapter, texture, compression and memory compression and memory
小程序直播+電商,想做新零售電商就用它吧!
Applet Live + e - commerce, si vous voulez être un nouveau e - commerce de détail, utilisez - le!
Service fusing hystrix
A new micro ORM open source framework
[转]: OSGI规范 深入浅出
YOLOv5-Shufflenetv2
Data is stored in the form of table
[turn to] MySQL operation practice (III): table connection
随机推荐
[depth first search] 695 Maximum area of the island
JVM call not used once in ten years
Bucket sort
YOLOv5添加注意力機制
[turn to] MySQL operation practice (III): table connection
被舆论盯上的蔚来,何时再次“起高楼”?
Insert sort
xftp7与xshell7下载(官网)
cocos2dx_ Lua particle system
Yolov5 ajouter un mécanisme d'attention
发现一个很好的 Solon 框架试手的教学视频(Solon,轻量级应用开发框架)
[turn to] MySQL operation practice (I): Keywords & functions
【论文笔记】Multi-Goal Reinforcement Learning: Challenging Robotics Environments and Request for Research
Embedded database development programming (V) -- DQL
Double pointer Foundation
Haut OJ 1243: simple mathematical problems
Lua wechat avatar URL
Download xftp7 and xshell7 (official website)
A preliminary study of sdei - see the essence through transactions
Generate filled text and pictures