Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Repeating functions with python turtle

I wish to know way to make loop of function to recreate the same shape/pattern(google photo logo) with a different rotation and position and different variables such as color. Below is code that will allow me to make one of the pallets with the correct angles but ratio is not exact. Also prefer not use any goto/home function as I need repeat this drawing later. Should I have used left/right for direction instead of set heading?

def photo():
    speed(1) # turtle speed (debugging)
    #speed(0)
    length = 50

    penup()
    color("#4688f4") #Blue petal
    begin_fill() 
    setheading(25)
    forward(length/5.5)
    setheading(0)
    forward(length)
    setheading(227)
    forward(length*0.87)
    setheading(135)
    forward(length*0.8)
    end_fill()

    color("#3d6ec9") #Blue petal
    begin_fill() 
    setheading(250)
    forward(length/5)
    setheading(270)
    forward(length/2.6)
    setheading(0)
    forward(length/1.6)
    end_fill() 

here you see the drawing from the code...

thats the above described turtle drawing

Update:

enter image description here

like image 288
Bondspencil Avatar asked Feb 28 '26 04:02

Bondspencil


1 Answers

very simplified answer:

my_colors =['blue', 'yellow', 'red', 'green'] # replace with hex values

for i in range(4):

    photo(my_colors[i])
    right(90)

photo function then needs to be adjusted to take a keyword, which could look like: def photo(my_color):, and where you use colors in your function, you just call it color(my_color)

but of course you need to think about where you will turn after each loop and if you will need to move forward as well.

like image 142
Cut7er Avatar answered Mar 01 '26 17:03

Cut7er



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!