home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 16 / 016.d81 / crystals (.txt) < prev    next >
Commodore BASIC  |  2022-08-26  |  2KB  |  80 lines

  1. 10 rem random crystallization
  2. 20 rem by mark zimmerman
  3. 30 rem
  4. 40 rem illustrates the motion of atoms
  5. 50 rem in a miniature crystal at a
  6. 60 rem chose temperature.
  7. 70 rem
  8. 80 rem chance to move is
  9. 82 remp=exp(-energynew-energyold)/temp))
  10. 90 rem
  11. 100 rem energy is simply -1*number of
  12. 110 rem  adjacent atoms.
  13. 120 rem
  14. 130 rem action takes place inside of a
  15. 140 rem box of non-moving atoms.
  16. 150 rem
  17. 190 rem
  18. 200 def fnr(j)=1+int(j*rnd(1))
  19. 220 dim xy(11,11):printchr$(142)"":poke53280,6
  20. 240 n=0:input"[147]temperature           ";t
  21. 260 input"number of atoms (1-99)";a
  22. 265 ifa<1ora>99thenprint"?redo please..":goto260
  23. 270 print"[147]"
  24. 280 gosub8000
  25. 300 gosub9000
  26. 400 gosub2000
  27. 500 gosub3000
  28. 600 p=exp(-(en-e)/t)
  29. 700 n=n+1
  30. 800 ifrnd(1)>pthen400
  31. 900 xy(x,y)=0:xy(xn,yn)=1:goto300
  32. 1999 rem
  33. 2000 rem pick random atom
  34. 2010 ifpeek(198)<>0then63000
  35. 2020 x=fnr(10):y=fnr(10):ifxy(x,y)=0then2020
  36. 2025 ifpeek(198)<>0then63000
  37. 2040 ifxy(x+1,y)=1andxy(x-1,y)=1andxy(x,y+1)=1andxy(x,y-1)=1then2020
  38. 2060 rem now pick a hole
  39. 2080 r=rnd(1):ifr<.25thenxn=x-1:yn=y:goto2200
  40. 2100 ifr<.5thenxn=x+1:yn=y:goto2200
  41. 2120 ifr<.75thenxn=x:yn=y-1:goto2200
  42. 2140 xn=x:yn=y+1
  43. 2200 ifxy(xn,yn)=1then2080
  44. 2300 return
  45. 2999 rem
  46. 3000 rem calc energy of atom
  47. 3020 e=-xy(x-1,y)-xy(x+1,y)-xy(x,y-1)-xy(x,y+1)
  48. 3040 en=-xy(xn-1,yn)-xy(xn+1,y)-xy(xn,yn-1)-xy(xn,yn+1)+1
  49. 3100 return
  50. 7999 rem
  51. 8000 rem  init configuration
  52. 8020 print"initializing atoms in box"
  53. 8040 fori=1toa
  54. 8060 x=fnr(10):y=fnr(10):print".";
  55. 8080 ifxy(x,y)=1then8060
  56. 8100 xy(x,y)=1:next i
  57. 8200 rem fill in boundary
  58. 8220 fori=0to11:xy(0,i)=1:xy(11,i)=1:xy(i,0)=1:xy(i,11)=1:next:print"[147]"
  59. 8300 return
  60. 8999 rem
  61. 9000 rem display configuration
  62. 9010 ifpeek(198)<>0then63000
  63. 9020 print"":print"n="n
  64. 9040 fori=1to10:printspc(10):forj=1to10
  65. 9060 ifxy(i,j)=1thenprint""chr$(209)"[144]";
  66. 9062 ifxy(i,j)=0thenprint"[144][214]";
  67. 9080 nextj
  68. 9100 print
  69. 9120 next i
  70. 9130 print"press a key to exit"
  71. 9140 return
  72. 63000 rem do again or leave?
  73. 63010 print"[147]      do you wish to try again?"
  74. 63020 poke198,0:wait198,1:geta$
  75. 63030 ifa$<>"y"anda$<>"n"thenpoke53280,rnd(1)*15:goto63010
  76. 63040 ifa$="y"thenfori=1to10:forj=1to10:xy(i,j)=0:nextj,i:goto240
  77. 63050 :
  78. 63060 print"[147]load"chr$(34)"payload"chr$(34)",8":print"run"
  79. 63070 poke631,13:poke632,13:poke198,2:end
  80.