您好,欢迎访问一九零五行业门户网

求问怎样用python/python turtle画“心”呢?

刚刚起步python,觉得python turtle真是萌神一般的存在呀~ 试着画了颗“心”,不过觉得方法实在是太笨了>
回复内容:from turtle import *def curvemove(): for i in range(200): right(1) forward(1)color('red','pink') begin_fill()left(140)forward(111.65)curvemove()left(120)curvemove()forward(111.65)end_fill()done()
from turtle import *from turtle import *
pensize(1)
color('black','red')
speed(2)
up()
goto(-12,100)
down()
begin_fill()
left(90)
circle(120,180)
circle(360,70.529)
left(38.942)
circle(360,70.529)
circle(120,180)
end_fill()
up()
goto(-250,-150)
down()from pylab import*t=linspace(0,2*pi,100)x=sin(2*t) + 2*sin(t)y=-cos(2*t)-2*cos(t)fill(x,y,'r')show()
心没画,玫瑰花倒是有一个之前忘了帖代码,现在补上。之前忘了帖代码,现在补上。
for i in range (1):
def paint(ang,r,ang2): #画图函数
turtle.penup()
turtle.setheading(ang)
turtle.pendown()
turtle.circle(r,ang2)
import turtle
turtle.speed(9)
turtle.color(white) #设置
turtle.pensize(7)
turtle.penup()
turtle.goto(50,-50)
turtle.pendown()
turtle.dot(200,pink) #画背景
turtle.penup()
turtle.goto(50,86.6)
ang=-150
r=300
ang2=46
for j in range (21): #循环
paint(ang,r,ang2) #画弧
ang2-=25
paint(ang+ang2+25,r,-ang2) #回退
ang2+=25
ang+=66
r=r*0.9
思路大概就是:画圆弧,回退大约1/3,转向,减小半径,画圆弧......一直循环...
视频传送门python玫瑰花_生活
提醒我贴代码的那个小同学,我看了你资料,看来你和我一个学校而且选的同一个选修课呢。不过我这个作业交过了,所以你参考一下,不懂的可以问我。
照抄的话老师会打你屁屁的
(╯‵□′)╯︵┻━┻。35道哪个不会可以私信我。我给你思路~不过最近考试周,我不一定都能帮得上忙。。。
--------------15.12.31-----------------import sysimport math def frange(start, end, step=1.0): if step > 0: while start end: yield start start += step elif step 0: while start > end: yield start start += step else: raise valueerror('range() step must not be zero')def f(x, y, z): a = x*x + 9.0/4*y*y + z*z - 1 return a*a*a - x*x*z*z*z - 9.0/80*y*y*z*z*z def h(x, z): for y in frange(1.0, 0.0, -0.001): if f(x, y, z) 0: return y return 0.0if __name__ == '__main__': for z in frange(1.5, -1.5, -0.1): for x in frange(-1.5, 1.5, 0.05): v = f(x, 0, z) if v 0: y0 = h(x, z) ny = 0.01 nx = h(x + ny, z) - y0 nz = h(x, z + ny) - y0 nd = 1.0/math.sqrt(nx*nx+ny*ny+nz*nz) d = (nx + ny - nz)*nd*0.5 + 0.5 sys.stdout.write('.:-=+*#%@'[int(d*5)]) else: sys.stdout.write(' ') sys.stdout.write('\n')
用python matplotlib画笛卡尔的心形线
import numpy as npimport numpy as np
import pylab as plt
from matplotlib import colors
a = [[] for i in range(1000)]
i = 0
while i j = 0
while j x = -1.8 + 0.003*i
y = -1.4 + 0.0028*j
z = y**2 + (-x - (y**2)**0.33333)**2
if z a[i].append(0.9)
else:
a[i].append(0.0)
j = j + 1
i = i + 1
cmap = colors.listedcolormap(['white', 'pink'])
im = plt.imshow(a, cmap = cmap, interpolation=bicubic )
plt.show()
其它类似信息

推荐信息