㈠ 怎么用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)