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
  Passing argument from top-level function to embedded function JaneTan 2 115 Oct-15-2020, 03:50 PM
Last Post: deanhystad
  Help with define a def function Omer_ 3 141 Sep-20-2020, 06:59 PM
Last Post: Omer_
  How to define a function to create a resorted list? sparkt 6 337 Aug-08-2020, 04:10 PM
Last Post: sparkt
  Use of input function to change screen background color in Turtles Oldman45 3 395 Jul-10-2020, 09:54 AM
Last Post: Oldman45
  return string from function with one argument jamie_01 2 343 May-28-2020, 11:07 PM
Last Post: menator01
  how to use getter as argument in function nanok66 3 426 May-13-2020, 09:15 AM
Last Post: nanok66
  When Defining a Function with an Equation as a Default Argument, which Value Is Used? OJGeorge4 4 374 Apr-09-2020, 08:48 AM
Last Post: DeaD_EyE
  SyntaxError: positional argument follows keyword argument syd_jat 3 1,884 Mar-03-2020, 08:34 AM
Last Post: buran
  How to pass variable as an argument to be used in a function? t4keheart 8 787 Jan-16-2020, 01:37 PM
Last Post: buran
  How to manually define color bar scale in seaborn heatmap SriRajesh 3 5,763 Sep-08-2019, 11:12 AM
Last Post: RudraMohan

Forum Jump:

User Panel Messages

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