# Why won't the turtles move together?

I have spent hours today trying to write a computer programme which moves 4 turtles together, from specific places, whilst keeping in a square shape when you connect all of the points. But weird things keep happening, they start by all moving together but they get to a point where they all start to move apart again, then begin creating weird patterns which appear to be random. I am not very experienced in using python so I would appreciate some help. Thanks.

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 from turtle import * from math import* ant1 = Turtle() ant2 = Turtle() ant3 = Turtle() ant4 = Turtle() ant1.pencolor("yellow") ant2.pencolor("red") ant3.pencolor("black") ant4.pencolor("pink") def start(): ant1.penup() ant2.penup() ant3.penup() ant4.penup() ant1.forward(100) ant1.left(180) ant2.left(90) ant2.forward(100) ant2.left(90) ant2.left(180) ant3.left(90) ant4.forward(100) ant4.left(90) ant4.forward(100) ant4.left(180) start() ant1.pendown() ant2.pendown() ant3.pendown() ant4.pendown() ant1.width(5) ant2.width(5) ant3.width(5) ant4.width(5) ant1.speed(20) ant2.speed(20) ant3.speed(20) ant4.speed(20) for i in range (100000000): difference13 = ant1.pos() - ant3.pos() angle13 = atan(difference13[1] / difference13[0]) ant1.left(angle13) ant1.forward(1) difference32 = ant3.pos() - ant2.pos() angle32 = atan(difference32[0] / difference32[1]) ant3.right(angle32) ant3.forward(1) difference24 = ant2.pos() - ant4.pos() angle24 = atan(difference24[1] / difference24[0]) ant2.left(angle24) ant2.forward(1) difference41 = ant4.pos() - ant1.pos() angle41 = atan(difference41[0] / difference41[1]) ant4.right(angle41) ant4.forward(1) 

Note by Malachi Hibbins
7 months ago

This discussion board is a place to discuss our Daily Challenges and the math and science related to those challenges. Explanations are more than just a solution — they should explain the steps and thinking strategies that you used to obtain the solution. Comments should further the discussion of math and science.

When posting on Brilliant:

• Use the emojis to react to an explanation, whether you're congratulating a job well done , or just really confused .
• Ask specific questions about the challenge or the steps in somebody's explanation. Well-posed questions can add a lot to the discussion, but posting "I don't understand!" doesn't help anyone.
• Try to contribute something new to the discussion, whether it is an extension, generalization or other idea related to the challenge.

MarkdownAppears as
*italics* or _italics_ italics
**bold** or __bold__ bold
- bulleted- list
• bulleted
• list
1. numbered2. list
1. numbered
2. list
Note: you must add a full line of space before and after lists for them to show up correctly
paragraph 1paragraph 2

paragraph 1

paragraph 2

[example link](https://brilliant.org)example link
> This is a quote
This is a quote
    # I indented these lines
# 4 spaces, and now they show
# up as a code block.

print "hello world"
# I indented these lines
# 4 spaces, and now they show
# up as a code block.

print "hello world"
MathAppears as
Remember to wrap math in $$ ... $$ or $ ... $ to ensure proper formatting.
2 \times 3 $2 \times 3$
2^{34} $2^{34}$
a_{i-1} $a_{i-1}$
\frac{2}{3} $\frac{2}{3}$
\sqrt{2} $\sqrt{2}$
\sum_{i=1}^3 $\sum_{i=1}^3$
\sin \theta $\sin \theta$
\boxed{123} $\boxed{123}$