Home  >  Article  >  Backend Development  >  How to fill colors in graphics in python

How to fill colors in graphics in python

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-06-22 11:40:4054919browse

Using Turtle, you can not only draw lines, but also fill the drawn closed lines.

-Set fill color: fillecolor(r, g, b)

-Start filling: begin_fill()

-End filling: end_fill()

How to fill colors in graphics in python

Draw a set of randomly distributed hearts with random sizes and different tones. First initialize a fill color. Then, use begin_fill() before drawing each shape and end_fill() after drawing. This will give you a filling effect.

Related recommendations: "Python Video Tutorial"

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()

The results are as follows:

How to fill colors in graphics in python

The above is the detailed content of How to fill colors in graphics in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What is lambda in python?Next article:What is lambda in python?