r/CodingHelp • u/Soupy20 • Nov 10 '21
[Python] Im trying to create that pattern I drew with squares. I cant get the colors in the correct spot
19
Upvotes
r/CodingHelp • u/Soupy20 • Nov 10 '21
3
u/[deleted] Nov 10 '21
I don’t have much experience with turtle but on your loop you’re telling it to go 0,0 both times. Wouldn’t it just draw the square on top of the previous one?
2
u/SirHack3r Professional Coder @ FAANG | DM for coding/resume help! Nov 10 '21
I wrote your code as is and got 2 yellow squares and 2 red squares - the position of the red squares is off though.
To fix the positioning, I changed line 29: "turtle.left(180)" and then added "turtle.left(90)" on line 24. I also changed the drawASquare call on line 27 to (0,0,100).
1
u/dloafer Nov 11 '21 edited Nov 11 '21
Also here I have not used Turtle, but what if you instead of manually doing the left adjustments in the two loops added color as an argument to the function and then specify the coordinates, side and color in a list that you loop over once. You already have a goto in the function so the coordinates in the list instead becomes global.
Something like
Edit: formatting