Abelian sandpile model: Difference between revisions
Content added Content deleted
No edit summary |
(Abelian sandpile model en FreeBASIC) |
||
Line 1,257: | Line 1,257: | ||
[0; 0; 1; 0; 0]] |
[0; 0; 1; 0; 0]] |
||
</pre> |
</pre> |
||
=={{header|FreeBASIC}}== |
|||
<lang freebasic>ScreenRes 320, 200, 8 |
|||
WindowTitle "Abelian sandpile model" |
|||
Dim As Long dimen = 220 |
|||
Dim As Long pila1(dimen*dimen), pila2(dimen*dimen) |
|||
Dim As Long i, x, y |
|||
Dim As Long partic = 400000 |
|||
Dim As Double t0 = Timer |
|||
Do |
|||
i = 0 |
|||
For y = 0 To dimen-1 |
|||
For x = 0 To dimen-1 |
|||
If x = dimen/2 And y = dimen/2 Then |
|||
partic -= 4 |
|||
pila1(i) += 4 |
|||
End If |
|||
If pila1(i) >= 4 Then |
|||
pila1(i) -= 4 |
|||
pila2(i-1) += 1 |
|||
pila2(i+1) += 1 |
|||
pila2(i-dimen) += 1 |
|||
pila2(i+dimen) += 1 |
|||
End If |
|||
Pset(x, y), (pila1(i)*2) |
|||
i += 1 |
|||
Swap pila1(i), pila2(i) |
|||
Next x |
|||
Next y |
|||
Loop Until partic < 4 |
|||
Bsave "abelian_sandpile.bmp",0 |
|||
Sleep</lang> |
|||
{{out}} |
|||
<pre>[https://www.dropbox.com/s/lky2ji9n15gn5u6/abelian_sandpile.bmp?dl=0 Abelian sandpile model FreeBasic image] |
|||
</pre> |
|||
=={{header|Go}}== |
=={{header|Go}}== |