设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7743|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。- k  S! r, f/ L5 C# f; D3 j
- ^5 i7 Q) E1 K: G3 h  z% i3 x
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。. W- c6 ]$ Y1 A9 r
8 o1 Q5 K3 t0 S' Z
turtles-own [a b c d k f g h" S# d" Q' E) j: {0 D, C4 j$ V5 M
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
6 v3 W: w/ S# X]% M3 V( J& Y9 T+ \- u) j! m: H1 r% S
to new  B  i5 P- i! ]; E$ }) K
  ca
4 r0 b# ?8 P0 _& }  [$ x  crt 5 * num_of_building. |1 Z7 T4 }* [% T
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]- ~7 H, H: P! K) I
  scatter     ;;keep center-turtle random positions 8 _  @8 l. O; M' C
  unit_plan   ;;make up the building plan
0 t- o& m9 I" c& l+ k4 t+ v. `+ `0 Jend! ~( s; ~* _2 D% q+ w. f
to scatter
# j1 m5 J+ X$ \" X$ y* y: Nask turtles with [remainder who 5 = 0]
, F& {$ p. i9 J! y[4 L" p8 e! W; s1 n! I. V4 i& I
set xcor xcor - 6 + random-float 15
5 ?4 F7 x7 v0 S; J, v! [) i( Yset ycor ycor - 6 + random-float 15& K- u& S; U0 _  h6 Z, ^' Y7 E7 G
]
0 W4 o3 m7 O/ Z0 M, h) G+ t  j( Kend
+ [0 @0 T: Z+ O4 E9 f/ Qto unit_plan
# g' d& C* p+ N0 Q: Lask turtles [
& c" E8 K2 c5 {if (remainder who 5 = 1) [set a who
3 a/ ]5 \4 c# w/ M% Z2 M1 J                          set x ( 0 - Wid / 2 )
) A0 O& c0 b0 T: v0 B2 d. l                          set y  Dep / 2 ]  }" u' R& k5 W9 E
           set b  int (a / 5) * 58 w5 U- H) g& r2 r( l$ }
    setxy ( xcor-of turtle b + x )  F- U: A4 c$ u& [2 k+ {2 _
          ( ycor-of turtle b + y )
5 f/ O, W) Q$ J* ]if (remainder who 5 = 2) [set c who4 N- W* E! s( I: E7 S: F& ~7 n
                          set x ( 0 - Wid / 2 )
. d; F! x" J  M                          set y (0 - Dep / 2 )  ]/ |' G2 J' z3 V4 c
                          set d int (c / 5) * 5
  Q3 c* ?* \* U& Z2 |0 K: R0 C   setxy   ( xcor-of turtle d + x )
4 k% ~! w( Y+ D) S" l           (ycor-of turtle d + y ) ' [4 s) T5 C# g# ?5 ~
          2 S% r) [0 T' O
            
/ B" w& p5 I* ^% O! R$ Yif (remainder who 5 = 3) [set k who
" B9 @) u! Y4 r# V/ v! e9 y4 ]                          set x( Wid / 2)  4 ]( M' E, G! C0 W- J* |) F' e
                          set y (0 - Dep / 2 ) ]2 ^) o2 K* s$ n3 N  k" N  J
                          set f int (k / 5) * 5( Y" [0 l4 B: u, W+ P& P2 t
  setxy   ( xcor-of turtle f + x )( @. ]$ y1 n% k1 k' D7 a
           (ycor-of turtle f + y )
4 {# |+ S  a" F  ~           * x0 R$ i5 ?" e0 l2 T/ O  s
           8 `1 A9 Z- h8 k! S
if (remainder who 5 = 4) [set g who
0 X+ s, Y; t  i/ \                          set x Wid / 2 ! ?+ q7 O/ l5 F  J7 |2 P) S& Q" I
                          set y  Dep / 2 ]
; n4 I; O3 B% J: U                          set h  int (g / 5) * 5
- s# Y8 x9 p; `2 H1 V8 p  setxy   ( xcor-of turtle h + x )# T' y; `. F( {8 \5 O, n
           (ycor-of turtle h + y )
. f& n& u9 T$ r0 h5 t9 j2 z                          % S3 T7 [  ]5 @4 i
                          . r/ V5 _+ O6 ~
                          ]
* U% _6 d5 `: @. x5 |0 Pend
, q8 c1 {, _  X/ q' }$ L' M, {8 J) q0 j8 N& j* o9 q( ^" f
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,; S( v' j% m6 T/ L6 y
应该是" m/ \* w# p$ h% B
ask turtles [* L6 \& E: [4 j0 l# o( ~
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) ! j  f! i+ \6 @% F& d8 F5 V
                          set y  Dep / 2
5 q, [2 |, ?& j1 v4 Z( f% X           set b  int (who / 5) * 5
# c* B; s8 N# _' z4 Q    setxy ( xcor-of turtle b + x ), z% D1 p" t6 n6 s. j- f
          ( ycor-of turtle b + y )]]
9 W% o8 H2 I, \$ hend
# [0 i! t, J- @& i) t: N; |( }之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-22 22:24 , Processed in 0.015298 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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