乌龟会根据特定补丁颜色更改颜色

时间:2018-07-01 18:51:32

标签: netlogo

此代码包含道路设置和乌龟创建过程,之后,使乌龟走上粉红色路径的过程,并试图使乌龟变色,使其变成红色斑点,但由于未知原因,此代码不工作,汽车永远不会改变颜色并保持蓝色,因为那里有创造色 我希望我能得到一些帮助

        turtles-own [
         speed
          s?

        ]



to setup-road
   clear-all
     ask patches [
  ifelse pycor < -8 and pycor > -17 [set pcolor black ]
  [set pcolor gray - 3 ]
   if pycor < -9 and pycor > -15 [ set pcolor gray ]
  if pycor > -10 and pycor < -8 and pxcor > 20 and pxcor < 27
    [set pcolor white ]
     if pycor < -2 and pycor > -4 and pxcor < 20 and pxcor > -24
    [set pcolor pink ]
         if pycor < -3 and pycor > -10 and pxcor < -22 and pxcor > -24
        [set pcolor green ]
         if pxcor = 20  and pycor = -3
        [set pcolor red
        ]

      ]
       set-default-shape turtles "car"
      create-turtles 2 [
        set color blue
                set size 2
       set xcor random-xcor
        set ycor -12
        set heading 90
        set speed 0.1 + random-float 0.9
        set s? true

      ]
      reset-ticks

    end

    to go

        ask turtles [
        let car-ahead one-of turtles-on patch-ahead 2
        if car-ahead != nobody
        [ fd speed]
        let gate  one-of patches in-radius 5 with [pcolor = green ]
        let path  one-of patches in-radius 5 with [pcolor = pink ]


        if s?
        [ ifelse gate != nobody
          [ move-to gate
            fd speed

              ifelse path != nobody
              [
              move-to path
               fd speed
              if patch-ahead 1 != nobody and pcolor != pink
              [set color green ]

            ]
              [fd speed]]

         [fd speed]

      ]
      ]

      tick
    end

0 个答案:

没有答案