Post by tsh73 on Nov 22, 2019 18:18:09 GMT
as per
en.wikipedia.org/wiki/Rule_30
Also rule 90 (Sierpinsky triangle) and some others.
Variables to be changed:
rule (0..255, but 0 is total empty and 255 is total fill. Anything else will do something)
factor - actually point size. From 1 up.
start - initial condition (upper line). Different density random fills work differently for Rule 184
Have fun
en.wikipedia.org/wiki/Rule_30
Also rule 90 (Sierpinsky triangle) and some others.
Variables to be changed:
rule (0..255, but 0 is total empty and 255 is total fill. Anything else will do something)
factor - actually point size. From 1 up.
start - initial condition (upper line). Different density random fills work differently for Rule 184
Have fun
'cellular automata
'rule30 at al
'tsh73 Nov 2019
'v1. Make it work, work right
'v2 work fast
'v3 try to change to 01 and use val - measured seperately, no better
'v4 turn to array instead of string
'out: remove commented code
rule=30 '//chaos
'rule = 110 '//chaos
'rule = 90 '//sierpinsky triangle
'rule = 184 '//majority
factor=3
start=0 'single center 1 (default)
'start=1 '1/3 0, 1/3 1, 1/3 0
'start=2 'random 25% 1
'start=3 'random 50% 1
'start=4 'random 75% 1
nomainwin
global maxX, curr, factor
open "Cellular automata" for graphics_nsb_fs as #gr
#gr "trapclose [quit]"
#gr "down"
#gr "home; posxy cx cy"
#gr "size ";factor
maxX=cx*2
maxY=2*cy
if cx < maxY then maxY=cx
maxX=int(maxX/factor)
maxY=int(maxY/factor)
dim aLine(maxX, 1) 'maxX, 0..1
curr=0
redim aLine(maxX, 1) 'fill with 0 (if you want call several times)
select case start
case 0
'initial center point
aLine(maxX/2, curr)=1
case 1
'1/3 0, 1/3 1, 1/3 0
for i = maxX/3 to 2*maxX/3
aLine(i, curr)=1
next
case 2
'random 25% 1
for i = 1 to maxX
if rnd(0)<0.25 then aLine(i, curr)=1
next
case 3
'random 50% 1
for i = 1 to maxX
if rnd(0)<0.5 then aLine(i, curr)=1
next
case 4
'random 75% 1
for i = 1 to maxX
if rnd(0)<0.75 then aLine(i, curr)=1
next
case else
'initial center point
aLine(maxX/2, curr)=1
end select
#gr "cls"
t0=time$("ms")
y=0
call drawLine y
for y = 1 to maxY
'make curLine$ out of prevLine$
prev=curr
curr=1-curr '1->0->1
aLine(1, curr)=0
for i=2 to maxX-1
SCAN 'possible break point
ind=aLine(i-1, prev)*4+_
aLine(i, prev)*2+_
aLine(i+1, prev)
if rule and (2^ind) then c=1 else c=0
aLine(i, curr)=c
next
aLine(maxX, curr)=0
call drawLine y
#gr "discard"
next
#gr "flush"
t1=time$("ms")
'notice "Time taken ";t1-t0
'91 sec, 94, 93
'discard - 81
's$->ind binary instead of array search: 61
'skip empty " ": 58,5
'ind as instr/4: slower (64 )
'no draw: 36,6
'alas array(val(s$)) is slower then (s$->ind binary), bia mid and '='
'number array instead of string: 55
wait
[quit]
timer 0
close #gr
end
'-------------------------
sub drawLine y
for i = 1 to maxX
if aLine(i, curr) then
#gr "set ";(i-1)*factor;" "; y*factor
'print i-1, y
end if
next
end sub