用python绘制一朵玫瑰花送给心上人

您所在的位置:网站首页 送给妈妈画一朵鲜花怎么画 用python绘制一朵玫瑰花送给心上人

用python绘制一朵玫瑰花送给心上人

2023-03-18 09:08| 来源: 网络整理| 查看: 265

生活需要仪式感,没有艺术细胞,那就用代码画朵玫瑰花聊表心意吧!

一、三维绘制

代码如下:

from matplotlib import cm import matplotlib.pyplot as plt import numpy as np fig=plt.figure() ax=fig.gca(projection='3d') [x,t]=np.meshgrid(np.array(range(25))/24.0,np.arange(0,575.5,0.5)/575*17*np.pi-2*np.pi) p=(np.pi/2)*np.exp(-t/(8*np.pi)) u=1-(1-np.mod(3.6*t,2*np.pi)/np.pi)**4/2 y=2*(x**2-x)**2*np.sin(p) r=u*(x*np.sin(p)+y*np.cos(p)) surf=ax.plot_surface(r*np.cos(t),r*np.sin(t),u*(x*np.cos(p)-y*np.sin(p)),rstride=1,cstride=1,cmap=cm.gist_rainbow_r, linewidth=0,antialiased=True) plt.show()

不满意?那就再来一朵。

二、turtle库绘制

代码如下: # Rose.py #coding:utf-8 import turtle as t t.setup(1000,1000) t.hideturtle() t.speed(11) t.penup() t.goto(50,-450) t.pensize(5) t.pencolor("black") t.seth(140) t.pendown() t.speed(10) t.circle(-300,60) t.fd(100) #绘制第一片叶子 t.seth(10) t.fd(50) t.fillcolor("green") t.begin_fill() t.right(40) t.circle(120,80) t.left(100) t.circle(120,80) t.end_fill() t.seth(10) t.fd(90) t.speed(11) t.penup() t.fd(-140) t.seth(80) #绘制第二片叶子 t.pendown() t.speed(10) t.fd(70) t.seth(160) t.fd(50) t.fillcolor("green") t.begin_fill() t.right(40) t.circle(120,80) t.left(100) t.circle(120,80) t.end_fill() t.seth(160) t.fd(90) t.speed(11) t.penup() t.fd(-140) t.seth(80) t.pendown() t.speed(10) t.fd(100) #绘制第一瓣花朵 t.seth(-20) t.fillcolor("crimson") t.begin_fill() t.circle(100,100) t.circle(-110,70) t.seth(179) t.circle(223,76) t.end_fill() #绘制第二瓣花朵 t.speed(11) t.fillcolor("red") t.begin_fill() t.left(180) t.circle(-223,60) t.seth(70) t.speed(10) t.circle(-213,15) t.left(70) t.circle(200,70) t.seth(-80) t.circle(-170,40) t.circle(124,94) t.end_fill() t.speed(11) t.penup() t.right(180) t.circle(-124,94) t.circle(170,40) t.pendown() t.speed(10) t.seth(-60) t.circle(175,70) t.seth(235) t.circle(300,12) t.right(180) t.circle(-300,12) t.seth(125) t.circle(150,60) t.seth(70) t.fd(-20) t.fd(20) t.seth(-45) t.circle(150,40) t.seth(66) t.fd(-18.5) t.fd(18.5) t.seth(140) t.circle(150,27) t.seth(60) t.fd(-8) t.speed(11) t.penup() t.left(20.8) t.fd(-250.5) #绘制第三瓣花朵 t.pendown() t.speed(10) t.fillcolor("crimson") t.begin_fill() t.seth(160) t.circle(-140,85) t.circle(100,70) t.right(165) t.circle(-200,32) t.speed(11) t.seth(-105) t.circle(-170,14.5) t.circle(123,94) t.end_fill() t.done()

参考:代码非原创,老祖宗代码



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3