langton_s_ant.py

Created by valmontechno

Created on March 31, 2024

612 Bytes


from kandinsky import set_pixel
from time import sleep

WIDTH = 320
HEIGHT = 222

world = 0b0

position = (WIDTH // 2) + (HEIGHT // 2 * WIDTH)
direction = 0

set_pixel(position % WIDTH, position // WIDTH, (248, 132, 24))

while position < WIDTH * (HEIGHT + 10):
    sleep(0.01)

    world ^= 1 << position
    direction += ((world >> position) & 1) * 2 -1
    direction %= 4

    set_pixel(position % WIDTH, position // WIDTH, '#000000' if (world >> position) & 1 else '#ffffff')
    position += (-WIDTH, 1, WIDTH, -1)[direction]
    set_pixel(position % WIDTH, position // WIDTH, '#f88418')

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.