Python Forum
Cant define turtle color with function argument - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Cant define turtle color with function argument (/thread-26149.html)



Cant define turtle color with function argument - Wrightys99 - Apr-22-2020

Hi

I am struggling to work out why the colours arent changing in this program.

I have created a function called 'flowers' and i pass 3 colours in, as arguments as well as some others.

When i run the program all the colour selections turn out black.

I would appreciate some help, im been through the python manual and cant figure out why.

import turtle
import random

fred=turtle.Turtle()
fred.speed(100)

def flower(x,y,petal_num,petal_col,center_col,square_col):
    fred.penup()
    fred.goto(x,y)
    fred.pendown()

    fred.begin_fill()
    fred.color = str(petal_col)

    for petal in range (petal_num):
        for arc in range(2):
            fred.circle(80,100)
            fred.left(80)
        fred.left(360/petal_num)

    fred.end_fill()

    fred.begin_fill()
    fred.color = str(center_col)
    fred.penup()
    fred.goto(x,y-40)
    fred.pendown()
    fred.circle(40)
    fred.end_fill()

    fred.hideturtle()

    fred.penup()
    fred.goto(x,y)
    fred.pendown()
    
    fred.color = str(square_col)
    def square():
        for i in range (4):
            fred.forward(35)
            fred.right(90)

    for pattern in range(36):
        square()
        fred.right(10)

flower(-200,-200,5,"honeydew","c","lavenderblush")
flower(200,200,7,"skyblue","yellow","cyan")
flower(-200,200,6,"salmon","deepskyblue","lightpink")
flower(200,-200,8,"skyblue","yellow","cyan")
flower(0,0,4,"skyblue","yellow","cyan")



RE: Cant define turtle color with function argument - deanhystad - Apr-22-2020

Use fred.color(colorname). Your color names are already strings, so you don't need the str(colorname).

Also, 'c' is not a color and my program didn't draw a flowere when honeydew was used. Don't know why.


RE: Cant define turtle color with function argument - Wrightys99 - Apr-22-2020

Thank you deanhystad

What a fool.

I tried that first and it didnt work.

But now i know why because c isnt a colour

Thank you for your time.

Much Appreciated