home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Loadstar 16
/
016.d81
/
crystals
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2022-08-26
|
2KB
|
80 lines
10 rem random crystallization
20 rem by mark zimmerman
30 rem
40 rem illustrates the motion of atoms
50 rem in a miniature crystal at a
60 rem chose temperature.
70 rem
80 rem chance to move is
82 remp=exp(-energynew-energyold)/temp))
90 rem
100 rem energy is simply -1*number of
110 rem adjacent atoms.
120 rem
130 rem action takes place inside of a
140 rem box of non-moving atoms.
150 rem
190 rem
200 def fnr(j)=1+int(j*rnd(1))
220 dim xy(11,11):printchr$(142)"":poke53280,6
240 n=0:input"[147]temperature ";t
260 input"number of atoms (1-99)";a
265 ifa<1ora>99thenprint"?redo please..":goto260
270 print"[147]"
280 gosub8000
300 gosub9000
400 gosub2000
500 gosub3000
600 p=exp(-(en-e)/t)
700 n=n+1
800 ifrnd(1)>pthen400
900 xy(x,y)=0:xy(xn,yn)=1:goto300
1999 rem
2000 rem pick random atom
2010 ifpeek(198)<>0then63000
2020 x=fnr(10):y=fnr(10):ifxy(x,y)=0then2020
2025 ifpeek(198)<>0then63000
2040 ifxy(x+1,y)=1andxy(x-1,y)=1andxy(x,y+1)=1andxy(x,y-1)=1then2020
2060 rem now pick a hole
2080 r=rnd(1):ifr<.25thenxn=x-1:yn=y:goto2200
2100 ifr<.5thenxn=x+1:yn=y:goto2200
2120 ifr<.75thenxn=x:yn=y-1:goto2200
2140 xn=x:yn=y+1
2200 ifxy(xn,yn)=1then2080
2300 return
2999 rem
3000 rem calc energy of atom
3020 e=-xy(x-1,y)-xy(x+1,y)-xy(x,y-1)-xy(x,y+1)
3040 en=-xy(xn-1,yn)-xy(xn+1,y)-xy(xn,yn-1)-xy(xn,yn+1)+1
3100 return
7999 rem
8000 rem init configuration
8020 print"initializing atoms in box"
8040 fori=1toa
8060 x=fnr(10):y=fnr(10):print".";
8080 ifxy(x,y)=1then8060
8100 xy(x,y)=1:next i
8200 rem fill in boundary
8220 fori=0to11:xy(0,i)=1:xy(11,i)=1:xy(i,0)=1:xy(i,11)=1:next:print"[147]"
8300 return
8999 rem
9000 rem display configuration
9010 ifpeek(198)<>0then63000
9020 print"":print"n="n
9040 fori=1to10:printspc(10):forj=1to10
9060 ifxy(i,j)=1thenprint""chr$(209)"[144]";
9062 ifxy(i,j)=0thenprint"[144][214]";
9080 nextj
9100 print
9120 next i
9130 print"press a key to exit"
9140 return
63000 rem do again or leave?
63010 print"[147] do you wish to try again?"
63020 poke198,0:wait198,1:geta$
63030 ifa$<>"y"anda$<>"n"thenpoke53280,rnd(1)*15:goto63010
63040 ifa$="y"thenfori=1to10:forj=1to10:xy(i,j)=0:nextj,i:goto240
63050 :
63060 print"[147]load"chr$(34)"payload"chr$(34)",8":print"run"
63070 poke631,13:poke632,13:poke198,2:end