问题
Just wondering, is it possible to make a turtle draw/fill with semi-transparent ink?
Something like:
turtle.setfillopacity(50) # Would set it to 50% transparency
Running python 2.7
回答1:
It's not possible to do that, but you could define your colors, and then a light equivalent, and use those.
Red = (255,0,0,0)
LRed = (100,0,0)
I think that would achieve similar effects. You could then just use a lighter color when you want it semi-transparent.
回答2:
This python turtle example fades out the text while keeping the original turtle stamps unmodified:
import turtle
import time
alex = turtle.Turtle()
alex_text = turtle.Turtle()
alex_text.goto(alex.position()[0], alex.position()[1])
alex_text.pencolor((0, 0, 0)) #black
alex_text.write("hello")
time.sleep(1)
alex_text.clear()
alex_text.pencolor((.1, .1, .1)) #dark grey
alex_text.write("hello")
time.sleep(1)
alex_text.pencolor((.5, .5, .5)) #Grey
alex_text.write("hello")
time.sleep(1)
alex_text.pencolor((.8, .8, .8)) #Light grey
alex_text.write("hello")
time.sleep(1)
alex_text.pencolor((1, 1, 1)) #white
alex_text.write("hello")
time.sleep(1)
alex_text.clear() #gone
time.sleep(1)
The text simulates an opacity increase to maximum. Alex's stamps are unmodified.
回答3:
You can by doing
import turtle
turtle = turtle.Turtle()
r = 100
g = 100
b = 100
a = 0.5
turtle.color(r,g,b,a)
(well, maybe it only works for repl.it)
回答4:
Well, you can use RGBA.
First, put in the normal statements:
import turtle
t = turtle.Turtle()
Then, use t.color()
, but use RGBA.
The first portion of RGBA is the same as RGB, and the last value is the percentage of opacity (where 0 is transparent, 1 is opaque.)
t.color(0,0,0,.5)
will get you black with 50% opacity.
回答5:
you can do this by using turtle.hideturtle()
if you want full opacity.
Like used here in the last line:
import turtle
t = turtle.Turtle()
t.speed(1)
t.color("blue")
t.begin_fill()
t.forward(100)
t.left(90)
t.forward(100)
t.left(90)
t.forward(100)
t.left(90)
t.forward(100)
t.end_fill()
t.color("red")
t.begin_fill()
t.forward(101)
t.left(90)
t.forward(100)
t.left(90)
t.forward(100)
t.left(90)
t.forward(100)
t.end_fill()
t.color("green")
t.begin_fill()
t.forward(101)
t.left(90)
t.forward(100)
t.left(90)
t.forward(100)
t.left(90)
t.forward(100)
t.end_fill()
t.color("yellow")
t.begin_fill()
t.forward(101)
t.left(90)
t.forward(100)
t.left(90)
t.forward(100)
t.left(90)
t.forward(100)
t.end_fill()
t.hideturtle()
来源:https://stackoverflow.com/questions/20322465/python-turtle-opacity