Totalistic Cellular Automaton

 投稿者:しばっち  投稿日:2015年10月28日(水)22時17分17秒
  http://mathworld.wolfram.com/Code912.html

!'Totalistic Cellular Automaton
CALL GINIT(800,400)
DIM M(50,25)
INPUT  PROMPT "RULE=":RULE !'0<RULE<=2186(3^7-1)
LET M(25,1)=1 !'初期値
!'LET M(25,1)=2
LET C$=RIGHT$("000000"&NSTR$(RULE,3),7)
FOR Y=1 TO 24
   FOR X=1 TO 50
      IF X-1>=1 THEN  LET CC=M(X-1,Y) ELSE LET CC=0
      LET CC=CC+M(X,Y)
      IF X+1<=50 THEN LET CC=CC+M(X+1,Y)
      LET C=VAL(C$(7-CC:7-CC))
      LET M(X,Y+1)=C
   NEXT X
NEXT  Y
SET WINDOW 0,1,1,0
MAT PLOT CELLS, IN 0 , 0 ; 1,1 : M
END

EXTERNAL SUB GINIT(XSIZE,YSIZE)
SET BITMAP SIZE XSIZE,YSIZE
!'SET WINDOW 0,XSIZE-1,YSIZE-1,0
SET POINT STYLE 1
SET COLOR MODE "REGULAR"
SET COLOR MIX(0) 1,1,1
SET COLOR MIX(1) .5,.5,.5
SET COLOR MIX(2) 0,0,0
!'SET COLOR MIX(3) 1,0,1
!'SET COLOR MIX(4) 0,1,0
!'SET COLOR MIX(5) 0,1,1
!'SET COLOR MIX(6) 1,1,0
!'SET COLOR MIX(7) 1,1,1
CLEAR
END SUB

EXTERNAL  FUNCTION NSTR$(X,N) !'N進法
DO
!' LET A$=MID$("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",MOD(X,N)+1,1)
   LET A$=STR$(MOD(X,N))
   LET B$=A$&B$
   LET X=INT(X/N)
LOOP UNTIL X=0
LET NSTR$=B$
END FUNCTION
 

戻る