2017-12-07 5 views
1

私はNetLogoを初めて使用しています。光源のパッチを越えて光を拡散させる光源と、光を避けるタートルを持つシンプルなプログラムをレイアウトする必要があります。NetLogo:カメに1色の色合いを認識させるには?

これは、基本的な 'set pcolor yellow'を使用し、 'patch-ahead [pcolor] = yellow [right 45] [fd speed]'コマンドの場合に使用できます。しかし、これは私に拡散光を与えません。

HeatBugsコードを適用することで、ソースパッチを越えて色を拡散させることができますが、ローミングカメはもはや色が黄色であるとは認識しません。コードを!=黒に設定しようとしましたが、これも機能しません。私はそれがパッチが各チックの後にrecoloredされているためだと仮定しています。

拡散した色のパッチを避けるために、亀に認識させる方法はありますか?または、光を拡散する簡単な方法。 (私はさまざまな強さのために隣人と黄色-1を使用していませんので、それをしません)

これは私がこれまで持っているコードです:

globals [ color-by-unhappiness? ] 

turtles-own[ 
    speed 
    speed-limit 
    speed-min 
    ideal-temp  ;; The temperature I want to be at 
    output-heat  ;; How much heat I emit per time step 
    unhappiness  ;; The magnitude of the difference between my ideal 
       ;; temperature and the actual current temperature here 
] 

patches-own[ 
    temp   
] 

to setup 
    clear-all 
    setup-turtles 
    ;;creating diffused light 
    set color-by-unhappiness? false ;; button 
    ask n-of number-of-lights patches [ 
    sprout 1 [ 
     set color white 
     set shape "circle" 
     set ideal-temp min-ideal-temp + random (max-ideal-temp - min- ideal-temp) ;;these are all sliders 
     set output-heat min-output-heat + random (max-output-heat - min- output-heat) ;;these are all sliders 
     set unhappiness abs (ideal-temp - temp) ;;ideal-temp is a button 
     color-by-ideal-temp 
     set size 2 
    ] 
    ] 
    reset-ticks 
end 

to setup-turtles 
    create-fears number-of-fears [ 
    set color violet 
    set shape "circle" 
    setxy random-xcor random-ycor 
    set speed 0.1 + random-float 0.9 
    set speed-limit 1 
    set speed-min 0.00 
    ] 
end 

to go 
    ask turtles [ 
    if speed > speed-limit [set speed speed-limit] 
    fd speed 
    ask fears[ 
    if patch-ahead 1 = nobody [rt 135] 
    if patch-right-and-ahead 45 1 != nobody and [pcolor] of patch-right-and-ahead 45 1 != black[left 45] 
    if patch-left-and-ahead 45 1 != nobody and [pcolor] of patch-left-and-ahead 45 1 != black[right 45] 
    ifelse [pcolor] of patch-here = yellow [set speed speed-min][fd speed] 
    ] 
    if not any? turtles [ stop ] 
    ;; diffuse heat through world 
    diffuse temp diffusion-rate 
    ask patches [ set temp temp * (1 - evaporation-rate) ] 
    ask turtles [ set temp temp + output-heat ask bugs [bug-move patch-here]] 
    recolor-turtles 
    recolor-patches 
    tick 
end 

to recolor-patches 
    ask patches [ set pcolor scale-color yellow temp 0 150 ] 
] 
end 
+0

http://ccl.northwestern.edu/netlogo/docs/dictionary.html#shade-of:ちょうどここで期待通りの動きが機能するように(0)黒に自分の色を設定することpcolorでパッチを頼みます –

答えて

0

私はあなたのコードをそのまま使用することはできません。 MCVE guidelinesをチェックし、コードを必要な部分だけに減らすためのヒントを確認してください。

Netlogoの色は文字列として指定できますが、数値の範囲にすぎません。ツール>カラースウォッチを見ると、「イエロー」の色の範囲はおよそ40〜50に対応しています。そのため、色の名前ではなく数値の範囲を使用してパッチの色を評価させることができます。移動し、ちょうどその数値範囲にパッチを避けるためにあなたのカメを求めることができ

patches-own [ light? temp] 

to setup 
    ca 
    ask patches [ 
    set light? false 
    ] 
    ask n-of 5 patches [ 
    set light? true 
    set temp 150 
    ] 
    recolor-patches 
    crt 10 [ 
    move-to one-of patches with [ not (pcolor > 40 and pcolor < 49) ] 
    ] 
    reset-ticks 
end 

to recolor-patches 
    ask n-of 3 patches with [ light? ] [ 
    if temp < 20 [ 
     set temp temp + random 20 
    ] 
    ] 
    repeat 5 [ 
    diffuse temp 0.1 
    ] 
    ask patches [ 
    ifelse temp > 0.25 [ 
     set temp temp - 0.005 
    ] [ 
     set temp 0 
    ] 
    set pcolor scale-color yellow temp 0 15 
    ] 
end 

to go 
    recolor-patches 
    ask turtles [ 
    ifelse [pcolor] of patch-ahead 1 > 40 and [pcolor] of patch-ahead 1 < 49 [ 
     let target min-one-of neighbors [pcolor] 
     if target != nobody [ 
     face target 
     fd 1 
     ] 
    ] [ 
     rt random 60 - 30 
     fd 1 
    ] 
    ] 
    tick 
end 

EDIT

セスようにので、この不必要に複雑な例のセットアップを使用してティスpointed outshade-of?プリミティブは、論理ステートメントより大きい/より小さいステートメントを実行できます。

to go 
    recolor-patches 
    ask turtles [ 
    ifelse shade-of? ([pcolor] of patch-ahead 1) yellow [ 
     let target min-one-of neighbors [pcolor] 
     if target != nobody [ 
     face target 
     fd 1 
     ] 
    ] [ 
     rt random 60 - 30 
     fd 1 
    ] 
    ] 
    tick 
end 

しかし、scale-colorは基本色を40(黄色の場合)に設定しているため、これはrecolor-patches手順を少し変更する必要があります。

to recolor-patches 
    ask n-of 3 patches with [ light? ] [ 
    if temp < 20 [ 
     set temp temp + random 20 
    ] 
    ] 
    repeat 5 [ 
    diffuse temp 0.1 
    ] 
    ask patches [ 
    ifelse temp > 0.25 [ 
     set temp temp - 0.005 
    ] [ 
     set temp 0 
    ] 
    set pcolor scale-color yellow temp 0 15 
    if pcolor = 40 [ 
     set pcolor black 
    ] 
    ] 
end 
+1

NetLogoには、ここで役立つ 'shade-of? 'プリミティブがあります。 –

+1

@SethTisue - それを指摘してくれてありがとう、私はそのオプションを含めるために私の答えを編集しました。 –

+0

私は早く反応しなかったことをお詫びします。これは本当に助けられて、私の必要としていたもののために完全なものでした。 – alexjamessays

関連する問題