如何将笔大小的滑块设置到Netlogo中的代码中

时间:2014-03-09 19:21:29

标签: netlogo

这是我的代码,我需要适合滑块,所以我编辑笔的大小我的全局变量是turtle-pen-size

 to setup
      clear-all
      ask patches [ set pcolor sky ]
      setup-turtles

    end

    to setup-turtles
      create-turtles turtles-to-create 
      [ set color lime setxy random-xcor random-ycor set size size-of-turtle]  
      set-default-shape turtles "circle"
    end

    to go 

     ask turtles[
         ifelse pen-down? [ pen-down ] [ pen-up ]
         fd 1
   ]

end

2 个答案:

答案 0 :(得分:1)

您可以将pen-size设置为要求每只乌龟pen-down

答案 1 :(得分:0)

我不完全确定你想在你的代码中做什么,pen-down?没有在你的代码中定义,我假设你有一个定义下笔的乌龟属性?如果你定义一个全局值,我认为你的所有海龟都有相同的值,对于笔大小,你可以使用以下代码

set pen-size turtle-pen-size

这是您完成的代码:

turtles-own[pen-down?]

    to setup
      clear-all
      reset-ticks
      ask patches [ set pcolor sky ]
      setup-turtles

    end

    to setup-turtles
      create-turtles turtles-to-create 
        [ 
          set color lime 
          setxy random-xcor random-ycor 
          set size size-of-turtle
          set pen-size turtle-pen-size
          set pen-down? one-of [true false]
        ]  
      set-default-shape turtles "circle"
    end

    to go 

      ask turtles[
        ifelse pen-down? 

          [ pen-down ] 
          [ pen-up ]


        fd 1
      ]
      tick
    end