rule110.py

Created by octo

Created on January 13, 2022

864 Bytes

Forked from /alain-busser/rule110: https://my.numworks.com/python/alain-busser/rule110


from kandinsky import *
from random import *

B=color(0,0,0)
W=color(255,255,255)
# Screen
SW=320
SH=222

def Alive(x,y):
  if x==0 or x==SW:return False
  elif get_pixel(x-1,y-1) and not get_pixel(x,y-1) and not get_pixel(x+1,y-1):return True
  else:return get_pixel(x-1,y-1)==get_pixel(x,y-1)==get_pixel(x+1,y-1)

def Init(): # Generate the first line randomly
  fill_rect(0,0,SW,1,B)
  for n in range(10):set_pixel(randrange(SW),0,W)

def Screen():
  # First entire screen fill
  for y in range(1,SH):
    for x in range(SW):
      if Alive(x,y):set_pixel(x,y,B)

  while True:
    # Shifting every line 1 pixel up
    for y in range(1,SH):
      for x in range(SW):
        set_pixel(x,y-1,get_pixel(x,y))

    # Gen new last line
    y=SH-1
    fill_rect(0,y,SW,1,W)
    for x in range(SW):
      if Alive(x,y):set_pixel(x,y,B)

Init()
Screen()

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.