automat.py

Created by pikube

Created on October 30, 2019

1.5 KB

Automate cellulaire à une dimension: chaque ligne est déterminée à partir de celle directement en haut de celle ci. Essayez auto(0,1,1,0,0,0,1,0). Chaque pixel est alors déterminé à partir des trois en haut de lui, pouvant être, chacun, soit noir soit blanc. Ainsi, dans auto(a,b,c,d,e,f,g,h), les 8 arguments (mettre 0 si blanc/1 si noir pour chaque cas) traitent des possibilités (pour N noir et B blanc): a=BBB; b=BBN; c=BNB; d=BNN; e=NBB; f=NBN; g=NNB; h=NNN


from math import *
import kandinsky
#for this to be clear white=0 black=1
def blck(x,y,col):
  kandinsky.set_pixel(x,y,kandinsky.color(255-col*255,255-col*255,255-col*255))
def isblck(x,y):
  if kandinsky.get_pixel(x,y)==kandinsky.color(0,0,0):
    return 1
  if kandinsky.get_pixel(x,y)!=kandinsky.color(0,0,0):
    return 0
def auto(a,b,c,d,e,f,g,h):  
  cx=1
  cy=1
  #setup first points
  blck(160,0,1)
  #blck(200,0,1)
  #main loop
  for loop in range(222):
    #white=0
    #blck=1
    for loop in range(318):
      #t1=white
      if isblck(cx-1,cy-1)==0:
        #t2=white
        if isblck(cx,cy-1)==0:
          #t3=white000
          if isblck(cx+1,cy-1)==0:
            blck(cx,cy,a)
          #t3=blck001
          if isblck(cx+1,cy-1)==1:
            blck(cx,cy,b)
        #t2=blck
        if isblck(cx,cy-1)==1:
          #t3=white010
          if isblck(cx+1,cy-1)==0:
            blck(cx,cy,c)
          #t3=blck011
          if isblck(cx+1,cy-1)==1:
            blck(cx,cy,d)
      #t1=dark
      if isblck(cx-1,cy-1)==1:
        #t2=white
        if isblck(cx,cy-1)==0:
          #t3=white100
          if isblck(cx+1,cy-1)==0:
            blck(cx,cy,e)
          #t3=blck101
          if isblck(cx+1,cy-1)==1:
            blck(cx,cy,f)
        #t2=black
        if isblck(cx,cy-1)==1:
          #t3=white110
          if isblck(cx+1,cy-1)==0:
            blck(cx,cy,g)
          #t3=blck111
          if isblck(cx+1,cy-1)==1:
            blck(cx,cy,h)
      cx+=1
    cx=1
    cy+=1
#auto(0,1,0,1,1,0,0,1)

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.