作者:wsg
时间;8月14日
//版本一:单个字符的心形图案
#include int main(void)
{
float a,x,y;
for(y=1.5f; y>-1.5f; y-=0.1f)
{
for(x=-1.5f; x<1.5f; x+=0.05f)
{
a = x*x+y*y-1;
//这里的@符号即为打印出的心形图案符号,可更改
char ch = a*a*a-x*x*y*y*y<=0.0f?@: ;
putchar(ch);
//或者putchar(a*a*a-x*x*y*y*y<=0.0f?*: );
}
printf("\n");
}
return 0;
}
空心版:
/* 代码来源于:/liuyubobobo/heart-curve-cplusplus/blob/master/main2.cpp */
#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