Ask coding questions

← Back to all posts
How to make a basic turtle gradient
EzraMast (0)

Hey im making a program and i want the lines my turtle makes to fade from one color to another (purple to pink) but i cant figure out how, any help would be appreciated

Answered by ruiwenge2 (1107) [earned 5 cycles]
View Answer
Comments
hotnewtop
ruiwenge2 (1107)

you can do something like:

from turtle import Screen, Turtle

COLOR = (0.60156, 0, 0.99218)
TARGET = (0.86328, 0.47656, 0.31250)

screen = Screen()
screen.tracer(False)

WIDTH, HEIGHT = screen.window_width(), screen.window_height()

deltas = [(hue - COLOR[index]) / HEIGHT for index, hue in enumerate(TARGET)]

turtle = Turtle()
turtle.color(COLOR)

turtle.penup()
turtle.goto(-WIDTH/2, HEIGHT/2)
turtle.pendown()

direction = 1

for distance, y in enumerate(range(HEIGHT//2, -HEIGHT//2, -1)):
  turtle.forward(WIDTH * direction)
  turtle.color([COLOR[i] + delta * distance for i, delta in enumerate(deltas)])
  turtle.sety(y)
  direction *= -1

screen.tracer(True)
screen.exitonclick()

look here: https://stackoverflow.com/questions/63999474/how-do-i-make-a-linear-gradient-with-python-turtle

[deleted]

@ruiwenge2 i learned turtle for about 2 months and don't now anything that you wrote here except for the very basic basic basics

ruiwenge2 (1107)

@poetaetoes i dont know it either i just found it on stack overflow

[deleted]
[deleted]
[deleted]

@ruiwenge2 didnt know u were allowed to do that :\