码迷,mamicode.com
首页 > 编程语言 > 详细

用python画一颗彩虹色爱心送给女朋友!!!

时间:2019-03-14 00:49:10      阅读:342      评论:0      收藏:0      [点我收藏+]

标签:lib   nump   imp   atp   lam   app   pip3   http   code   

1.准备工作:

       代码中用到numpy和matplotlib,需要先安装这两个库

       pip3 install numpypip3 install matplotlib

       会用到的数学公式:(x^2+y^2-1)^3+x^2*y^3=0

2.编写代码:

      importnumpy asnp

      importmatplotlib.pyplot asplt

      x_coords = np.linspace(- 100, 100, 500)

      y_coords = np.linspace(- 100, 100, 500)

      points = []

      fory iny_coords:

      forx inx_coords:

      if((x* 0.03)** 2+(y* 0.03)** 2- 1)** 3-(x* 0.03)** 2*(y* 0.03)** 3<= 0:

     points.append({ "x": x, "y": y})

     heart_x = list(map( lambdapoint: point[ "x"], points))

     heart_y = list(map( lambdapoint: point[ "y"], points))

     plt.scatter(heart_x, heart_y, s= 10, alpha= 0.5,c=range(len(heart_x)), cmap=<cmap>)

     plt.show()

     运行后上面的代码会显示下面的图

技术图片

     这样我们的彩虹色爱心就出来了。

       

 

用python画一颗彩虹色爱心送给女朋友!!!

标签:lib   nump   imp   atp   lam   app   pip3   http   code   

原文地址:https://www.cnblogs.com/gsd-tt/p/10527379.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!