Langton's ant: Difference between revisions

Content added Content deleted
(→‎{{header|Common Lisp}}: Break out display logic.)
(→‎{{header|Java}}: One line was out of order)
Line 1,517: Line 1,517:
</pre>
</pre>
=={{header|Java}}==
=={{header|Java}}==
{{incorrect|Java|The chirality of the output is reversed, meaning the ant is turning left when the spec says it should turn right, and vice-versa.}}
This implementation allows for sizes other than 100x100, marks the starting position with a green box (sometimes hard to see at smaller zoom levels and the box is smaller than the "pixels" so it doesn't cover up the color of the "pixel" it's in), and includes a "zoom factor" (<code>ZOOM</code>) in case the individual "pixels" are hard to see on your monitor.
This implementation allows for sizes other than 100x100, marks the starting position with a green box (sometimes hard to see at smaller zoom levels and the box is smaller than the "pixels" so it doesn't cover up the color of the "pixel" it's in), and includes a "zoom factor" (<code>ZOOM</code>) in case the individual "pixels" are hard to see on your monitor.
<lang java>import java.awt.Color;
<lang java>import java.awt.Color;
Line 1,561: Line 1,560:
int xChange = 0, yChange = -1; //start moving up
int xChange = 0, yChange = -1; //start moving up
while(antX < width && antY < height && antX >= 0 && antY >= 0){
while(antX < width && antY < height && antX >= 0 && antY >= 0){
plane[antY][antX] = !plane[antY][antX];
if(plane[antY][antX]){
if(plane[antY][antX]){
//turn left
//turn left
Line 1,581: Line 1,579:
}
}
}
}
plane[antY][antX] = !plane[antY][antX];
antX += xChange;
antX += xChange;
antY += yChange;
antY += yChange;