import turtle //導(dǎo)入模塊
10年積累的成都做網(wǎng)站、網(wǎng)站建設(shè)經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先網(wǎng)站設(shè)計(jì)后付款的網(wǎng)站建設(shè)流程,更有遼中免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
import time
import os
def draw_square(org_x, org_y, x, y): //定義紅旗繪制函數(shù)
turtle.setpos(org_x, org_y) //定義畫筆初始位置
turtle.color('red', 'red') //顏色
turtle.begin_fill() //開始繪制
turtle.fd(x) //繪制偏轉(zhuǎn)方向和角度
turtle.lt(90)
turtle.fd(y)
turtle.lt(90)
turtle.fd(x)
turtle.lt(90)
turtle.fd(y)
turtle.end_fill() //繪制結(jié)束
def draw_star(center_x, center_y, radius): //定義星星繪制函數(shù)
print(center_x, center_y) //顯示位置
turtle.pencolor('black') //畫筆軌跡顏色
turtle.setpos(center_x, center_y) //中心點(diǎn)位置
pt1 = turtle.pos() //偏轉(zhuǎn)角度計(jì)算
turtle.circle(-radius, 360 / 5)
pt2 = turtle.pos()
turtle.circle(-radius, 360 / 5)
pt3 = turtle.pos()
turtle.circle(-radius, 360 / 5)
pt4 = turtle.pos()
turtle.circle(-radius, 360 / 5)
pt5 = turtle.pos()
turtle.color('yellow', 'yellow') //星星顏色
turtle.begin_fill() //開是繪制
turtle.goto(pt3)
turtle.goto(pt1)
turtle.goto(pt4)
turtle.goto(pt2)
turtle.goto(pt5)
turtle.end_fill() //繪制結(jié)束
print(turtle.pos())
turtle.pu() //隱藏畫筆軌跡
draw_square(-320, -260, 660, 440) //繪制紅旗
star_part_x = -320 //自定義星星大小等屬性
star_part_y = -260 + 440
star_part_s = 660 / 30
center_x, center_y = star_part_x + star_part_s * 5, star_part_y - star_part_s * 5 //計(jì)算星星中心點(diǎn)位置
turtle.setpos(center_x, center_y)
turtle.lt(90)
draw_star(star_part_x + star_part_s * 5, star_part_y - star_part_s * 2, star_part_s * 3) //繪制星星
turtle.goto(star_part_x + star_part_s * 10, star_part_y - star_part_s * 2) //同上
turtle.lt(round(turtle.towards(center_x, center_y)) - turtle.heading())
turtle.fd(star_part_s)
turtle.rt(90)
draw_star(turtle.xcor(), turtle.ycor(), star_part_s)
turtle.goto(star_part_x + star_part_s * 12, star_part_y - star_part_s * 4)
turtle.lt(round(turtle.towards(center_x, center_y)) - turtle.heading())
turtle.fd(star_part_s)
turtle.rt(90)
draw_star(turtle.xcor(), turtle.ycor(), star_part_s)
turtle.goto(star_part_x + star_part_s * 12, star_part_y - star_part_s * 7)
turtle.lt(round(turtle.towards(center_x, center_y)) - turtle.heading())
turtle.fd(star_part_s)
turtle.rt(90)
draw_star(turtle.xcor(), turtle.ycor(), star_part_s)
turtle.goto(star_part_x + star_part_s * 10, star_part_y - star_part_s * 9)
turtle.lt(round(turtle.towards(center_x, center_y)) - turtle.heading())
turtle.fd(star_part_s)
turtle.rt(90)
draw_star(turtle.xcor(), turtle.ycor(), star_part_s)
turtle.ht()
time.sleep(5) //設(shè)置掛起時(shí)間
os._exit(1)
首先要學(xué)會(huì)python,不然有程序也看不明白啊。
然后就是看你要畫什么樣的了。簡(jiǎn)單的5條線就ok。下面的程序就送你一顆星星。雖然沒有天上的那么亮。:)
from?matplotlib?import?pyplot?as?plt
import?numpy?as?np
r?=?4.0
def?circle_p(r,d):
return?[r*np.sin(d/180.0*np.pi),r*np.cos(d/180.0*np.pi)]
wjx_p?=?[circle_p(r,i*72)?for?i?in?range(7)]
for?i?in?range(5):
x?=?[wjx_p[i][0],?wjx_p[i+2][0]]
y?=?[wjx_p[i][1],?wjx_p[i+2][1]]
plt.plot(x,y,'r')
plt.show()
想學(xué)python可以搜搜我的課程,用python做些事。
打開電腦,安裝python3.6,打開Idle;進(jìn)入Python語言編程環(huán)境后,點(diǎn)File(文件)下面的New file,新建一個(gè)文件;出現(xiàn)一個(gè)以u(píng)ntitled為默認(rèn)文件名的窗口,下面是個(gè)空白的編輯頁(yè)面;在空白的編輯頁(yè)面處輸入代碼;選定一個(gè)保存位置,并給程序命名。
turtle.seth(angle):只改變海龜?shù)男羞M(jìn)方向(角度按逆時(shí)針),但不行進(jìn),angle為絕對(duì)度數(shù)
for?i?in?range(1,10):
if?(i=5):
x=i
else:
x=10-i
for?j?in?range(1,x+1):
print("*",end='')
print("\n")
1 from turtle import * 2 def curvemove(): #這個(gè)函數(shù)是為了繪制愛心上方的曲線 3 for i in range(200): 4 right(1) 5 fd(1) 6 7 pensize(2) #調(diào)整畫筆粗細(xì) 8 speed(10) #調(diào)節(jié)畫筆速度 9 color(‘red‘,‘red‘) #畫筆顏色及填充顏色10 begin_fill() #開始填充11 left(140)12 fd(111.65)13 curvemove() #調(diào)用函數(shù)14 left(120)15 curvemove() #調(diào)用函數(shù)16 fd(111.65)17 end_fill() #結(jié)束填充18 hideturtle() #隱藏畫筆19 done()