设为首页收藏本站

最大的系统仿真与系统优化公益交流社区

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8800|回复: 1

[交流] 看看这段代码的问题

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。8 Z% K# Z0 G9 \
  {- o6 y  E$ m- v7 D
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
; T6 w0 j0 \- G( y- `* }+ T8 K
# P& D2 J: u# v4 P9 Y+ P. \$ kturtles-own [a b c d k f g h
. B& i7 v2 {0 E; ?8 F  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
, V. s4 q7 m& ^% w1 `  X]
4 {) F& G5 c. V4 ]+ Q: j4 K3 dto new) {! b0 _' q' j
  ca7 R3 _" Z! z/ E% e
  crt 5 * num_of_building
6 E5 @. ~" [. ], j6 c. o" W  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
( o1 e! ^9 u2 [* _+ A$ t+ s  scatter     ;;keep center-turtle random positions
: d1 E9 e# ]+ A8 m6 w+ |: @3 d  unit_plan   ;;make up the building plan5 @: v: W+ w: y/ {# |6 e! ]) y* W
end
5 Q( m# `, Y( J: i) s1 u9 @to scatter
8 p2 p# {  c3 ?, Kask turtles with [remainder who 5 = 0]
3 B1 V1 |; Z% F: v[
& J. j! C; Q/ \8 j" xset xcor xcor - 6 + random-float 15
4 P& g; ]; E% g' d/ Zset ycor ycor - 6 + random-float 15  V. g0 \  R. U5 Y# f# P. B
]+ ~- K* b* Q( r8 W* T7 B% V
end1 Q: `, B. |7 s6 {4 R3 J
to unit_plan
- q+ }7 s" r, }ask turtles [! Q  c! ]3 v; i/ W& j( F
if (remainder who 5 = 1) [set a who
3 F( }+ \* L2 w& }/ x  c                          set x ( 0 - Wid / 2 )
5 ?, K& ^& q! I' D" a; N                          set y  Dep / 2 ]+ k+ G$ S! P' C  K: E3 P2 _/ O9 }: I
           set b  int (a / 5) * 5
. e% i, v6 @* E+ o; ^    setxy ( xcor-of turtle b + x )( _; J( v0 b( [# Y, T
          ( ycor-of turtle b + y )
7 s, }; W" I$ P" M. wif (remainder who 5 = 2) [set c who
# {: ~+ _0 l  K# t; F                          set x ( 0 - Wid / 2 ) " T/ k1 t6 m: u$ b- o* w$ L% j
                          set y (0 - Dep / 2 )  ], X. Y" q+ Z4 X& f0 t
                          set d int (c / 5) * 5" k# f+ N: U8 p( t8 r. A
   setxy   ( xcor-of turtle d + x )
4 F8 ]  Z1 E4 [           (ycor-of turtle d + y )
2 h3 R# G6 |) N* S         
9 K# i$ h+ |  ~' @) k1 o            # ^6 h! O. Q. ?2 o% s
if (remainder who 5 = 3) [set k who& _$ O1 G) P3 ?
                          set x( Wid / 2)  
! b* q" Q$ m1 o; l' A7 d                          set y (0 - Dep / 2 ) ]
% c& j1 l6 \* G5 k  ~8 r                          set f int (k / 5) * 5
& J( }# k7 q/ `. U  i9 u  setxy   ( xcor-of turtle f + x )
1 u( b9 c; Z1 p0 j# }, t           (ycor-of turtle f + y )
: X: C- {. o, u' h' `9 i$ F           
8 m2 s$ K2 F  x( b! D' x4 G           
2 H! t$ v, q) h# t/ C* O. _if (remainder who 5 = 4) [set g who
/ e# Y) w8 W- S) o                          set x Wid / 2   d' h3 G. O" [, D* a, `" N6 d: {
                          set y  Dep / 2 ]
/ p) l( y& `- d9 T                          set h  int (g / 5) * 5# b; P0 c# v4 H- ]+ b. ^7 l
  setxy   ( xcor-of turtle h + x )' T( `  t7 I* V, W; ]" W, y6 @
           (ycor-of turtle h + y )
! ^  P6 c: m6 p                          8 [  {) u/ z- Y
                          : _8 Z9 ~, |: }' x/ }. e
                          ]
( n. {  h# F  Y( \) H  ?( Uend+ @, G& j7 f, d. z& G7 k$ h

) u* q3 O9 T. g) t' Q% }[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
8 l! Z% m8 }# t7 n$ K$ s1 d应该是
8 O' ^" M; P% |7 y* uask turtles [- ?6 l, W% c4 z/ M& k& n: Z
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 7 L- l+ h7 b! x( S7 V9 M* J
                          set y  Dep / 2
) x4 }; y3 s5 |( g4 b/ S3 B           set b  int (who / 5) * 55 D: a  J  ]  W: ]; O' d# y
    setxy ( xcor-of turtle b + x )
- y( r( [% O( u! D# N3 n2 W" n6 \          ( ycor-of turtle b + y )]]% K2 O6 A  P* s! _1 e
end
. _8 J+ F9 g( n" C( a4 ?) U之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|SimulWay 道于仿真   

GMT+8, 2026-8-5 20:36 , Processed in 0.014878 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表