-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
154 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"cache_date": "2024-05-29", "page_authors": {}} | ||
{"cache_date": "2024-06-02", "page_authors": {}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
--- | ||
title: 甜甜圈代码🍩 | ||
# 隐藏的模块 | ||
hide: | ||
# - navigation # 隐藏左边导航 | ||
# - toc #隐藏右边导航 | ||
# - footer #隐藏翻页 | ||
# - feedback #隐藏反馈 | ||
tags: | ||
- 技术分享 | ||
comments: false #评论,默认不开启 | ||
--- | ||
|
||
[![image.gif](https://i.postimg.cc/ryGZvqbN/image.gif)](https://postimg.cc/HjxtM1Tr) | ||
|
||
代码如下 | ||
```c title="math.py" | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
|
||
#define R(mul,shift,x,y) \ | ||
_=x; \ | ||
x -= mul*y>>shift; \ | ||
y += mul*_>>shift; \ | ||
_ = 3145728-x*x-y*y>>11; \ | ||
x = x*_>>10; \ | ||
y = y*_>>10; | ||
|
||
int8_t b[1760], z[1760]; | ||
|
||
int main() { | ||
int sA=1024,cA=0,sB=1024,cB=0,_; | ||
for (;;) { | ||
memset(b, 32, 1760); // text buffer | ||
memset(z, 127, 1760); // z buffer | ||
int sj=0, cj=1024; | ||
for (int j = 0; j < 90; j++) { | ||
int si = 0, ci = 1024; // sine and cosine of angle i | ||
for (int i = 0; i < 324; i++) { | ||
int R1 = 1, R2 = 2048, K2 = 5120*1024; | ||
|
||
int x0 = R1*cj + R2, | ||
x1 = ci*x0 >> 10, | ||
x2 = cA*sj >> 10, | ||
x3 = si*x0 >> 10, | ||
x4 = R1*x2 - (sA*x3 >> 10), | ||
x5 = sA*sj >> 10, | ||
x6 = K2 + R1*1024*x5 + cA*x3, | ||
x7 = cj*si >> 10, | ||
x = 40 + 30*(cB*x1 - sB*x4)/x6, | ||
y = 12 + 15*(cB*x4 + sB*x1)/x6, | ||
N = (-cA*x7 - cB*((-sA*x7>>10) + x2) - ci*(cj*sB >> 10) >> 10) - x5 >> 7; | ||
|
||
int o = x + 80 * y; | ||
int8_t zz = (x6-K2)>>15; | ||
if (22 > y && y > 0 && x > 0 && 80 > x && zz < z[o]) { | ||
z[o] = zz; | ||
b[o] = ".,-~:;=!*#$@"[N > 0 ? N : 0]; | ||
} | ||
R(5, 8, ci, si) // rotate i | ||
} | ||
R(9, 7, cj, sj) // rotate j | ||
} | ||
for (int k = 0; 1761 > k; k++) | ||
putchar(k % 80 ? b[k] : 10); | ||
R(5, 7, cA, sA); | ||
R(5, 8, cB, sB); | ||
usleep(15000); | ||
printf("\x1b[23A"); | ||
} | ||
} | ||
``` | ||
|
||
然后 | ||
`gcc math.c -o math` | ||
|
||
`./math` | ||
|
||
| ||
感兴趣的可以去研究背后的数学知识,地址:[donut.c without a math library](https://www.a1k0n.net/2021/01/13/optimizing-donut.html) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
|
||
#define R(mul,shift,x,y) \ | ||
_=x; \ | ||
x -= mul*y>>shift; \ | ||
y += mul*_>>shift; \ | ||
_ = 3145728-x*x-y*y>>11; \ | ||
x = x*_>>10; \ | ||
y = y*_>>10; | ||
|
||
int8_t b[1760], z[1760]; | ||
|
||
int main() { | ||
int sA=1024,cA=0,sB=1024,cB=0,_; | ||
for (;;) { | ||
memset(b, 32, 1760); // text buffer | ||
memset(z, 127, 1760); // z buffer | ||
int sj=0, cj=1024; | ||
for (int j = 0; j < 90; j++) { | ||
int si = 0, ci = 1024; // sine and cosine of angle i | ||
for (int i = 0; i < 324; i++) { | ||
int R1 = 1, R2 = 2048, K2 = 5120*1024; | ||
|
||
int x0 = R1*cj + R2, | ||
x1 = ci*x0 >> 10, | ||
x2 = cA*sj >> 10, | ||
x3 = si*x0 >> 10, | ||
x4 = R1*x2 - (sA*x3 >> 10), | ||
x5 = sA*sj >> 10, | ||
x6 = K2 + R1*1024*x5 + cA*x3, | ||
x7 = cj*si >> 10, | ||
x = 40 + 30*(cB*x1 - sB*x4)/x6, | ||
y = 12 + 15*(cB*x4 + sB*x1)/x6, | ||
N = (-cA*x7 - cB*((-sA*x7>>10) + x2) - ci*(cj*sB >> 10) >> 10) - x5 >> 7; | ||
|
||
int o = x + 80 * y; | ||
int8_t zz = (x6-K2)>>15; | ||
if (22 > y && y > 0 && x > 0 && 80 > x && zz < z[o]) { | ||
z[o] = zz; | ||
b[o] = ".,-~:;=!*#$@"[N > 0 ? N : 0]; | ||
} | ||
R(5, 8, ci, si) // rotate i | ||
} | ||
R(9, 7, cj, sj) // rotate j | ||
} | ||
for (int k = 0; 1761 > k; k++) | ||
putchar(k % 80 ? b[k] : 10); | ||
R(5, 7, cA, sA); | ||
R(5, 8, cB, sB); | ||
usleep(15000); | ||
printf("\x1b[23A"); | ||
} | ||
} |