python的填充色怎么弄_python中如何给图形填充颜色
使用Turtle不只可以畫線條,也可以將畫出的封閉線條進行填充。
-設定填充色:fillecolor(r, g, b)
-開始填充:begin_fill()
-結束填充:end_fill()
畫一組隨機分布,隨機大小和不同色調的心形。先初始化一個填充顏色。然后,在畫每個圖形繪制之前使用begin_fill()以及繪制之后使用end_fill()。這樣就能得到一個填充效果。
相關推薦:《Python視頻教程》import turtle as t
import random as r
def pink():
color = (1, r.random(), 1)
return color
def randomrange(min, max):
return min + (max- min)*r.random()
def moveto(x, y):
t.penup()
t.goto(x, y)
t.pendown()
def heart(r, a):
factor = 180
t.seth(a)
t.circle(-r, factor)
t.fd(2 * r)
t.right(90)
t.fd(2 * r)
t.circle(-r, factor)
t.setup(800, 800, 200, 200)
t.speed(9)
t.pensize(1)
t.penup()
for i in range(20):
t.goto(randomrange(-300, 300), randomrange(-300, 300))
t.begin_fill()
t.fillcolor(pink())
heart(randomrange(10, 50), randomrange(0, 90))
t.end_fill()
moveto(400, -400)
t.done()
結果如下:
總結
以上是生活随笔為你收集整理的python的填充色怎么弄_python中如何给图形填充颜色的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: dell系统重装后无法进入系统_笔记本电
- 下一篇: c++ 管理员身份_CATIA的管理员模