如何在netlogo中加入补丁时代的效果?

如何在netlogo中加入补丁时代的效果?,netlogo,Netlogo,如何在下面的代码中完成以下操作: 面片更改颜色以反映其与行“min pycor”的距离 例如,颜色从黄色到红色再到黑色交替(表示死亡) 但这应该考虑到黄色斑块>红色>黑色的产生 turtles-own [ stem? ;; true for stem cells, false for transitory cells age ;; age of cell. changes color with age metastatic? ;; false for progeny of st

如何在下面的代码中完成以下操作:

面片更改颜色以反映其与行“min pycor”的距离

例如,颜色从黄色到红色再到黑色交替(表示死亡)

但这应该考虑到黄色斑块>红色>黑色的产生

turtles-own
[
 stem?     ;; true for stem cells, false for transitory cells
 age  ;; age of cell. changes color with age
 metastatic?  ;; false for progeny of stem cell 0, true for progeny of stem cell 1
]

globals
[
 cell-count
]

to setup
clear-all
set-default-shape turtles "square"
ask patches[
  if pycor = min-pycor [
    ifelse random 10 <= 2 
     [set pcolor white]
     [sprout 1 [set shape "square" set color blue] ] 
 ]
 ]
evaluate-params
reset-ticks
end

to go
ask patches with [pcolor = yellow]
[if count neighbors with [pcolor = black] > 0
 [ask one-of neighbors with [pcolor = black][set pcolor yellow]
   ]
]

ask patches with [pcolor = white] 
[if count neighbors with [pcolor = black] > 0
[ask one-of neighbors with [pcolor = black][set pcolor yellow]
  ]
]
tick
 end
 ;;transitional cells move and hatch more. Turtle proc.
  to move-transitional-cells
  if (not stem?)
 [
  set color ( red + 0.25 * age )
  fd 1
  if (age < 6)
  [
    hatch 1
    [  ;amplification
     rt random-float 360
     fd 1
    ]
  ]
   ]
  end

 to mitosis ;; turtle proc. - stem cells only
 if stem?
 [
  hatch 1
  [
  fd 1
  set color red
  set stem? false
  ifelse (who = 1)
    [ set age 16 ]
    [ set age 0 ]
   ]
   ]
  end

 to death   ;; turtle proc.
 if (not stem?) and (not metastatic?) and (age > 20)
  [ die ]
 if (not stem?) and metastatic? and (age > 4)
  [ die ]
 end

to evaluate-params
set cell-count count turtles  ;cell count
if (cell-count <= 0)
 [ stop ]
end

to kill-original-stem-cell
 ask turtle 0
 [ die ]
 end

to kill-moving-stem-cell
ask turtle 1
[ die ]
end

 to kill-transitory-cells
 ask turtles with [ age < 10 and not stem? ]
  [ die ]
 end
海龟自己的
[
干细胞?;干细胞为真,短暂细胞为假
年龄;;细胞的年龄。颜色随年龄变化
转移性?;干细胞0的后代为假,干细胞1的后代为真
]
全局变量
[
细胞计数
]
设置
清除所有
将默认形状海龟设置为“方形”
询问补丁[
如果pycor=最小pycor[
如果其他随机10 0
[向邻居询问[pcolor=black][设置pcolor-yellow]
]
]
使用[pcolor=白色]询问补丁
[如果用[pcolor=black]计算邻居数>0
[向邻居询问[pcolor=black][设置pcolor-yellow]
]
]
打上钩
结束
过渡细胞移动和孵化更多。
移动移行细胞
如果(不是阀杆?)
[
设置颜色(红色+0.25*年龄)
fd 1
if(年龄<6岁)
[
舱口1
[;放大
rt随机浮点360
fd 1
]
]
]
结束
有丝分裂;;仅限于原干细胞
如果干?
[
舱口1
[
fd 1
设置颜色为红色
设置阀杆?错误
ifelse(who=1)
[设定年龄16岁]
[设定年龄0]
]
]
结束
死亡;;海龟程序。
如果(不是干?)和(不是转移?)和(年龄>20岁)
[死亡]
如果(不是干细胞?)和转移性?和(年龄>4岁)
[死亡]
结束
评估参数
设置单元格计数海龟;单元格计数

如果(cell count您似乎有两个相互冲突的需求,基于代码中的接近度的颜色更改和基于您询问的PYCOR的颜色更改

暂时忽略代码,我们可以通过多种方式基于PYCOR设置颜色。例如,我们可以创建色带,我们可以创建抖动混合的颜色,或者我们可以创建颜色之间的“平滑”过渡

第一个很简单。我们可以使用IFELSE结构。本例创建偶数条带,但您可以更改“divide”变量来创建任意高度的条带

let color1 red
let color2 yellow
let color3 black

let divide1 (min-pycor + world-height * 0.33)
let divide2 (min-pycor + world-height * 0.66)

ask patches
[ ifelse pycor < divide1 [ set pcolor color1 ][
  ifelse pycor < divide2 [ set pcolor color2 ][
                           set pcolor color3
  ]]
]
我们可以通过在pycor中引入随机元素来创建抖动带。我们还必须添加一些测试来保持随机数在范围内

let colors [ red yellow black ]
let bands length colors 
let band-height floor (world-height / bands + .5)
let dither band-height * .5 ;; adjust this to change dithery-ness
ask patches
[ let py pycor - min-pycor + dither - random-float ( dither * 2 ) 
  ;; you might want to really study the above line to fully grok what's happening there
  if py < 0 [ set py 0 ]
  if py > world-height [ set py world-height ]
  set pcolor item ( floor ( py / band-height ) ) colors
]
let颜色[红黄黑]
让带长度颜色
让乐队高度落地(世界高度/乐队+.5)
让抖动带高度*.5;;调整此值以更改抖动度
询问补丁
[让py pycor-min pycor+抖动-随机浮动(抖动*2)
你可能想真正研究一下上面这一行,全面了解那里发生了什么
如果py<0[设置py 0]
如果py>世界高度[设置py世界高度]
设置pcolor项目(地板(py/带高))颜色
]

渐变(渐变)带比较硬,因为NetLogo的颜色空间不会在色调上进行渐变,只有色调和阴影,因此无法通过这种方式从红色变为黄色。因此我们必须使用RGB(三值列表)颜色,而不是NetLogo(单值)颜色。这超出了我现在想输入的范围,所以你就这样做了--左边是一个尺寸。

你真的需要更具体地回答你的问题。你不能只发布一堆代码和一些模糊的规范,期望人们理解你在做什么……什么是“黄色补丁>红色>黑色”是一种进步?一种等级制度?
let colors [ red yellow black ]
let bands length colors 
let band-height floor (world-height / bands + .5)
let dither band-height * .5 ;; adjust this to change dithery-ness
ask patches
[ let py pycor - min-pycor + dither - random-float ( dither * 2 ) 
  ;; you might want to really study the above line to fully grok what's happening there
  if py < 0 [ set py 0 ]
  if py > world-height [ set py world-height ]
  set pcolor item ( floor ( py / band-height ) ) colors
]