3

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

Marcelo Cantos
  • 174,413
  • 38
  • 319
  • 360
Brennan Wilkes
  • 195
  • 3
  • 3
  • 13
  • I can't find anything. Normally, it would be an optional fourth color component (r, g, b, a), but the documentation makes no mention of it. – Marcelo Cantos Dec 03 '13 at 10:30

5 Answers5

1

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)

1

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.

SherylHohman
  • 14,460
  • 16
  • 79
  • 88
0

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.

Eric Leschinski
  • 135,913
  • 89
  • 401
  • 325
  • 2
    This wouldn't work if there is something behind what you are painting on. It will still be overwritten with the solid color, rather than being partially visible through the colors on top. – mbomb007 Sep 07 '16 at 21:45
0

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.

Eric Leschinski
  • 135,913
  • 89
  • 401
  • 325
-1

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()
therealemg
  • 35
  • 6
  • `turtle.hideturtle()` does more than opacity, it also makes it unclickable. Not only that, but total invisibility isn't the only use case for opacity. Often, you want partial transparency. – ggorlen Feb 05 '22 at 22:23