Fortran 95
这段代码有点大,但它会产生不错的ASCii结果:
program Rorschach
implicit none
integer :: i, j, k, l, N, seed
integer, dimension (24) :: i_zero, j_zero
real :: aux
integer, dimension (17,12) :: matrix_I = 0
character, dimension (17,12) :: matrix_C
! random seed according to system clock
call SYSTEM_CLOCK(count=k)
call RANDOM_SEED(size=N)
allocate(seed(N))
seed=k+37*(/ (i - 1, i = 1, n) /)
call RANDOM_SEED(PUT=seed)
! generating 7 random points
do i=1,7
call RANDOM_NUMBER(aux)
i_zero(i) = 15 * aux + 2 ! range = 2-16
call RANDOM_NUMBER(aux)
j_zero(i) = 11 * aux + 2 ! range = 2-12
enddo
! generating 7 large spots of ink
do i=1,7
matrix_I(i_zero(i),j_zero(i)) = 3 ! central points have ink value 3
do k=-1,1
do l=-1,1
if (.NOT.((k==0) .AND. (l==0))) then ! immediate neighbours...
if ( (((i_zero(i)+k)<=17).OR.((i_zero(i)+k)>0)) .AND. (((j_zero(i)+l)<=12).OR.((j_zero(i)+l)>0)) ) then ! ... that are inside the designed area ...
if (matrix_I(i_zero(i)+k,j_zero(i)+l) < 2) matrix_I(i_zero(i)+k,j_zero(i)+l) = 2 ! ... and that do not have ink value larger than 2 will be attributed as 2
endif
endif
enddo
enddo
enddo
! generating N little sparkles of ink
call RANDOM_NUMBER(aux)
N = int(11 * aux) + 20 ! N = 20-30
i = 0
do while (i <= N)
call RANDOM_NUMBER(aux)
i_zero(i) = 16 * aux + 1 ! range = 1-17
call RANDOM_NUMBER(aux)
j_zero(i) = 11 * aux + 1 ! range = 1-12
if (matrix_I(i_zero(i),j_zero(i)) < 1) then ! if the selected point already has more ink than 1, then cycle the loop
matrix_I(i_zero(i),j_zero(i)) = 1
else
cycle
endif
i = i + 1
enddo
! converting matrix of integers into matrix of characters
do i=1,17
do j=1,12
select case(matrix_I(i,j))
case(0)
matrix_C(i,j) = " "
case(1)
matrix_C(i,j) = "."
case(2)
matrix_C(i,j) = "+"
case(3)
matrix_C(i,j) = "@"
end select
enddo
enddo
! printing it on the screen + its reflection
do i=1,17
do j=1,12
write(*,"(A1)",advance="NO") matrix_C(i,j)
enddo
do j=12,2,-1
write(*,"(A1)",advance="NO") matrix_C(i,j)
enddo
write(*,"(A1)") matrix_C(i,1)
enddo
end program Rorschach
该代码已完全注释,但基本思想是它生成一个值在0到3之间的矩阵,代表该点的墨水量。有7个大的墨水点(一个值为3的点被值2包围)和许多小的“火花”(值1)。然后,使用以下转换将该矩阵转换为字符矩阵:
0 =
1 = .
2 = +
3 = @
结果如下:
+++ . . +++
+@++++ . . ++++@+
++++@+. .+@++++
.+++ ++++ +++.
+@@+
. . . +++@@+++ . . .
. +@++++@+ .
++++++ ++++++
+@+ +@+
. ++++ ++++ .
. +@+ +@+ .
. .+++. .+++. .
. . . . . .
. . . .
. .. .. .
. .