【圣诞树】
圣誕樹
- 圣誕樹
圣誕樹
代碼如下:
#include <math.h> #include <stdio.h> #include <stdlib.h> #include<Windows.h> #define PI 3.14159265359 #define T x + sl * r * cosf(th), y + sl * r * sin(th) float X, Y; float cir(float x, float y, float r) {return sqrtf((x - X) * (x - X) + (y - Y) * (y - Y)) - r; } float un(float d1, float d2) {return d1 < d2 ? d1 : d2; } float f(float x, float y, float th, float sl, int n) {float d = 0.0f;for (float r = 0.0f; r < 0.8f; r += 0.02f)d = un(d, cir(T, 0.05f * sl * (0.95f - r)));if (n > 0)for (int t = -1; t <= 1; t += 2) {float tt = th + t * 1.8f, ss = sl * 0.9f;for (float r = 0.2f; r < 0.8f; r += 0.1f) d = un(d, f(T, tt, ss * 0.5f, n - 1)), ss *= 0.8f;}return d; } int main(int argc, char *argv[]) {system("color A");int n = argc > 1 ? atoi(argv[1]) : 3;for (Y = 0.8f; Y > 0.0f; Y -= 0.02f, putchar('\n'))for (X = -0.35f; X < 0.35f; X += 0.01f) putchar(f(0, 0, PI * 0.5f, 1.0f, n) < 0 ? '*' : ' '); }可以根據自己喜好去改變圣誕樹的顏色。(system(“color xx”);)
第一個對應于背景,第二個對應于前景。
可以為以下任何值:
0=黑色
1=藍色
2=綠色
3=湖藍色
4=紅色
5=紫色
6=黃色
7=白色
8=灰色
9=亮藍色
A=亮綠色
B=亮湖藍色
C=亮紅色
D=亮紫色
E=亮黃色
F=亮白色
例如,用 system(“color 0A”); 其中color后面的0是背景顏色(黑色),A是字體顏色(綠色)。
實現效果如下:
總結
- 上一篇: [导入]山寨也疯狂:前卫手表造型 Coo
- 下一篇: 麻省理工学院智能探索计划,旨在探索人类智