Skip to content

Instantly share code, notes, and snippets.

@joemilbourn
Last active January 28, 2021 09:55
Show Gist options
  • Save joemilbourn/9cd0e922e9a9ddc8e67e68745b9d6908 to your computer and use it in GitHub Desktop.
Save joemilbourn/9cd0e922e9a9ddc8e67e68745b9d6908 to your computer and use it in GitHub Desktop.
ant
from kandinsky import *
from random import *
def rcolor():
return color(randint(0, 255),
randint(0, 255),
randint(0, 255))
rule = [1, -1, -1, 1]
nr = len(rule)
moves = [(-1, 0), (0, -1), (1, 0), (0, 1)]
colors = [(0, 0, 0)] + [rcolor() for _ in range(nr-1)]
p = (160, 111)
d = 0
fill_rect(0, 0, 320, 222, colors[0])
while True:
idx = colors.index(get_pixel(*p))
set_pixel(p[0], p[1], colors[(idx + 1) % nr])
d = (d + rule[idx]) % len(moves)
p = ((p[0] + moves[d][0]) % 320, (p[1] + moves[d][1]) % 222)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment