admin 管理员组

文章数量: 887031


2024年1月26日发(作者:二郎神图片大全)

/* 代码来源于:/liuyubobobo/heart-curve-cplusplus/blob/master/ */#include #include // The first heart shape in hollow// (x^2+y^2-1)^3 - x^2*y^3 = 0// y ~ (-1.1 , 1.3 )// x ~ (-1.2 , 1.2 )int main() { for( float y = 1.3 ; y >= -1.1 ; y -= 0.06 ) { for( float x = -1.2 ; x <= 1.2 ; x += 0.025 ) { if( pow((x*x+y*y-1.0),3) - x*x*y*y*y <= 0.0 ) printf(" "); else printf("*"); } printf("n"); } return 0;}

#include

int main(int argc, char *argv[])

{

float f, x, y, z;

for(y=1.5f; y>-1.5f; y-=0.1f)

{

for(x=-1.5f; x<1.5f; x+=0.05f)

{

z = x*x+y*y-1;

f = z*z*z-x*x*y*y*y;

// =================================== printf("033[47m"); char buf[100] = {"happybirthday"}; if (f<=0.0f) { printf("033[1;31m%c033[0m", buf[(int)(f*-8.0f)]); } else { printf("%c", ' '); } printf("033[0m"); // ===================================== }

printf("n");

}

return 0;

}

加强版:

#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;}int main(int argc, char *argv[])

{ 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'); }}

变形版:


本文标签: 图片 来源于 作者 代码 二郎神