Python Forum
Cant define turtle color with function argument
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cant define turtle color with function argument
#1
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")
Reply
#2
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.
Reply
#3
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  mutable argument in function definition akbarza 1 423 Dec-15-2023, 02:00 PM
Last Post: deanhystad
  Turtle Star Fill Color Yellow-White Interchanging Color Effect codelab 9 900 Oct-25-2023, 09:09 AM
Last Post: codelab
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 1,026 Dec-25-2022, 03:00 PM
Last Post: askfriends
  i want to use type= as a function/method keyword argument Skaperen 9 1,771 Nov-06-2022, 04:28 AM
Last Post: Skaperen
  Regex - Pass Flags as a function argument? muzikman 6 3,482 Sep-06-2021, 03:43 PM
Last Post: muzikman
  How to use a tuple as an argument of a function zarox 5 3,460 Nov-14-2020, 08:02 PM
Last Post: buran
  Struggling for the past hour to define function and call it back godlyredwall 2 2,156 Oct-29-2020, 02:45 PM
Last Post: deanhystad
  calling a function and argument in an input phillup7 3 2,551 Oct-25-2020, 02:12 PM
Last Post: jefsummers
  Passing argument from top-level function to embedded function JaneTan 2 2,202 Oct-15-2020, 03:50 PM
Last Post: deanhystad
  Help with define a def function Omer_ 3 2,093 Sep-20-2020, 06:59 PM
Last Post: Omer_

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020