langton.py

Created by cent20

Created on April 19, 2021

562 Bytes

𝗙𝗼𝘂𝗿𝗺𝗶𝘀 𝗱𝗲 𝗟𝗮𝗻𝗴𝘁𝗼𝗻

Automate cellulaire.


# De Fedyna Kevin
from kandinsky import set_pixel, get_pixel
from ion import keydown

fourmis = [160, 111]
facing = ((0, 1), (1, 0), (0, -1), (-1, 0))

def move():
    global fourmis, facing
    
    d = 0
    while not keydown(2):
        if get_pixel(*fourmis) == (248, 252, 248):
            d = (d - 1) % 4
            set_pixel(fourmis[0], fourmis[1], (0,) * 3)
        else:
            d = (d + 1) % 4
            set_pixel(fourmis[0], fourmis[1], (255,) * 3)
        
        fourmis = [fourmis[i] + facing[d][i] for i in range(2)]

move()

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.