java实现心形图案|桃心

There is something wrong when you use thedouble type minus an int type. Because when you refer to a double type.

Eg. Double 1.0;

Some ide may get the value 1.00000000000

And others may get 0.999999999999999

But they represent the same number.

The same problem here.

So you must find the precise position here.

 

for this we use the function (x^2+y^2-1)^3 - x^2*y^3 = 0;

单个桃心:

       public static void main(String argv[]){
              for(float y = (float) 1.5;y>-1.5;y -=0.1)
              {
                     for(float x= (float) -1.5;x<1.5;x+= 0.05)
                     {
                           float a = x*x+y*y-1;
                           if((a*a*a-x*x*y*y*y)<=0.0)
                           {
                                  
                                  
                                  System.out.print("*");
                           
                           }
                           else
                                  System.out.print(" ");
                     }
                     System.out.print("\n");
              }
       }

for two of the pic

       public static void main(String argv[]){
        for(float y = (float) 1.5;y>-1.5;y -=0.1)
        {
               for(float x= (float) -1.5;x<1.5;x+= 0.05)
               {
                     float a = x*x+y*y-1;
                     if((a*a*a-x*x*y*y*y)<=0.0)
                     {
                           if(Math.abs(x+0.100000712)<=1e-6 && Math.abs(y-0.6999998)<=1e-6)
                           {
                                     System.out.print("F");
                                   continue;
                            }
                           if(Math.abs(x+0.050000306)<=1e-6 && Math.abs(y-0.6999998)<=1e-6)
                            {
                                   System.out.print("r");
                                   continue;
                            }
                            if(Math.abs(x+-3.0621885E-7)<=1e-6 && Math.abs(y-0.6999998)<=1e-6)
                            {
                                   System.out.print("a");
                                   continue;
                            }
                            if(Math.abs(x-0.049999695)<=1e-6 && Math.abs(y-0.6999998)<=1e-6)
                            {
                                   System.out.print("n");
                                   continue;
                            }
                            if(Math.abs(x-0.100000001)<=1e-6 && Math.abs(y-0.6999998)<=1e-6)
                            {
                                   System.out.print("k");
                                   continue;
                            }
                            
                            System.out.print("*");
                     
                     }
                     else
                            System.out.print(" ");
               }
               
               for(float x= (float) 1.5;x<4.5;x+= 0.05)
               {
                     float a = (x-3)*(x-3)+y*y-1;
                     boolean flag = false;
                     if((a*a*a-(x-3)*(x-3)*y*y*y)<=0.0)
                     {
                           if(Math.abs(x-3+0.100000712)<=1e-6 && Math.abs(y-0.6999998)<=1e-6)
                           {
                                     System.out.print("C");
                                     flag = true;
                                   continue;
                            }
                           if((Math.abs(x-2.9499986)) <= 1e-6 && Math.abs(y-0.6999998)<=1e-6 )
                            {
                                   System.out.print("a");
                                   continue;
                            }
                            if(Math.abs(x-2.9999986)<=1e-6 && Math.abs(y-0.6999998)<=1e-6)
                            {
                                   System.out.print("s");
                                   continue;
                            }
                            if(Math.abs(x-3.0499985)<=1e-6 && Math.abs(y-0.6999998)<=1e-6)
                            {
                                   System.out.print("i");
                                   continue;
                            }
                            if(Math.abs(x-3.0999985)<=1e-6 && Math.abs(y-0.6999998)<=1e-6)
                            {
                                   System.out.print("o");
                                   continue;
                            }
                            
                            System.out.print("*");
                     
                     }
                     else
                            System.out.print(" ");
               }
               
               System.out.print("\n");
        }
       }


  • 15
    点赞
  • 35
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值