Child of Sandpile

No preview image

1 collaborator

Pie_cha cha pie (Author)

Tags

(This model has yet to be categorized with any tags)
Child of model Sandpile
Visible to everyone | Changeable by everyone
Model was written in NetLogo 6.2.1 • Viewed 129 times • Downloaded 11 times • Run 0 times
Download the 'Child of Sandpile' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

;;关于沙堆模型:https://wiki.swarma.org/index.php?title=%E6%B2%99%E5%A0%86%E6%A8%A1%E5%9E%8B
;;改变沙子流动规则,严格按照四个方向流动
globals [
  N
  Ea
]

to setup
  clear-all
  set N [ ];;存储每加一粒沙子坍塌的次数
  set Ea [ ]
  setup-patches
  setup-turtles
  reset-ticks;;时间重置
end 

to setup-patches
  ask patches [ set pcolor yellow ];;
end 

to setup-turtles
  set-default-shape turtles "dot"
end 

to go
  if ticks > num_stop [ stop ];;程序停止标志
  updata-patches;;显示瓦片上的沙子数,一个沙子为绿色,二个为蓝色,三个为红色,
  add-turtles;;加沙子
  move-turtles;;沙子移动
  hide-turtles;;到达边界就隐藏
  tick;;要确保,tiks之前的命令都正常运行,ticks才能正常运行
  if ticks > num_stop [
    do-plots;;
  ]
end 

to add-turtles
  ;;ask patch random-xcor random-ycor [
  ask patch 0 0 [
    sprout 1  [ set color black ]
  ];;加沙子
end 

to hide-turtles
  ask turtles [
    if patch-at dx 0 = nobody
    [ hide-turtle ]
    if patch-at 0 dy = nobody
    [ hide-turtle ]
  ]
end 

to move-turtles
  let s 0
  let i 0;;控制只移动四个
;  ask turtles with [count turtles-here >= 4 ] [ ;;四个沙子进行四个方向的随机选择,而不是每一个方向有一个沙子的
;    set s s + 0.25
;    face one-of neighbors4              ;; face N, E, S, or W
;    forward 1                           ;; advance one step
;  ]
  while [ any? (patches with [count turtles-here >= 4 ])] [
    foreach sort (patches with [count turtles-here >= 4 ]) [ x -> ;;对由拥有四个沙子的瓦片组成的主体列表中的每一个瓦片进行操作
      set i 0;;控制只移动四个,其余的不用管,效果依旧很好,验证了沙子从那个瓦片开始流动的顺序是无关的
      (foreach sort ([turtles-at 0 0] of x) [ y -> ;;得到每一个瓦片上的四个沙子组成的主体列表,对每一只沙子进行转向移动操作
         if i < 4 [
          ask y [
            set heading (i * 90);;让沙子面向北东南西四个方向
            forward 1
          ]
        ]
        set i i + 1
      ])
      set s s + 1
    ]
  ]
  set N fput s N;;存放坍塌次数
  set Ea fput ticks Ea;;存放坍塌强度
  display
end 

to updata-patches
  ask patches with [ count turtles-here = 0 ] [
    set pcolor  yellow ]
  ask patches with [ count turtles-here = 1 ] [
    set pcolor  green ]
  ask patches with [ count turtles-here = 2 ] [
    set pcolor  blue ]
  ask patches with [ count turtles-here = 3 ] [
    set pcolor  red ]
  display
end 

to do-plots
  set N remove 0 N;;除去0.因为有0就不能取对数
  set N (map [ x -> ln x ] N)
  set-plot-pen-mode 1
  set-plot-pen-interval 1
  set-current-plot "N-E" ;;
  set-current-plot-pen "N" ;;
  histogram N ;;
end 

There is only one version of this model, created over 2 years ago by cha pie.

Attached files

No files

Parent: Sandpile

This model does not have any descendants.

Graph of models related to 'Child of Sandpile'