设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8882|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。, ~* [7 }9 _/ u$ @: B3 ^
" Z2 V9 L$ _5 V! Y4 D
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。. m$ R& M) _& B9 w
5 S6 [! Q/ y1 r3 {3 B
turtles-own [a b c d k f g h% s- @' a5 e  w  q  q) M$ I
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 9 a$ E& y2 u# x- Q* w5 w
]
$ v. K2 c5 b% |, }to new
  J8 f2 c: t) J6 b9 X  ca# X' K' O7 Q% y, M4 {- r
  crt 5 * num_of_building% w) d; ^3 S9 q1 I% ?& _
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
% k2 U! F8 r1 R0 j* }$ L. n  scatter     ;;keep center-turtle random positions
* `, d' c. K* G3 Z. e  unit_plan   ;;make up the building plan0 h0 d7 X2 U& r6 f3 F6 O3 J7 {
end" R: L. C$ \; q/ u  _9 n
to scatter
3 B/ x9 r0 H) _' Z" i, Hask turtles with [remainder who 5 = 0]" u0 G; g$ K1 W+ ]0 e. g
[
. \( I9 G6 ^! mset xcor xcor - 6 + random-float 15# ^2 Z+ g. |( P* L" {& a
set ycor ycor - 6 + random-float 15
" y) c# l4 p4 J5 N! h; C; v4 q]
9 [; {* K1 b8 H: c/ c! w# v2 gend
3 Z" ]: U$ m! U+ X0 q& ]( [to unit_plan 6 }6 g  T, K' t; {
ask turtles [
6 R! @6 {9 j/ ?& Xif (remainder who 5 = 1) [set a who 1 ~' T8 C" c6 p; I( @2 l" i$ A* s: `
                          set x ( 0 - Wid / 2 ) # C, h- }- I1 d" o
                          set y  Dep / 2 ]
" A% c5 D, b7 B" d& X1 K8 e5 R           set b  int (a / 5) * 5
* W& W  X8 Y0 l$ e0 W8 \    setxy ( xcor-of turtle b + x )
9 X* R5 H! k- ]* b          ( ycor-of turtle b + y )
9 Y6 R( N; b0 e7 jif (remainder who 5 = 2) [set c who  v9 ?7 j) @* g& |* f) p. q
                          set x ( 0 - Wid / 2 ) + K4 R  h; C4 I+ v' ]
                          set y (0 - Dep / 2 )  ]
, j( M, ]2 D& T* D6 T                          set d int (c / 5) * 5
5 q6 ~4 r" y- K* w! [2 `4 H   setxy   ( xcor-of turtle d + x )
1 S* A( b* b) _: `# |           (ycor-of turtle d + y )
1 p& z6 a" v1 s- N8 ~: V  l  j          . f5 P9 o0 g/ J  ^
            
* w7 g# s+ B* A) c, m% W  K6 nif (remainder who 5 = 3) [set k who
; g& ]6 I, o1 \8 k3 [                          set x( Wid / 2)  9 ^( r% a# J6 D  e- O6 [. J2 m# L" d
                          set y (0 - Dep / 2 ) ]
% e' V4 ~) Z$ A( M  w0 X/ J                          set f int (k / 5) * 53 i  a7 N4 E% U# K1 a3 `
  setxy   ( xcor-of turtle f + x )$ R  j4 V  ~; _
           (ycor-of turtle f + y )
" [. q1 d8 @% v3 g/ v' T  j. U           1 N8 J# A+ ?, Q% a0 k) K. ^
           " W; }8 K* q$ l$ @$ Z' q
if (remainder who 5 = 4) [set g who
! F8 B9 e5 o0 m4 ~                          set x Wid / 2 4 P3 {3 O' l% i/ `
                          set y  Dep / 2 ], o2 z, S. R8 B: g  C
                          set h  int (g / 5) * 5
2 ?  U: S+ R; }% g9 J/ N+ @  setxy   ( xcor-of turtle h + x )# p1 Y; Y5 U0 f8 [. n0 M
           (ycor-of turtle h + y ) 4 Z; |# h1 P( P4 [. _
                          
8 v; w+ ^4 |4 l                          
, g. X. H) M, z                          ]
2 O) c5 P) X* n7 t, yend
, X0 n7 k1 E# G) D5 I9 Z/ p5 R/ r
/ l1 q5 Y8 H0 A# \. H- k[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
. Z1 ^/ Z) M9 D应该是- @% K* t; f: I3 ?7 [
ask turtles [
5 p' c  j3 ?& g7 w& ?if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 4 G; h6 x) V( w- g
                          set y  Dep / 2 0 [% O. L; l* N8 r1 @( i/ ]5 y3 x
           set b  int (who / 5) * 5/ H# G! w7 }1 t9 f  e
    setxy ( xcor-of turtle b + x )( H' m$ h& N7 {
          ( ycor-of turtle b + y )]]
0 A% }& _1 O# [! i: I: I5 \end
: Z! I  U, V" U* L之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-16 15:10 , Processed in 0.019315 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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