求問怎樣用python/python turtle畫“心”呢?

來源:互聯網
上載者:User
剛剛起步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 += stepelif step < 0:while start > end:yield start start += stepelse: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.01nx = 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.5sys.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 < 1000:
j = 0
while j < 1000:
x = -1.8 + 0.003*i
y = -1.4 + 0.0028*j
z = y**2 + (-x - (y**2)**0.33333)**2
if z <= 1:
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()
  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.