#!/usr/local/bin/tt

EXT_SHELL="/usr/bin/gnuplot -p 2> /dev/null"

# シミュレーションのパラメーター
global grid=600					# SPACE_GRID_SIZE
global ps=4						# PIXEL_SIZE(byte) - int
global vs=8						# VISUALIZATION_STEP
rule = int(shift(30))
p(rule)

# シミュレーションの実行
pt = NULL
loop( cnt<INT_MAX ){
	cellautom(pt,grid,rule)
	if( cnt%vs==0 ) iplot("${cnt}",pt)
}

# プロット
def iplot(title,ptr){
	!set size square
	!set cbrange [0:3]
	!set title "${title}"
	!plot '-' bin array=${grid}x${grid} format='%int' with image not
	write(EXT_SHELL,ptr,grid*grid*ps)
}
