设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8063|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
- R: ]) ]& t) Z; M: w. W$ U* \# a5 E* ~- q& o# I. q' W
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
1 |" R- |, |+ e2 Z' c& }* x% M4 E. \/ V8 _6 n
turtles-own [a b c d k f g h
" k8 n9 @& Q* {3 ^! D  x y     ;; these are the leaf-turtle's offsets relative to center-turtle : }# u6 t7 Y8 l9 D2 l3 u. h! G$ Q
]
" k' W7 J2 Y2 s# p" I" C& X* m# z  A2 Lto new
9 U. }. O: q1 N8 F. K( s/ c3 |# }' C  ca
# \; n* b/ t( G9 i  crt 5 * num_of_building/ S2 T4 f1 H9 k) X+ U% Z3 [' H. K& J
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
9 J2 |9 c3 n: I, F- x5 }  scatter     ;;keep center-turtle random positions 2 e3 L( d+ I) ?& z) c* S
  unit_plan   ;;make up the building plan
# L- G  Q. o9 Mend! ^, `. F. `9 g, h
to scatter
/ z- D- K7 n% ^+ e3 M3 fask turtles with [remainder who 5 = 0]
( b. C( r2 a1 O( K+ f. e[
) t6 b  k, K% M: `% P7 ~3 Nset xcor xcor - 6 + random-float 15
5 g; Q' t' K7 Bset ycor ycor - 6 + random-float 15( B2 A: J" p/ U2 E- p
]
) U0 Q" K! K) k+ w& _/ {end
4 R! A% E2 J3 w3 C2 L! Kto unit_plan
  y; o! H9 p3 M& Zask turtles [
, Q) `& T2 H$ U. ^3 Tif (remainder who 5 = 1) [set a who
1 V( m0 G3 l$ g5 N% A, m                          set x ( 0 - Wid / 2 )   x( S4 G# e6 D( s9 ?; z
                          set y  Dep / 2 ]
& B3 J# W5 U, J+ y% z2 m           set b  int (a / 5) * 5# b  _6 ?* X; @& a# e
    setxy ( xcor-of turtle b + x )9 W, R9 X3 i, g$ A; K" b
          ( ycor-of turtle b + y )
' w+ b; _' s' t' Rif (remainder who 5 = 2) [set c who$ b! p/ ^5 A# W, ?
                          set x ( 0 - Wid / 2 )
1 `3 o9 {- ^. H& `                          set y (0 - Dep / 2 )  ]- _  R* t. p/ z1 s$ c( V
                          set d int (c / 5) * 5+ A* j$ ^4 p: j
   setxy   ( xcor-of turtle d + x )# f4 l# F7 I+ ~( b$ R- p; k" e7 _
           (ycor-of turtle d + y ) 5 t+ k/ ~2 n5 ^
         
/ F$ R* i. F$ [' Z- I            
# f2 X2 ~1 l: b3 r8 ?if (remainder who 5 = 3) [set k who2 y) M8 m9 X. J- J+ }6 W' c- G
                          set x( Wid / 2)    Q, M  T( O: h5 ^( a- `+ [
                          set y (0 - Dep / 2 ) ]
! D, v- M  H  a5 A9 \                          set f int (k / 5) * 5
; k6 _0 i0 n' z- m; Y  setxy   ( xcor-of turtle f + x )7 W7 J5 W) S; V7 |2 h2 f* _  E
           (ycor-of turtle f + y )   B; s3 D" X7 @/ Q8 ~, u5 S) S
           
& I, t) i7 T5 `! {  y           
3 }, O" {& r) D9 l. }5 s; }if (remainder who 5 = 4) [set g who) C1 W9 v( x  @/ G
                          set x Wid / 2   t) ~3 |( F4 n$ ]! y
                          set y  Dep / 2 ]
$ R1 f) r$ }0 q2 n3 y% u                          set h  int (g / 5) * 5! {6 B& M" j2 n
  setxy   ( xcor-of turtle h + x )
/ r3 w5 G& ^1 \8 B, h. f% h3 Z' n           (ycor-of turtle h + y )
( p, y0 [% B# H" r                          
# }+ J+ n7 C4 g) G. I                          1 [" e$ i% z% }* U5 K& v7 O8 a; F7 B
                          ]! P; f" u( ]2 \( W
end- N4 c- u" g. D& Z6 N

/ S' m% G6 ?( I/ h; t" I[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,- b( o0 Q# n7 G/ n
应该是" M  S/ w5 h7 |# e
ask turtles [# N& N9 r6 T% K6 R! s2 c/ D% e
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
% \3 N; R" i3 d1 Q                          set y  Dep / 2
5 v+ C3 [) o+ ?4 V( A" l           set b  int (who / 5) * 5
( i4 M9 F9 u. b- T  o    setxy ( xcor-of turtle b + x )- K4 o1 r3 F2 N* [9 q; b; y" ?
          ( ycor-of turtle b + y )]]8 h. U& ]) R& w1 M
end
; n: @) x0 U1 ]0 K之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-2 22:08 , Processed in 0.017279 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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