|
索耶的小说真的可以称作是幻想科学,在少量幻想的基础上,通过严格的逻辑推理,得到非比寻常的结论。这本书绝对称得上是硬科幻的经典之作了。故事很简单,作者娓娓道来,科学观和价值理念润物细无声。
ps,我对这本书中的生命游戏程序很感兴趣,写了一段matlab代码,可以直接运行。
function generation(iniRate,limit,width,height)
if nargin < 4
height = 400;
end
if nargin < 3
width = 300;
end
if nargin < 2
limit = 1000;
end
if nargin < 1
iniRate = 0.66;
end
life = rand(height,width) > iniRate;
for age = 1:limit
imshow(imresize(life,2));
lifeLeft = [zeros(height,1) life(:,1:end-1)];
lifeRight = [life(:,2:end) zeros(height,1)];
lifeUp = [zeros(1,width); life(1:end-1,];
lifeDown = [life(2:end,; zeros(1,width)];
lifeLeftUp = zeros(height,width);
lifeLeftUp(2:end,2:end) = life(1:end-1,1:end-1);
lifeLeftDown = zeros(height,width);
lifeLeftDown(1:end-1,2:end) = life(2:end,1:end-1);
lifeRightUp = zeros(height,width);
lifeRightUp(2:end,1:end-1) = life(1:end-1,2:end);
lifeRightDown = zeros(height,width);
lifeRightDown(1:end-1,1:end-1) = life(2:end,2:end);
neighbor = lifeLeft + lifeRight + lifeUp + lifeDown + lifeLeftUp + lifeLeftDown + lifeRightUp + lifeRightDown;
stay = (neighbor == 2);
born = (neighbor == 3);
life = (stay.* life + born)>0;
pause(0.02);
end
end |
|