Skip to content Skip to sidebar Skip to footer

Python Turtle Opacity?

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.

Solution 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.

Solution 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.

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

Solution 4:

Well, you can use RGBA. First, put in the normal statements:

  1. import turtle
  2. 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.)

  1. t.color(0,0,0,.5)

will get you black with 50% opacity.

Solution 5:

you can do this by using turtle.hideturtle() if you want full opacity.

Like used here in the last line:

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

Post a Comment for "Python Turtle Opacity?"