C++命令行画心形<转载>

#include <stdio.h>

int main()
{
for (float y = 1.5f; y > -1.5f; y -= 0.1f)
{
for (float x = -1.5f; x < 1.5f; x += 0.05f)
{
float z = x * x + y * y - ;
float f = z * z * z - x * x * y * y * y;
putchar(f <= 0.0f ? ".:-=+*#%@"[(int)(f * -8.0f)] : ' ');
} putchar('\n');
}
}
#include <stdio.h>

int main()
{
for (float y = 1.5f; y > -1.5f; y -= 0.1f)
{
for (float x = -1.5f; x < 1.5f; x += 0.05f)
{
float z = x * x + y * y - ;
float f = z * z * z - x * x * y * y * y;
putchar(f <= 0.0f ? ".:-=+*#%@"[(int)(f * -8.0f)] : ' ');
} putchar('\n');
}
}
#include <stdio.h>
#include <math.h> float f(float x, float y, float z)
{
float a = x * x + 9.0f / 4.0f * y * y + z * z - ; 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;
} int main()
{
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');
}
}
#include <math.h>

float f(float x, float y, float z)
{
float a = x * x + 9.0f / 4.0f * y * y + z * z - ; 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;
} int main()
{
FILE* fp = fopen("heart.ppm", "w");
int sw = , sh = ;
fprintf(fp, "P3\n%d %d\n255\n", sw, sh); for (int sy = ; sy < sh; sy++)
{
float z = 1.5f - sy * 3.0f / sh;
for (int sx = ; sx < sw; sx++)
{
float x = sx * 3.0f / sw - 1.5f;
float v = f(x, 0.0f, z);
int r = ;
if (v <= 0.0f)
{
float y0 = h(x, z);
float ny = 0.001f;
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) / sqrtf() * nd * 0.5f + 0.5f;
r = (int)(d * 255.0f);
} fprintf(fp, "%d 0 0 ", r);
} fputc('\n', fp);
}
fclose(fp);
}
#include <stdio.h>
#include <math.h>
#include <windows.h>
#include <tchar.h> float f(float x, float y, float z)
{
float a = x * x + 9.0f / 4.0f * y * y + z * z - ; 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;
} int main()
{
HANDLE o = GetStdHandle(STD_OUTPUT_HANDLE);
_TCHAR buffer[][] = { _T(' ') };
_TCHAR ramp[] = _T(".:-=+*#%@"); for (float t = 0.0f;; t += 0.1f)
{
int sy = ;
float s = sinf(t);
float a = s * s * s * s * 0.2f;
for (float z = 1.3f; z > -1.2f; z -= 0.1f)
{
_TCHAR* p = &buffer[sy++][];
float tz = z * (1.2f - a);
for (float x = -1.5f; x < 1.5f; x += 0.05f)
{
float tx = x * (1.2f + a);
float v = f(tx, 0.0f, tz);
if (v <= 0.0f)
{
float y0 = h(tx, tz);
float ny = 0.01f;
float nx = h(tx + ny, tz) - y0;
float nz = h(tx, tz + ny) - y0;
float nd = 1.0f / sqrtf(nx * nx + ny * ny + nz * nz);
float d = (nx + ny - nz) * nd * 0.5f + 0.5f;
*p++ = ramp[(int)(d * 5.0f)];
}
else
*p++ = ' ';
}
} for (sy = ; sy < ; sy++)
{
COORD coord = { , sy };
SetConsoleCursorPosition(o, coord);
WriteConsole(o, buffer[sy], , NULL, );
}
Sleep();
}
}
#include<stdio.h>
#include <Windows.h>
#include <math.h>
#define Maxnum 1800
#define PI 3.1415926
int Nownum;
char *buff[Maxnum]; void main()
{
void SetToNum(int SetNum);//300M 每格子 共9个格子
Nownum=;
int ix;ix=;
DWORD startTime = ;
double x=-1.11;
double y=;
startTime = GetTickCount(); //毫秒数 while()
{
if ( ((GetTickCount() - startTime)%) <= ){
if (ix%==){
y=((pow(abs(x),2.0/)+sqrt(pow(abs(x),4.0/)-*(x*x-)))/);// x^(2)^(1/3)/2+sqrt(x^(4)^(1/3)-4*(x^2-1))/2;//y+
}
else{
y=((pow(abs(x),2.0/)-sqrt(pow(abs(x),4.0/)-*(x*x-)))/);// x^(2)^(1/3)/2-sqrt(x^(4)^(1/3)-4*(x^2-1))/2;//y-
} SetNum=(int)Maxnum/*(+y/1.3);
SetToNum(SetNum); x=x+0.1;ix++;
if (x>1.11){SetNum=;SetToNum(SetNum);x=-1.11;printf("Pauseing:10s\n");Sleep();}
printf("Nownum:%d(%f)\n" ,Nownum,x);
}
} } void SetToNum(int SetNum)
{
if (SetNum>Maxnum){printf("Error:SetNum>MaxNum!\n");return;}
if (Nownum<SetNum)
{
for (Nownum++;Nownum<=SetNum;Nownum++)
{
buff[Nownum]= new char[*];
}
Nownum--;
}
else if (Nownum>SetNum)
{
for (;Nownum>SetNum;Nownum--)
{
delete buff[Nownum];
}
}
}

文章来源:https://www.zhihu.com/people/miloyip/activities

上一篇:mybatis sql参考


下一篇:【7】python核心编程 第十一章-函数和函数式编程