本文共 1552 字,大约阅读时间需要 5 分钟。
进度条like this
[##############################]100%(这里是小菊花) 实现如下//cpp#include#include #include float f(float x, float y, float z) { float a = x * x + 9.0f / 4.0f * y * y + z * z - 1; return a * a * a - x * x * z * z * z - 9.0f / 80.0f * y * y * z * z * z;}float h(float x, float z) { for (float y = 1.0f; y >= 0.0f; y -= 0.001f) if (f(x, y, z) <= 0.0f) return y; return 0.0f;}void Heart() { for (float z = 1.5f; z > -1.5f; z -= 0.05f) { for (float x = -1.5f; x < 1.5f; x += 0.025f) { float v = f(x, 0.0f, z); if (v <= 0.0f) { float y0 = h(x, z); float ny = 0.01f; float nx = h(x + ny, z) - y0; float nz = h(x, z + ny) - y0; float nd = 1.0f / sqrtf(nx * nx + ny * ny + nz * nz); float d = (nx + ny - nz) * nd * 0.5f + 0.5f; putchar(".:-=+*#%@"[(int)(d * 5.0f)]); } else putchar(' '); } putchar('\n'); }}int main(){ char arr[102]; char* sign = "|/-'\'"; //小菊花的零件 int i = 0; arr[0] = 0; for (i = 0; i <= 100; i++) { printf("[%-100s] [%d%%] %c\r", arr, i, sign[i%3]); Sleep(70); fflush(stdout); //刷新输出 arr[i] = '#'; arr[i + 1] = 0; } printf("\nheart.jpg\n"); Sleep(1000); Heart(); system("pause"); return 0;}
注意的是打印’%’时需要输入两个’%’
每次都需要从开头打印所以是/r 要让右’]’从一开始就放在最右端%-100s 耐心等等里面有惊喜哦(^__^)转载地址:http://qvgbb.baihongyu.com/