1

以下のコードで次のことを達成するにはどうすればよいですか。

パッチは、行「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
4

1 に答える 1

2

コード内の近接性に基づく色の変更と、質問する PYCOR に基づく色の変更という 2 つの相反する要件があるようです。

コードを少し無視すると、さまざまな方法で 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
  ]]
]

数学的な方法でそれを行うこともできます。この例では、偶数バンドを作成します。

let colors [ red yellow black ]
let bands length colors 
let band-height floor ( world-height / bands + .5 )
;; pycor - min-pycor shifts the range from 0 to world-height
ask patches [ set pcolor item ( floor ( ( pycor - min-pycor ) / band-height ) ) colors ]

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
]

NetLogo カラー スペースは色相の段階的なシフトを行わず、色合いと陰影のみを行うため、グラデーション (グラデーション) バンドはよりタフです。そのため、赤から黄色にそのように移行する方法は実際にはありません。したがって、NetLogo (単一値) の色の代わりに、RGB (3 つの値のリスト) の色を使用する必要があります。そして、それは私が現時点でタイプしようとしているものを超えています。

于 2013-02-05T14:12:51.413 に答える