㈠ 怎麼用python畫三角形並填色以及畫五角星並且填色(急!!!)
可以. 用fill='#XXXXXX'參數:
from Tkinter import Tk, Canvas, Frame, BOTH
from math import sin, pi,cos
def pentagramPoints(cx, cy, R):
xita = 36*pi/180
r = R*cos(2*xita)/cos(xita)
points = []
for i in range(0, 10):
angle = i*xita + 0.5*xita
if i % 2:
points+=[cx + r*cos(angle), cy - r*sin(angle)]
else:
points+=[cx + R*cos(angle), cy - R*sin(angle)]
return points
if __name__ == '__main__':
root = Tk()
f = Frame(root)
f.pack(fill=BOTH, expand=1)
canvas = Canvas(f)
canvas.create_polygon(30, 10, 160, 470, 290, 10, outline="#000000", fill="#00ff00", width=3)
canvas.create_polygon(pentagramPoints(480, 240, 100), outline = '#000000', fill='#ff0000', width=3)
canvas.pack(fill=BOTH, expand=1)
root.geometry("640x480+300+300")
root.mainloop()
㈡ python中怎麼把五角星畫在中間
fromturtleimport*
fillcolor("red")
begin_fill()
whileTrue:
forward(200)
right(144)
ifabs(pos())<1:
break
end_fill()
運行這段代碼,會繪制出一個紅色五角星圖形。
碼字不易,望採納。
㈢ 請問如何用Python turtle畫一個多角星
一般是要靠算角度的
import turtle
import time
turtle.forward(100)
turtle.right(144)
time.sleep(1)
turtle.forward(100)
turtle.right(144)
time.sleep(1)
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
time.sleep(1)
turtle.right(144)
turtle.forward(100)
time.sleep(3)
你可以寫一個子函數通過給定的角的數量用公式計算出角度再代入上述代碼的角度參數里就OK了
㈣ 如何用Python寫星星符號
foriinrange(1,10):
if(i<=5):
x=i
else:
x=10-i
forjinrange(1,x+1):
print("*",end='')
print(" ")
㈤ 如何用python的turtle畫五角星
turtle.seth(angle):只改變海龜的行進方向(角度按逆時針),但不行進,angle為絕對度數
㈥ Python中如何畫一個畫筆顏色為黃色的五角星,邊長為200,畫布背景顏色為黑色,畫
import turtle
turtle.bgcolor("black")
turtle.pencolor("yellow")
turtle.penup()
turtle.goto(-65,65)
turtle.pendown()
for i in range(5):
turtle.left(72)
turtle.fd(200)
turtle.right(144)
turtle.fd(200)
turtle.hideturtle()
㈦ python2.7繪制五角星
要設置填充色,t.fillcolor("red")
importturtle
t=turtle.Turtle()
t.fillcolor("red")
t.begin_fill()
t.hideturtle()
t.up()
t.goto(-50,-50)
t.left(36)
t.down()
foriinrange(5):
t.forward(200)
t.left(144)
t.end_fill()
㈧ python使用turtle庫繪制如下的五角星
Turtle庫是Python語言中一個很流行的繪制圖像的函數庫,想像一個小烏龜,在一個橫軸為x、縱軸為y的坐標系原點,(0,0)位置開始,它根據一組函數指令的控制,在這個平面坐標系中移動,從而在它爬行的路徑上繪制了圖形。
㈨ python五角星
我試了下,這部分參數應該這樣改:
望採納
㈩ 如何採用Python語言繪制一個五角星
#!/usr/bin/env python
import turtle
import time
turtle.forward(100)
turtle.right(144)
time.sleep(1)
turtle.forward(100)
turtle.right(144)
time.sleep(1)
turtle.forward(100)
turtle.right(144)
turtle.forward(100)
time.sleep(1)
turtle.right(144)
turtle.forward(100)
time.sleep(3)