How to setup a slider for pen size into the code in Netlogo

时光毁灭记忆、已成空白 提交于 2019-12-25 02:11:23

问题


this is my code , i need to fit the slider so i edit the pen size my global variable is 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

回答1:


You could set pen-size where you are asking each turtle to pen-down




回答2:


I am not exactly sure what you want to do in your code, the pen-down? is not defined in your code, I assume you have a turtle property which defines a pen-down? to one of values of true and false, if you define it a global value I believe all of your turtles end up with same value, for pen-size you can use following code

set pen-size turtle-pen-size

This is your completed code:

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


来源:https://stackoverflow.com/questions/22286902/how-to-setup-a-slider-for-pen-size-into-the-code-in-netlogo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!